Information Technology Reference
In-Depth Information
18.2 Function codes
Each value is addressed via a register. The first register address on the Modbus is referenced
to zero. The following sections outline the main function codes.
18.2.1 Read coil status (01)
This function reads the ON/OFF status in Boolean logic. The query message specifies the
starting coil and quantity of coils to be read. For example to read 12 values (0Ch) from de-
vice 18 (12h), starting at address 02DE, then the following is used:
Address Function Start address (hi) Start address (lo) No. (hi) No. (low) LRC
:12 01 02 DE 00 0C 01
The response contains the coil status, in which the data field is packed with bit values, one
for each coil. A one represents ON, a zero represents OFF and the lsb of the first byte con-
tains the first address coil. Other coil values follow this and, if the number of coil values is
not a multiple of eight, then zeros are used to pad the end values. The byte count field pre-
cedes the coil values and specifies the quantity of complete bytes of data. An example re-
sponse to the above query is
Address Function Number of bytes Data values (8 to 1) Data values (12 to 9) LRC
:12 01 02 BA 10 FB
Thus, if the addressed coils are Coil 1 to Coil 12, then the Coils 8 to Coil 1 have the status of
1101 1100 (BAh), which means that Coil 8, Coil 7, Coil 5, Coil 4 and Coil 3 are ON, and
Coil 6, Coil 2 and Coil 1 are OFF. The other four coils are 0001 for Coil 12 to Coil 9. Thus,
Coil 9 is ON and Coil 12, Coil 11 and Coil 10 are OFF.
18.2.2 Read Input Status (02)
This function reads the ON/OFF status of discrete inputs from the slave device. This function
reads the ON/OFF status of logic Boolean. It has the same format as the read coil Status
function code. For example to read four values, starting at address 11FF, then the following is
used:
Address Function Start address (hi) Start address (lo) No. (hi) No. (low) LRC
:12 02 11 FF 00 04 D8
The response is in the same format as the read coil status function. An example response to
the above query is
Address Function Number of bytes Data values (4 to 1) LRC
:12 02 01 02 CC
which returns the status of the four inputs as
Input 4
(Address: 1202)
OFF (0000 0 010)
Input 3
(Address: 1201)
OFF (0000 0 0 10)
Input 2
(Address: 1200)
ON
(0000 00 1 0)
Input 1
(Address: 11FF)
OFF (0000 001 0 )
Search WWH ::




Custom Search