in reply to Losing bytes with Device::SerialPort ?
I think it unlikely that the problem you have is related to the UART buffer being off or not working properly. You are holding the serial port open so the serial port driver will certainly receive all the data that comes in for you, whether or not your process is scheduled.
The problem might be an unwanted character translation as others have pointed out. Another possibility is that there is something else also listening to the serial port and it is absorbing a character once in a while. This could be a getty or some other process watching for something to happen on a serial port. Some program might also be running that expects to talk to some kind of transparent serial port dongle like an X10 Firecracker that really isn't so transparent after all.
Since it sounds like you have a magic sequence at the start of every received message (0x55 0xaa), you can use this to synchronise to the start of a message and recover from the situation where you have fallen out of sync due to a lost character. The details of doing this depend on whether or not the protocol is designed so that the magic sequence cannot possible occur in the body of a message (maybe it would be quoted if it does appear). To do this, you should read characters one at a time until you find a 0x55 followed by a 0xaa, use this to detect that you have come to the start of a new message, and then read the rest of the header in bulk (and then the body in bulk).
In order to solve your problem, you will probably want to dump everything you read from the serial port into a debugging log. When you get a corrupted message, analyze the PREVIOUS message in the log to see how it ended. You might find that the end of the previous message contained the start of the current one, which would be wrong and would indicate the size of the previous message was one byte off.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Losing bytes with Device::SerialPort ?
by BrowserUk (Patriarch) on Dec 22, 2005 at 16:05 UTC | |
by Celada (Monk) on Dec 22, 2005 at 22:48 UTC | |
by BrowserUk (Patriarch) on Dec 22, 2005 at 23:05 UTC | |
|
Re^2: Losing bytes with Device::SerialPort ?
by Anonymous Monk on Dec 23, 2005 at 08:42 UTC | |
by Celada (Monk) on Dec 23, 2005 at 19:56 UTC | |
by Anonymous Monk on Dec 23, 2005 at 10:50 UTC |