Prev: simulink / variables
Next: simulink / variables
From: Chen Zhao on 25 Jun 2010 13:02 Hi, I'm making a GUI that displays a information according to the data read from a serial port. The device outputs data every 5 seconds, so the GUI updates information every 5 seconds. I want to include a uicontrol toggle button that will start/stop receiving data. When I use fread (serial), the program waits until 64 bytes of data is received; this means it could be waiting for up to 5 seconds. During this time, none of the callbacks from any of the uicontrols work, until fread gets its 64 bytes. Is there a way I can get around this so that the callbacks work instantly, even when fread is waiting for data? Here's a part of my code: function out = sread() delete(instrfind); s = serial('COM1'); set(s,'BaudRate',9600); fopen(s); fprintf(s,'*IDN?'); out = fread(s,64); % this is where the program waits fclose(s); delete(s); end function button_callback(varargin) state = get(button(1),'Value'); while state == get(button(1),'Max') state = get(button(1),'Value'); pause(0.01); set(button(1),'str','Stop'); if state == get(button(1),'Min') break; end read(); % this function includes sread() and also updates GUI end set(button(1),'str','Start'); end Thanks -Chen
|
Pages: 1 Prev: simulink / variables Next: simulink / variables |