Converting and Instrument Object Array (instrfind) into strings?

조회 수: 4 (최근 30일)
Jason
Jason 2020년 1월 6일
댓글: Jason 2020년 1월 6일
Hello, Im using an edit box (GUIDE) as a message reported by utilising multi lines (by setting max property >1)
I have a function that I have created to report out important information.
I am using it for RS232 connections, and want to show in my edit box the results of instrfind:
Instrument Object Array
Index: Type: Status: Name:
1 serial closed Serial-COM3
2 serial closed Serial-COM3
3 serial closed Serial-COM3
4 serial closed Serial-COM3
5 serial open Serial-COM3
Here is my ReportMessage function:
function ReportMessage(handles,msg)
currString=get(handles.editMessage,'String');
currString=[{msg};currString]; %add to top of message box
set(handles.editMessage,'String',currString);
drawnow;
How can I convert and Instrument Object Array into strings?How can I convert and Instrument Object Array into strings?
In particular, I just want to report out any open comms ports
Thanks
Jason
  댓글 수: 2
Guillaume
Guillaume 2020년 1월 6일
Note that as of R2019b, instrfind is not recommended, you should be using serialport instead.
There is no built-in function that directly convers an instrument object array into strings but it's trivial to write one that simply insert into strings whichever properties of the object you want to display. Therefore, what text do you want displayed?
Jason
Jason 2020년 1월 6일
Hi, thanks for this. So it would just be the coms port and its CURRENT status:
Index: Type: Status: Name:
1 serial closed Serial-COM3
2 serial closed Serial-COM3
3 serial closed Serial-COM3
4 serial closed Serial-COM3
5 serial open Serial-COM3
Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2020년 1월 6일
I don't have any serial port on this machine so can't really test for the actual property names, but it should be something like:
ports = instrfind('Type', 'serial');
descriptions = compose('%s on port %s is currently %s', string(ports.Name), string(ports.Port), string(ports.Status));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Serial and USB Communication에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by