Why am I unable to generate bytes-available events from my Serial port ?
I have a problem using an action function property in a serial connection with MATLAB. I want to connect the serial port of my computer to a device in interrupt mode (when my computer receives 10 bytes from the serial port, plot this data). I used the BytesAvailableAction function and these two scripts:
The first script is connect.m to establish a connection:
global ss=serial('com1');s.bytesavailableactionmode='byte';s.bytesavailableactioncount=15;s.bytesavailableaction='plotout';fopen(s)
The MATLAB file that I expect to run when acquisition is interrupted is plotout.m:
function plotout(obj,event)global sglobal in1;if s.bytesavailable>1in1=fread (s,s.bytesavailable/2,'int16');load in ints=size(in);tad=size(in1);in(1,ts(2)+1:ts(2)+tad(1))=in1';save in inplot(in)pauseend
When I use these MATLAB files, plotout executes only one time and stops until I push the ‘Enter’ button.
I send 45 bytes to my computer's serial port from another port (COM2) with these commands:
s2=serial('com2');fopen(s2)for i=1:45fwrite(s2, i,’int16’);end
When it receives the first 15 bytes, it plot this data and stops, and I must push the ‘Enter’ button.
I want to be able to plot all the received data automatically without my interference
Best Answer