Revision 1.1
WebSwitch™ Users Manual
3.4.1 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. In addition, the discrete inputs can be read using this function which allows the full
state of WebSwitch™ to be read in a single transaction.
Valid Starting Address and Quantity of Coils combinations:
Valid starting address can fall in the range of 0x0000 and 0x0004. Valid quantities can also fall in the
range of 0x0000 and 0x0004. The only restriction is that the sum of the starting address and the quantity
of coils must not be greater than 0x0004. For example, if you want to read 0x0004 bits, two coils and two
inputs, then the starting address would be 0x0004. If you want to read the inputs only, you may read
0x0002 bits and use the starting address of 0x0002. On the other hand, you may want to read the
second outlet state only. This can be achieved by starting at address 0x0001 and using a quantity of
0x0001.
Request
Modbus/TCP:
Transaction identifier (2 Bytes): 0x0001
Protocol identifier (2 Bytes): 0x0000
Length (2 Bytes): 0x0006
Unit Identifier (1 Byte): 0xff
Modbus:
Function Code (1 Byte): 0x01 (read coils)
Starting address (2 Bytes): 0x0000 (0x0000 to 0x0004)
Quantity of Coils (2 Bytes): 0x0004 (0x0001 to 0x0004)
Character String Example
:
char read_coils_mb_request[ ]={0x00, 0x01, 0x00, 0x00, 0x00, 0x06,
0xff, 0x01, 0x00, 0x00, 0x00, 0x04 };
Response
Modbus/TCP:
Transaction identifier (2 Bytes): 0x0001
Protocol identifier (2 Bytes): 0x0000
Length (2 Bytes): 0x0004
Unit identifier (1 Byte): 0xff
Modbus:
Function code (1 Byte): 0x01 (read coils)
Byte count (1 Byte): 0x01
Coil status (1 Byte): 0x00 to 0x0F (bit 0=outlet state 1, bit 1=outlet state 2, bit 3=input state 1, bit
4=input state 2)
Xytronix Research & Design, Inc.
75