Unstable streaming from external device

2 Ansichten (letzte 30 Tage)
Nicolò Francesco Bernardi
Nicolò Francesco Bernardi am 8 Mär. 2011
I have to receive a continuous stream of information from a device connected to the serial port. The device continuously transmits one byte at a frequency of 200 Hz. I can succesfully connect to the device, with
s = serial('COM6');
set(s,'BaudRate',115200,'DataBits',8,'StopBits',1)
fopen(s);
and also I get the stream of data, with
data(i) = fread(s,1,'uint8');
My problem is that during the acquisition process I often loss pieces of information, in an erratic and unpredictable way. Thus, the streaming appears so far neither stable nor reliable. What could be the problem? Maybe something with memory/buffer, or else that the computer occasionally starts some other operation and looses the timing with the serial port...or something similar; in fact, it improves a little with a faster computer and it gets worse if I load the routine with other operations (e.g., real-time plotting of the data during the streaming).
How could I fix this problem? Is there any other explanation? The slowest machine I'm using it's an Intel Core Duo CPU T7500 @ 2.20 Ghz, 2.12 GHz and 3 GB of RAM, with Windows XP. Matlab version is 2008b. However, it seems to me that 200Hz transmission rate should be well below the limits of any actual computer, so the problem should be something else. Thank you very much

Antworten (2)

Walter Roberson
Walter Roberson am 8 Mär. 2011
You are only using 2000 bits per second of bandwidth, but you are configured for 115200 bits per second. The higher the rate you configure for, the more problems you will have with electromagnetic noise and poor-quality cables and flow control. If you switch down to 2400 or 4800 bits per second, you should be fine with those factors in all but the noisiest environments. 9600 is the practical dividing line, usually working but not always. Above 9600 it is advised to use hardware flow control.

Vieniava
Vieniava am 8 Mär. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by