showing Results of Serialportlist in a UITextArea

조회 수: 2 (최근 30일)
Jason
Jason 2020년 11월 26일
댓글: Avratanu Biswas 2020년 11월 27일
Hello, I would like to display the available ports on my PC using serialportlist("available")
I have come across the evalc..code below
portstring = evalc('display(serialportlist("available"))')
ReportMessage(app,portstring);
Reportmessage is my own function that adds to a textarea
It works except I get some rubbish first:
1×2 <a href="matlab:helpPopup string" style="font-weight:bold">string</a> array
"COM5" "COM10"
Is there a better way to display the results of serialportlist in a uitextarea?
Thanks
Jason

채택된 답변

Jason
Jason 2020년 11월 27일
This seems to work
freeports = serialportlist("available")
str=sprintf('%s\t', freeports{1:end});
ReportMessage2(app,['Comms Available: ',str]);
  댓글 수: 1
Avratanu Biswas
Avratanu Biswas 2020년 11월 27일
Glad that it worked for you . Using "evalc" never a good idea.( Why Avoid the eval Function? ) - might answer you the reason behind those additional unwanted texts in your very initial post.
Cheers !
A

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

추가 답변 (1개)

Avratanu Biswas
Avratanu Biswas 2020년 11월 26일
편집: Avratanu Biswas 2020년 11월 26일
In case I understood your question correctly, what if you write it in this way
portstring = serialportlist("available"); % instead of using evalc
app.UItextarea.Value = portstring; % using the given name of the UItextarea
  댓글 수: 1
Jason
Jason 2020년 11월 27일
Hello, due to me ReportMessage concatenating vertically, this doesn't work.
function ReportMessage(app,msg) %For message box on config tab
currString=get(app.MessagesTextArea2,'Value');
currString=[currString;{char(msg)}]; %add to top of message box
app.MessagesTextArea2.Value=currString;
drawnow;
scroll(app.MessagesTextArea2,'bottom');
Error using matlab.ui.control.TextArea/set.Value (line 101)
'Value' must be a character vector, or a 1-D array of the following type: cell array of character vectors, string, or categorical.

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

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by