What is replacement for instrfind function?

13 ビュー (過去 30 日間)
Ivan Sojic
Ivan Sojic 2022 年 10 月 5 日
編集済み: Ivan Sojic 2022 年 10 月 11 日
Hello,
I just saw that "instrfind" function will be removed in the future releases.I am using this function frequently to detect open COM ports and close them before re-running application.
eg.
out = instrfind('Port',['COM',int2str(ComNum)]);
if ~isempty(out)
fclose(out);
delete(out)
clear out
end
What procedure do you recommend to use in order to access already open COM port?
I see this step as extremeny useful, otherwise "serialport" will report an error (Unable to connect to the serialport device at port...)
Best regards,
Ivan Sojic

回答 (1 件)

Steven Lord
Steven Lord 2022 年 10 月 5 日
The Compatibility Considerations section of the instrfind function documentation page gives a list of replacement functions for various uses of instrfind. Quickly skimming through the options suggests the serialport interface family of functions is the correct replacement. See this documentation page for more information.
  5 件のコメント
dpb
dpb 2022 年 10 月 6 日
ADDENDUM
It would seem about the only available workaround/kludge available to the user code would be to create a global array or struct that holds the serialport object handles. While globals tend to be ugly and messy, that would at least reduce the likelihood of many of the ways one might otherwise get orphaned handles.
Of course, ideally, one doesn't ever have that occur, but "stuff" happens...
dpb
dpb 2022 年 10 月 6 日
編集済み: dpb 2022 年 10 月 7 日
ADDENDUM SECOND
s=serialport
without any arguments will connect to the last cleared serialport object instance.
This gives one-step recovery, but doesn't let one retrieve status of any port by name as does instrfind
This machine has only one COM port so can't see what happens with more than one -- would a subsequent use of
s(2)=serialport;
reopen the previous second-to-last cleared serialport object instance or ...???

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSerial and USB Communication についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by