Matlab GUI: Showing data from COM port in listbox without using any push button

1 回表示 (過去 30 日間)
Matuno
Matuno 2014 年 6 月 21 日
回答済み: dpb 2014 年 6 月 21 日
I Want to display, in listbox, the data received in COM port. I can show the incoming data in listbox using push button. The data is showing exactly as long as I use push button, but after removing the push button and only using listbox [putting code in listbox's callback] nothing is showing. How can I use listbox to execute the code and shows what it is getting in COM port?
Code::
function listbox1_Callback(hObject, eventdata, handles)
s = serial ('COM6'); % the communication port
fopen(s); %open the serial port
scanText = fscanf(s);
data = scanText;
set(handles.listbox1,'String',...
[data]);
fclose(s);

採用された回答

dpb
dpb 2014 年 6 月 21 日
Because there is no event for the listbox w/o a user intervention -- so the callback function will never be called.
You need to create a serial port event callback -- see documentation under "Events and Callbacks" link under the Serial Port Devices section. It's under Data and File Management chapter.

その他の回答 (1 件)

Roberto
Roberto 2014 年 6 月 21 日
The callback function of a listbox is executed when you select an element of the list, what I think you might want is to read from device automatically, to achieve this you can use the 'Create function' that is executed when the object is created:
function listbox1_Create_Fcn(hObject, eventdata, handles)
s = serial ('COM6'); % the communication port
fopen(s); %open the serial port
scanText = fscanf(s);
data = scanText;
set(handles.listbox1,'String',...
[data]);
fclose(s);

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by