loading
 
serial port reading problem
Liu from United Kingdom  [2 posts]
16 year
Hi,

I am trying to stream data from a digital compass, the basic code below:

s=serial('COM9');
set(s,'BaudRate',9600);
fopen(s)
str=fscanf(s);
fclose(s)

the data can be read one time because the program only perform fcanf one time, now I want to update the robot position all the time, so I need to fscanf the COM port all the time until I press stop in my MATLAB GUI, I used while loop in the program like

while (s.Stauts=='open')
str=fscanf(s);
end

problem is the com port is opened all the time caused the program in a dead loop, I can not use the fclose to shut down the serial port any more? how can I add a loop to keep reading the port as well as I can stop the reading when I want? thanks for your hints. I appreciate your help 10000000X times in advance!

Jiazhong
Anonymous 16 year
You have to look into overlapped or asynchronous IO. This will complicate things tremendously and I'm not sure Matlab (which we do not support by the way) even provides that. Perhaps this is a better question to be asked on the Mathworks website? There is quite a bit of examples and discussions surrounding matlab elsewhere on the web.

If you are, however, interested in using your compass with RoboRealm let us know and we will see what we can do about supporting it.

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index