Update plot in GUIDE

조회 수: 11 (최근 30일)
Martin Thompson
Martin Thompson 2018년 2월 25일
댓글: Martin Thompson 2018년 2월 27일
I have a timer function that ticks every second and calls a display update function:
function update_display(hObject,eventdata,hfigure)
% Timer timer1 callback, called each time timer iterates.
% Update plot data
handles = guidata(hfigure);
set(handles.main_plot, 'XData', [1:length(handles.data)],'YData',handles.data)
drawnow
guidata(hfigure, handles);
% END USER CODE
Problem is, the plot doesnt update.I know the function is entered. Also in the program there is a bytesavailablefcn that triggers and harvests data from the serial port:
% START USER CODE
function update_function(hObject,eventdata,hfigure)
handles = guidata(hfigure)
fread(handles.s, 1,'int8');
fread(handles.s, 1,'int8');
fread(handles.s, 1,'int8');
handles.data(handles.count) = (fread(handles.s, 1,'uint8'));
fread(handles.s, 1,'int8');
fread(handles.s, 1,'int8');
fread(handles.s, 1,'int8');
fread(handles.s, 1,'int8');
fread(handles.s, 1,'int8');
handles.count = handles.count + 1;
handles.s.BytesAvailable;
handles.s.ValuesReceived;
guidata(hfigure, handles)
There's about 540 bytes arriving per second, and the function harvests every 9 bytes (so 60 times a second) but this doesnt seem to be the issue.
I know that the timer callback is being executed every second, it should be uninterruptible by default I read. Could it be because there are too many values in the array to plot? I am suspicious that the timer callback function is actually being interrupted.
Can anyone see where I'm going wrong?
Cheers
  댓글 수: 1
Martin Thompson
Martin Thompson 2018년 2월 27일
For anyone watching this, firstly I moved the timer start function to outside of the opening function. This however only made it work about 1 out of 4 times.
The real solution was to define my bytes available function after I used fopen. Despite setting my button function to uninterruptible, and defining the bytes available function BEFORE fopen was used (theoretically shouldn't that mean nothing is being recieved), AND making sure the serial port was properly closed and cleared everytime. It was the solution.
Also implicit here is that the bytesavailable function was actually interrupting the uninterruptible button function before fopen could actually be used!

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by