V Exception Responses
V Exception Codes
4.1 Exception Responses
Except for broadcast messages, when a master device sends a
query to a slave device it expects a normal response. One of four
possible events can occur from the master's query:
V If the slave device receives the query without a communication
error, and can handle the query normally, it returns a normal
V If the slave does not receive the query due to a communication
error, no response is returned. The master program will
eventually process a timeout condition for the query.
V If the slave receives the query, but detects a communication
error (parity, LRC, or CRC), no response is returned. The
master program will eventually process a timeout condition for
V If the slave receives the query without a communication error,
but cannot handle it (for example, if the request is to read a
nonexistent coil or register), the slave will return an exception
response informing the master of the nature of the error.
The exception response message has two fields that differentiate
it from a normal response:
Function Code Field
In a normal response, the slave echoes the function code of the
original query in the function code field of the response. All
function codes have a most significant bit (MSB) of 0 (their values
are all below 80 hexadecimal). In an exception response, the slave
sets the MSB of the function code to 1. This makes the function
code value in an exception response exactly 80 hexadecimal
higher than the value would be for a normal response.
With the function code's MSB set, the master's application
program can recognize the exception response and can examine
the data field for the exception code.
In a normal response, the slave may return data or statistics in
the data field (any information that was requested in the query).
In an exception response, the slave returns an exception code in
the data field. This defines the slave condition that caused the
exception. Here is an example of a master query and slave
exception response. The field examples are shown in hexadecimal.
In this example, the master addresses a query to slave device 10
(0A hex). The function code (01) is for a Read Coil Status
operation. It requests the status of the coil at address 1245 (04A1
Note: Only one coil is to be read, as specified by the number of
coils field (0001).
If the coil address is nonexistent in the slave device, the slave will
return the exception response with the exception code shown (02).
This specifies an illegal data address for the slave. For example, if
the slave is a 984-385 with 512 coils, this code would be returned.
4.2 Exception Codes