GUI and COM port interface

Hi, I have a question. May I can I know how to communicate serial com port with GUI push button? For eg: s=serial('COM15')into the GUI push button so when I clicked on it will directly connect to the com port.Thanks in advance.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 8일

0 개 추천

Open the serial port and save the resulting object in to a convenient location (such as in a handles structure), and then in the callback for the object, retrieve the stored object and use it to read from or write to.

댓글 수: 5

MrPuzzled Marc
MrPuzzled Marc 2011년 3월 8일
Do i need to add in any functions in order to access the code?
Walter Roberson
Walter Roberson 2011년 3월 8일
No. You just need to configure and open the port some time before the user becomes able to click on that button -- though if you do it after the GUI is initialized, then your callback routine _might_ have to use handles = getappdata(hObject) in order to get the updated handles structure (if, that is, you store the serial port in the handles structure.)
If your serial port is opened an indefinite time before the callback, then you might want to start the callback by reading and discarding all existing data from the serial port, in case something came through while you were idle.
fread(s, s.BytesAvailable)
Walter Roberson
Walter Roberson 2011년 3월 8일
Based upon the code you emailed, you would want to open the serial port in the Connect callback itself.
MrPuzzled Marc
MrPuzzled Marc 2011년 3월 8일
I do not get you in the last 2 reply.I seem puzzled. Could you explain more?Do you have any example that can refer?
Thanks.
MrPuzzled Marc
MrPuzzled Marc 2011년 3월 8일
I tried using handles=getappdata(serial('COM15')); on the push button M-file.However error occurs. It says conversion of double from serial is not possible.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by