I’ve got a two controllers one with uclinux, second without any os. They are connected by serial port. I check that new message received with select function. Message length might be different and controller without os sends message per bytes. So, there is a possibility that one controller does not send whole message and select function returns that new message is available. After that I will receive incorrect message.
How I can prevent this situation?
I’ve got a two controllers one with uclinux, second without any os. They are
Share
The
selectfunction will only tell you that you can read at least one byte without blocking. The message sent on the serial port needs to either have a predefined header that contains the total length of the message, or a special end-of-message marker.When
selectsays you can read, you read as many bytes as you can and put them in a buffer. If the message is not complete you go back to wait for more data withselect. When more data arrives you continue append to the buffer. When a complete message is received you process it.