Operation
WebRelay-10 Users Manual
3.4.4 Read Coils - Modbus Function Code 01 (0x01)
This function returns the state of the relay coils. 0 denotes that the coil is not energized, 1 denotes that
the coil is energized.
Request
Valid starting address can fall in the range of 0x0000 and 0x0009. Relay 1 is at address 0x0000, Relay
2 is at address 0x0001, Relay 3 is at address 0x0002, and so forth. Multiple relays may be read at the
same time by specifying the correct starting address and quantity of coils to be read.
Start Address:
0x0000
(coil 1) to
0x0009
(coil 10)
Coil Quantity: 0x0001 (1 coil) to 0x000A (10 coils)
The sum of the start address and coil count cannot exceed the maximum coil count or an error response
will be returned.
Modbus TCP Request Frame Example – Read Coils 2 through 10
Field Name
Length
Function
Example Data
Transaction Identifier
2 bytes
Synchronization number.
0x0001
Protocol Identifier
2 bytes
Zero for Modbus/TCP
0x0000
Message Length
2 bytes
Number of bytes in frame (below)
0x0006
Unit Identifier
1 byte
Slave Address (0xff if not used)
0xFF
Function Code
1 byte
Read Coils
0x01
Data
4 bytes
Start Address (
0x0000-0x0009
)
Quantity of coils to read (
0x0001-0x000A
)
0x0001
0x0009
Tx String: 00 01 00 00 00 06 FF 01 00 01 00 09
Response
The WebRelay-10 will respond to the request with a data field of one or two bytes, each bit representing
the coil status. A '
1
' indicates the relay is
ON
. A '
0
' indicates that the relay is
OFF
. A single byte is
returned if no more than 8 coils are requested. Two bytes are returned if the status of nine or 10 coils
are requested.
Consequently, the message length will be 0x0004 bytes or 0x0005 bytes, depending on the number of
coils.
Bit zero of the return value will be the state of the coil corresponding to the start address. For example, if
a start address of 0x0006 is used, bit zero will be the status of coil 7. The tables below show two
examples.
Coil status for relays 7-9, start address of 0x0006 and quantity of 3:
Single Byte
Bit 7
6
5
4
3
2
1
Bit 0
X
X
X
X
X
Relay
9
Relay
8
Relay
7
Full, 10-bit return value:
Upper Byte
Lower Byte
Bit 15 14
13
12
11
10
9
8
7
6
5
4
3
2
1
Bit 0
X
X
X
X
X
X
Relay
10
9
8
7
6
5
4
3
2
Relay
1
page 66
Xytronix Research & Design, Inc.