Unstable streaming from external device
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Walter Roberson
2011-3-8
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.
0 个评论
Vieniava
2011-3-8
I suggest you to use serial as in http://www.mathworks.com/help/techdoc/matlab_external/bytesavailablefcn.html.
Here is howto for writing callback function - http://www.mathworks.com/help/techdoc/matlab_external/f73779.html#f75633
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Instrument Control Toolbox Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!