RS232 with Matlab

K

Thread Starter

killer

Hey guys,

This is my first article here. I hope some of u nerds can help me out. I try to read in data from RS 232 using serial port and matlab. I just dont know how to keep reading the data from RS-232 given that the program runs forever.
 
A

Ahmad Colahi

s = serial('com1');
s.InputBufferSize = 10;
fopen(s);
fid = fopen('c:\out.txt','w')

a = fread(s,8);
fwrite(fid,char(a));

fclose(s);
fclose(fid);
 
when I pick the RS232 data, I write the program listed below.

s=serial('COM1');
set(s,'InputBufferSize',20);
fopen(s);
acc=fscanf(s,'%d');
fclose(s);

However, I could not use the acc matrix immediately. for instance,I put the logic sentence in the for loop.

acc(i)=fscanf(s,'%d');

however, the program will be terminated,

could somebody kindly help me to put the rs-232 data into the matrix and let me go the following calculations?

Thanks

Ray
 
Top