Matlab GUI: Reading from Serial port and showing in different listboxes at the same time

5 次查看(过去 30 天)
I am working with serial port and multiple list boxes to read data in serial port. The listboxes are used to read specific data (suppose the data is coming from 3 different sources, so I have 3 listboxes).
Now the problem:
I want to read all the data separately and continuously. I mean, when I am clicking one listbox (e.g. listbox#2) after reading listbox#1's data, the listbox#1 automatically stops, so again I need to click listbox#1 to read the data for listbox#1. But I want to get the data continuously in all the listboxes without clicking (clicking for first time to initializing) every time. How can I achieve this? I have tried timer function but it shows following error: Error while evaluating TimerFcn for timer 'timer-1'.
Sample code:
function main_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.timer = timer(...
'ExecutionMode', 'fixedRate', ... % Run timer repeatedly
'Period', 1, ... % Initial period is 1 sec.
'TimerFcn', {@listbox1_Callback, handles});
guidata(hObject, handles);
function listbox1_Callback(hObject, eventdata, handles)
%serConn is the connection to COM port
out = fscanf(handles.serConn);
string = 'degrees1';
t=1;
while(t < 15)
if strncmp(out,string,8)
rxtext = out(14:15);
currList = get(handles.listbox, 'String');
set(handles.listbox,'String',...
[currList ; [temp]]);
end
pause(5);
t = t+1;
end
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by