05-02-2006 02:16 AM
05-02-2006 10:24 PM
Hi Giridhar,
Receiving a modbus RTU message is a lot harder for a slave than the master because of message synching issues if an error occurs. The algorythm I have used successfully goes like this:
If you have done this in stages, then you will have all portions of the msg. I bundled then into a cluster with address, function, data, crc, status. The status indicated whether all was received correctly or if an error occurred. I have considered altering this to run a string through the stages and add the data to it as it arrives.
To deal with timeouts etc, I ran an standard error cluster through the above vi stages. Things like serial port timeouts were then captured and blocked the rest of the message handler from putting together a message with bad data.
If a timeout occurred, I had an error handler that cleared characters from the buffer until a gap occurred (i.e. a timeout of about a three character time length indicating the message had finished). This is actually the trickier part of the whole thing – recovering from an error (like a missed msg byte) and resynching again. Easier for the master – you just wait awhile and clear the receive buffer, but the slave must be ready to receive the next message header.
Note that this procedure does not handle multiple slaves, where each slave must reject msgs from other slaves. The way I was going to handle this was to check the address as it was received and if it did not match, then to handle the message according to the error case above.
Hope this helps, it is a lot more verbose than I intended when I stated writing this reply!
Derek