Why does the serial port object in MATLAB periodically seems to stall and miss some bytes of data?

20 views (last 30 days)
I am having an issue with the serial port object missing bytes of data periodically. I am reading the data with a very high baud rate (around 1.25 MBaud).
It appears that serial port object periodically stalls and misses bytes of data. The issue is more apparent and the packet loss seems to be correlated with switching between processes using ALT+TAB or with the processes that are run in the background (like antivirus program).

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 31 Mar 2024 at 0:00
Edited: MathWorks Support Team on 31 Mar 2024 at 21:03
On modern desktop systems, the serial port is given a lower priority than other
services in order to enhance the desktop experience. As one example, the OS will usually disable the interrupt handling when data reaches the port, and pool the interrupts that traditional DOS-based systems respect, to prevent slowing down GUI updates. The user may notice that their mouse is jumpy during these times, which is a sign of the same issue.
To work around these scheduling glitches as the system updates the desktop, enable serial hardware flow control on both sides of the serial connection. The serial port hardware will then pause until the data is read rather than letting the data bounce off a full buffer.
Serial hardware flow control is documented in the MATLAB Serial docs. The following is the link to this documention:
  1 Comment
Walter Roberson
Walter Roberson on 11 Apr 2016
David, you need hardware assistance for that, a serial card with a hefty buffer and that does DMA. That introduces latency. Situations that need low latency need a small buffer, which runs a higher risk of buffer overflow.
Alternately you can use a data acquisition card that handles the serial port.
Keep in mind, David, that in your Question that you posted about your Psychtoolbox experiments, you are not using a serial port, you are using a USB port with a driver that is emulating a serial port, and so you are at the mercy of the quality of implementation of that driver, and you are at the mercy of the way serial ports are emulated over USB, as USB is a master/slave poll-and-response relationship.

Sign in to comment.

More Answers (0)

Products


Release

R2008b

Community Treasure Hunt

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

Start Hunting!