I'm running an ARM-based computer that receives data from an external device via serial. The external device alternates between bursts of data and idling: 25 bytes, then 3ms idle, 25 bytes, 3ms idle, and so on. However, every so ofter it drops a byte in the middle of the packet and only outputs 24 bytes. Because of the slight inconsistency, I'm trying to figure out a way to detect when the line goes idle so I can be confident that I'm processing at the beginning of the next packet.

The packet does use start and stop bytes, 0xF0 and 0x00, but they are not unique. A 0xF0 or 0x00 may arrive as data in the middle of the packet as well without any special handling. I believe detecting 3ms of idle followed by a start byte is the only way to be certain a new packet is arriving.

Is there a way in Linux to detect the idle line and synchronize to the beginning of a new packet this way? I'm coding primarily in C using open() and read() on the serial port, but a shell script would work too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.