Update plot in GUIDE

11 views (last 30 days)
Martin Thompson
Martin Thompson on 25 Feb 2018
Commented: Martin Thompson on 27 Feb 2018
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 Comment
Martin Thompson
Martin Thompson on 27 Feb 2018
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!

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!