Modbus Exception Code

M

Thread Starter

MF

Hello,

I have to create a light implementation of modbus server with "additional address" and "error check". If I receive a packet with lack of fields what kind of "modbus exception code" I have to respond?
For example: if I receive <pre>
ADDITIONAL ADDRESS 1B
READ HOLDING REGISTERS 1B
STARTING ADDRESS 2B
QUANTITY OF REGISTERS 1B instead of 2B
CRC16 2B</pre>
what kind of "modbus exception code" I have to respond?
 
If you are lacking fields in your Modbus request, the CRC is likely incorrect as well. Even if the CRC is correct (let's say for some reason the master built a "bad" packet but calculated the correct CRC for this packet), if it's missing a field that you would consider required, then in my opinion I don't think a response should be generated. Think about it from the perspective of multiple nodes on the network: if a node receives a malformed packet, there are two possible scenarios:

1. The packet was sent malformed, and therefore all devices on the network received the same packet. To prevent bus contention, no devices should respond.

2. The packet was sent correctly, but for some reason the slave received it incorrectly (due to noise, etc.) Because the packet may have been targeted at a different slave, and that slave may have received it correctly, the slave receiving it incorrectly should again not respond to prevent bus contention.

In the end, you should not respond to a packet (either successfully or with an exception response) unless you are quite certain that the request was targeted specifically at you.

Darrin
 
Top