Revision 2.6
3.3 Modbus Operation
WebRelay-Quad™ can be controlled (and read) using Modbus/TCP protocol. This provides a
standard means of using WebRelay-Quad™ in conjunction with devices and software from other
manufacturers. This section contains the information necessary to communicate with WebRelay-
Quad™ using Modbus/TCP. This is not a tutorial on Modbus and it is assumed that reader is
already familiar with Modbus. Detailed Modbus information can be found at
http://www.modbus.org.
It is important to note that when the control password in WebRelay-Quad™ is enabled,
Modbus/TCP communications are disabled. This is because Modbus/TCP does not provide a
mechanism for password protection. Make sure the control password is disabled (default) before
using Modbus with WebRelay-Quad™.
WebRelay-Quad™ functions as a Modbus server. Client devices open a connection with
WebRelay-Quad™ on port 502 (unless another modbus port is selected) and sends commands or
requests to to read the state of a relay, or change a relay. When WebRelay-Quad™ receives a
command, it will perform the desired function and return a response. The following commands are
available:
━ Read Coils (Modbus function 01) - read the status of the relay (and/or the input).
━ Write Single Coil (Modbus function 05) - change the relay state
━ Write Multiple Coils (Modbus Function Code 15) – change multiple relays at the same time
━ Write Multiple Registers (Modbus function 16) - pulse the relay or multiple relays.
Multiple commands may be sent without closing and re-opening the connection but if no data is
transferred for about 50 seconds the connection will time out. To keep the connection open, a
read request can be sent periodically.
3.3.1 Read Coils (Modbus Function Code 01 (0x01))
This function returns the state of the relay coil(s).
Relay 1 is at address 0x0000, relay 2 is at address 0x0001, relay 3 is at address 0x0002, and
relay 4 is at address 0x0003. Multiple relays may be read at the same time by specifying the
correct starting address and quantity of coils. When address 0x0000 is used, the quantities of
coils can be 0x0001, 0x0002, x0003 or 0x0004. When address 0x0003 is used, the only valid
quantity of coils is 0x0001. This means that relays 1 and 4 cannot be read without reading relays
2 & 3.
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 ~ 0x0003)
Quantity of coils (2 Bytes): 0x0002 (0x0001 ~ 0x0004)
Character String Example:
char read_coils_mb_request[] =
Response
Modbus/TCP:
Transaction identifier (2 Bytes): 0x0001
Xytronix Research & Design, Inc.
{0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0xff, 0x01, 0x00, 0x00, 0x00, 0x02 };
WebRelay-Quad™ Users Manual
page 32
Need help?
Do you have a question about the WebRelay-Quad X-WR-4R1-5 and is the answer not in the manual?