Template: Modbus RTU Relay Protocol V2

From Waveshare Wiki
Jump to: navigation, search

Development Protocol V2

From September 2021, the V2 of the development protocol will be adopted. The V1 is not compatible with Modbus commands and now the V2 is fully compatible with the Modbus protocol.
There is no difference in hardware between V1 and V2. Customers who have purchased the V1 version but need to use the V2 development agreement, can contact customer service to upgrade the firmware.

Function code

Function code Description
01 Read the state of Relay
03 Read the address and version
05 Write a single Relay
06 Set baud rate and address
0F Write all Relays

Control Single Relay

Command: 01 05 00 00 FF 00 8C 3A

Byte Meaning Description
01 Device address 0x00: the broadcast address; 0x01-0xFF: device addresses
05 05 Command Command for controlling Relay
00 00 Address The register address of controlled Relay, 0x0000 - 0x0008
FF 00 Command 0xFF00: open Relay;
0x0000: close Relay;
0x5500: flip Relay
8C 3A CRC16 The CRC16 checksum of the first six bytes

Answer: 01 05 00 00 FF 00 8C 3A

Byte Meaning Description
01 Device address 0x00: the broadcast address; 0x01-0xFF: dives addresses
05 05 Command Command for controlling relay
00 00 Address The register address of controlled Relay,0 x 0000-0 x 0008
FF 00 Command 0xFF00: open Relay;
0x0000: close Relay
0x5500: flip Relay
8C 3A CRC16 The CRC16 checksum of the first six bytes.

Examples: [Device with address 01]:
Relay 0 OFF: 01 05 00 00 00 00 CD CA
Relay 1 ON: 01 05 00 01 FF 00 DD FA
Relay 1 OFF: 01 05 00 01 00 00 9C 0A
Relay 2 ON: 01 05 00 02 FF 00 2D FA
Relay 2 OFF: 01 05 00 02 00 00 6C 0A
Relay 3 ON: 01 05 00 03 FF 00 7C 3A
Relay 3 OFF: 01 05 00 03 00 00 3D CA
Relay 0 Flip: 01 05 00 00 55 00 F2 9A
Relay 1 Flip: 01 05 00 01 55 00 A3 5A
Relay 2 Flip: 01 05 00 02 55 00 53 5A
Relay 3 Flip: 01 05 00 03 55 00 02 9A

Control All Relays

Command: 01 05 00 FF FF 00 BC 0A

Byte Meaning Description
01 Device Address 0x00: the broadcast address; 0x01-0xFF: device address
05 05 Command Control relays
00 FF Address Fixed 0x00FF
FF 00 Command 0xFF00: Relay on
0x0000: Relay off
0x5500: Relay flips
BC 0A CRC16 The CRC16 checksum of the first six bytes

Answer: 01 05 00 FF FF 00 BC 0A

Byte Meaning Description
01 Device address 0x00: the broadcast address; 0x01-0xFF: devices address
05 05 command Command for controlling Relay
00 FF Address Fixed 0x00FF
FF 00 CRC16 0xFF00: Relay open;
0x0000: Relay close;
0x5500: Relay flip
BC 0A CRC16 The CRC16 checksum of the first six bytes

Example:
[Device with Address 01]:
All relays open: 01 05 00 FF FF 00 BC 0A
All relays closed: 01 05 00 FF 00 00 FD FA
All relays flip: 01 05 00 FF 55 00 C2 AA

Read States of Relays

Command:01 01 00 00 00 08 3D CC

Bytes Meaning Description
01 Device address 0x00: the broadcast address; 0x01-0xFF: device addresses
01 01 Command Command for checking states of Relay
00 00 Initial Address Fixed 0 x 0000
00 08 Command Fixed 0 x 0008
3D CC CRC16 The CRC16 checksum of the first six bytes

Answer:01 01 01 00 51 88

Byte Meaning Description
01 Device address 0x00: the broadcast address; 0x01-0xFF: device addresses
01 01 Command Command for checking states of Relay
01 Number The number of bytes returned
00 State The state of Relay
Bit0: The state of the first Relay;
Bit1: The state of the second Relay;
Bit2: The state of the third Relay;
……
Bit7: The state of the eighth Relay
8C 35 CRC16 The CRC16 checksum of the first six bytes

Examples:

[Device with Address 01]

Command: 01 01 00 00 00 08 3D CC
Answer: 01 01 01 00 51 88 //Close all Relays
Command: 01 01 00 00 00 08 3D CC
Answer: 01 01 01 01 90 48 //Open Relay 0 and close other Relays
Command: 01 01 00 00 00 08 3D CC
Answer: 01 01 01 41 91 B8 //Open Relay 0 and Relay 6, close other Relays

Write States of Relays

Command: 01 0F 00 00 00 08 01 FF BE D5

Bytes Meaning Description
01 Device address 0x00: the broadcast address; 0x01-0xFF: the device address
0F 0F Command Write Relay Status Command
00 00 Relay start address Fixed 0x0000
00 08 Number of relays Fixed 0x0008
01 Number of bytes Fixed 0x01
FF Relay Status Bit0: control the first relay;
Bit1: control the second relay;
Bit2: control the third relay;
……
Bit7: Control the eighth relay
BE D5 CRC16 CRC16 checksum of the first 6 bytes of data

Answer: 01 0F 00 00 00 01 94 0B

Bytes Meaning Description
01 Device address 0x00: the broadcast address; 0x01-0xFF: the device address
0F 0F Instruction All Register Control Instructions
00 00 Address Fixed 0x0000
00 08 Number of relays Fixed 0x0008
54 0D CRC16 CRC16 checksum of the first 6 bytes of data

Example:
[Device with Address 01]
All relays on: 01 0F 00 00 00 08 01 FF BE D5
All relays off: 01 0F 00 00 00 08 01 00 FE 95
0-1 ON; 3-7 OFF: 01 0F 00 00 00 08 01 03 BE 94

Relay Flash ON/OFF Command

Command: 01 05 02 00 00 07 8D B0

Bytes Meaning Description
01 Device address 0x00: the broadcast address; 0x01-0xFF: the device address
05 05 Command Single Control Command
02 Command 02 for flashing on, 04 for flashing off
00 Relay Address The address of the relay to be controlled, 0x00~0x08
00 07 Interval time Delay time is data*100ms
Value: 0x0007, delay: 7*100MS = 700MS
8D B0 CRC16 CRC16 checksum of the first 6 bytes of data

Answer: 01 05 02 00 00 07 8D B0

Bytes Meaning Description
01 Device address 0x00: the broadcast address; 0x01-0xFF: the device address
05 05 Command Single Control Command
02 Command 02 for flashing on, 04 for flashing off
00 Relay address To control the relay address, 0x00~0x08
00 07 Interval time Delay time is data*100ms
Value: 0x0007, delay: 7*100MS = 700MS
8D B0 CRC16 CRC16 checksum of the first 6 bytes of data

Example:

[Device with Address 01]

Relay 0 is open: 01 05 02 00 00 07 8D B0 //700MS = 7*100MS = 700MS
No.1 relay out of the way: 01 05 02 01 00 08 9C 74 //800MS
No.0 relay flashes off: 01 05 04 00 00 05 0C F9 //500MS
No.1 relay flashes off: 01 05 04 01 00 06 1D 38 //600MS

Set Baud Rate Command

Command: 00 06 20 00 00 05 43 D8

Bytes Meaning Description
00 device address 0x00: the broadcast address; 0x01-0xFF: the device address
06 06 command set baud rate and address
20 00 command register 0x2000 sets the baud rate, 0x4000 sets the device address
00 parity 0x00: no parity check, 0x01: even parity check, 0x02: odd parity check
05 baud rate value the corresponding baud rate value:
0x00: 4800
0x01: 9600
0x02: 19200
0x03: 38400
0x04: 57600
0x05: 115200
0x06: 128000
0x07: 256000
43 D8 crc16 CRC16 checksum of the first 6 bytes of data

Answer: 00 06 20 00 00 05 43 D8

Bytes Meaning Description
00 Device address 0x00: the broadcast address; 0x01-0xFF: the device address
06 06 command set baud rate and address
20 00 command register 0x2000 sets the baud rate, 0x4000 sets the device address
00 parity 0x00: no parity check, 0x01: even parity check, 0x02: odd parity check
05 baud rate value the corresponding baud rate value:
0x00: 4800
0x01: 9600
0x02: 19200
0x03: 38400
0x04: 57600
0x05: 115200
0x06: 128000
0x07: 256000
43 D8 CRC16 CRC16 checksum of the first 6 bytes of data

Examples:
[Device with Address 01]

Set baud rate 4800: 00 06 20 00 00 00 83 DB
Set baud rate 9600: 00 06 20 00 00 01 42 1B
Set baud rate 115 200: 00 06 20 00 00 05 43 D8

Set Device Address Command

Command: 00 06 40 00 00 01 5C 1B

Bytes Meaning Description
00 device address 0x00: the broadcast address; 0x01-0xFF: the device address
06 06 command set the baud rate and device address
40 00 command register 0x2000 sets the baud rate, 0x4000 sets the device address
00 01 device address set the device address as 0x0001-0x00FF
5C 1B CRC16 CRC16 checksum of the first 6 bytes of data

Answer: 00 06 40 00 00 01 5C 1B

Bytes Meaning Description
00 device address 0x00: broadcast address; 0x01-0xFF: device addresses
06 06 command set baud rate and device address
40 00 command register 0x2000 sets baud rate, 0x4000 sets device address
00 01 device address the device address set; 0x0001-0x00FF
5C 1B CRC16 CRC16 checksum of the first 6 bytes of data

Examples:
[Device with Address 01]

Set device address as 0x01: 00 06 40 00 00 01 5C 1b
Set device address as 0x02: 00 06 40 00 00 02 1C 1A
Set device address as 0x03: 00 06 40 00 00 03 DD DA

Read Device Address Command

Command: 00 03 40 00 00 01 90 1B

Bytes Meaning Description
00 Device address 0x00: the broadcast address; 0x01-0xFF: the device address
03 03 command read the device address command
40 00 command register 0x4000: read the device address, 0x8000: read the software version
00 01 bytes fixed 0x0001
90 1B CRC16 CRC16 checksum of the first 6 bytes of data

Answer: 01 03 02 00 01 79 84

Bytes Meaning Description
00 device address 0x00: the broadcast address; 0x01-0xFF: the device address
03 03 command Read the software version and the device address command
02 bytes return bytes
00 01 device address set the device address as 0x0001-0x00FF
79 84 CRC16 CRC16 checksum of the first 6 bytes of data

Examples:
[Device with Address 01]
Command: 00 03 40 00 00 01 90 1B
Answer: 01 03 02 00 01 79 84 //address 0x01
[Device with Address 02]
Command: 00 03 40 00 00 01 90 1B
Answer: 02 03 02 00 02 7D 85 //address 0x02
[Device with Address 03]
Command: 00 03 40 00 00 01 90 1B
Answer: 03 03 02 00 03 81 85 //address 0x03

Read Software Version Command

Command: 00 03 80 00 00 01 AC 1B

Bytes Meaning Description
01 Device address 0x00: the broadcast address; 0x01-0xFF: the device address
03 03 command Read the software version and the device address command
80 00 Command register 0x4000: read the device address, 0x8000: read the software version
00 01 Bytes Fixed 0x0001
8F CA CRC16 CRC16 checksum of the first 6 bytes of data

Answer: 01 03 02 00 C8 F0 B8

Bytes Meaning Description
01 Device Adress 0x00: the broadcast address, 0x01-0xFF: the device addresses
03 03 Command Read the software version and the device address command
02 Bytes Return bytes
00 C8 Software version Convert to decimal and move the decimal point to the left by two places to indicate the software version

0x00C8 = 200 = V2.00

F0 B8 CRC16 CRC16 checksum of the first 6 bytes of data

Examples:
Command: 00 03 80 00 00 01 AC 1B
Answer: 03 03 02 00 C8 F1 00 //0x00C8=200=V2.00

Development Protocol V1

From September 2021, the V2 of the development protocol will be adopted. The V1 is not compatible with Modbus commands and now the V2 is fully compatible with the Modbus protocol.
There is no difference in hardware between V1 and V2. Customers who have purchased the V1 version but need to use the V2 development agreement can contact customer service to upgrade the firmware.

Command Format

The command contains 8 bytes:

Byte 1: Device Address
Byte 2: Function code
Byte 3 4: Address of register (big-endian)
Byte 5 6: data of register (big-endian)
Byte 7 8: CRC16 cheksum (little-endian)

Function code

Function code Description
01 Read the state of Relay
03 Read address, revision
05 Write single Relay
06 Configure baudrate, address
0F Write all Relays

Control single relay

Command: 01 05 00 00 FF 00 8C 3A

Byte Meaning Description
01 Device address 0 x 00 is broadcast address;0x01-0xFF are device addresses (Device address is 01 by default)
05 05 Command Command for controlling Relay
00 00 Address The register address of controlled Relay, 0 x 0000 - 0 x 0008
FF 00 Command 0 x FF00: Open Relay;
0 x 0000: Close Relay;
0 x 5500: Flip Relay
8C 3A CRC16 The CRC16 checksum of the first six bytes.

Answer: 01 05 00 00 FF 00 8C 3A

Byte Meaning Description
01 Device address 0 x 00 is broadcast address; 0 x 01-0 x FF are dives addresses
05 05 Command Command for controlling relay
00 00 Address The register address of controlled Relay,0 x 0000-0 x 0008
FF 00 Command 0 x FF00: Open Relay;
0 x 0000: Close Relay
0 x 5500: Flip Relay
8C 3A CRC16 The CRC16 checksum of the first six bytes.

Examples: [Device with address 01]: Open Relay 0: 01 05 00 00 FF 00 8C 3A
Close Relay 0: 01 05 00 00 00 00 CD CA
Open Relay 1: 01 05 00 01 FF 00 DD FA
Close Relay 1: 01 05 00 01 00 00 9C 0A
Open Relay 2: 01 05 00 02 FF 00 2D FA
Close Relay 2: 01 05 00 02 00 00 6C 0A
Open Relay 3: 01 05 00 03 FF 00 7C 3A
Close Relay 3: 01 05 00 03 00 00 3D CA
Flip Relay 0: 01 05 00 00 55 00 F2 9A
Flip Relay 1: 01 05 00 01 55 00 A3 5A
Flip Relay 2: 01 05 00 02 55 00 53 5A
Flip Relay 3: 01 05 00 03 55 00 02 9A

Control all Relay

Command: 01 05 00 FF FF 00 BC 0A

Byte Meaning Description
01 Device address 0 x 00 is broadcast;0 x 01-0 x FF are devices address
05 05 command Command for controlling Relay
00 FF Address Fixed 0 x 00FF
00 FF Command 0 x 00FF: Open Relay;
F 00 CRC16 The CRC16 checksum of the first six bytes

Answer: 01 05 00 FF FF 00 BC 0A

Byte Meaning Description
01 Devices 0 x 00 is broadcast address;0 x 01-0 x FF is device address
05 05 Command Command for controlling
00 FF Address Fixed 0 x 00FF
FF 00 Command 0 x FFFF: Open Relay;
0 x 0000: Close Relay;
0 x 5A00: Flip Relay;
BC 0A CRC16 The CRC16 checksum of the first six bytes.

Example:

[Device with address 01]:

Open all Relays: 01 05 00 FF FF 00 BC 0A
Close all Relays: 01 05 00 FF 00 00 FD FA
Flip all Relays: 01 05 00 FF 55 00 C2 AA

Read states of Relays

Command:01 01 00 00 00 08 3D CC

Bytes Meaning Description
01 Device address 0 x 00 is broadcast address;0 x 01-0 x FF are device addresses
01 01 Command Command for checking states of Relay
00 00 Address Fixed 0 x 00FF
00 08 Command Fixed 0 x 0008
3D CC CRC16 The CRC16 of the first six bytes

Answer: 01 01 01 00 8C 35

Byte Meaning Description
01 Device address 0 x 00 is broadcast address; 0 x 01-0 x FF are device addressese
01 01 Command Command for checking states of Relay
01 Number The number of bytes returned。
00 State The state of Relay
Bit0: The state of the first Relay;
Bit1: The state of the second Relay;
Bit2: The state of the third Relay;
……
Bit7: The state of the eighth Relay;
8C 35 CRC16 The CRC16 checksum of the first six bytes.

Examples:

[Device with Address 01]

Command: 01 01 00 00 00 08 3D CC
Answer: 01 01 01 00 51 88 //Close all Relays
Command: 01 01 00 00 00 08 3D CC
Answer: 01 01 01 01 90 48 //Open Relay 0 and close other Relays
Command: 01 01 00 00 00 08 3D CC
Answer: 01 01 01 41 91 B8 //Open Relay 0 and Relay 6, close other Relays

Write Relay

Command: 01 0F 00 00 00 08 01 FF BE D5

Byte Meaning Description
01 Device address 0x00 is the boradcast address;0x01-0xFF are device addresses
0F 0F Command Command for writing Relay
00 00 Begin Address Fixed 0x0000
00 08 number of Channels Fixed 0x0008
01 number of bytes Fixed 0x01
FF Status of Relays Bit0: Control the first channel;
Bit1: Control the second channel;
Bit2: Control the third channel;
...
Bit7: Control the seventh channel:
BE D5 CRC16 The CRC16 checksum of the first six bytes.

Answer: 01 0F 00 00 00 08 54 0D

Byte Meaning Description
01 Device address 0x00 is the boradcast address; 0x01-0xFF are device addresses
0F 0F Command Command for controlling all Relay
00 00 Address Fixed 0x0000
00 08 number of channels Fixed 0x0008
54 0D CRC16 The CRC16 checksum of the first six bytes

Example:

[Device with address 01]

Open all Relay: 01 0F 00 00 00 08 01 FF BE D5
Close all Relay: 01 0F 00 00 00 08 01 00 FE 95
0-1 Open;3-7 Close: 01 0F 00 00 00 08 01 03 BE 94

Open/Close Relay in certain time

Command: 01 05 02 00 00 07 8D B0

Byte Meaning Description
01 Device address 0 x 00 is the boradcast address; 0 x 01-0 x FF are device addresses
05 05 Command Command for controlling signle Relay
02 Command 02 is the command for closing Relay in the current time,04 is the command for opening Relay in the current time
00 Address of Relay The address of Relay controlled
00 07 Delay The Delay time is Data*100ms
Data: 0 x 0007,Delay: 7*100MS = 700MS
8D B0 CRC16 The CRC16 checksum of the first six bytes.

Answer:01 05 02 00 00 07 8D B0

Byte Meaning Description
01 Device address 0 x 00 is the boradcast address;0 x 01-0 x FF are device addresses
05 05 Command Command for controlling single Relay
02 Command 02 is the command for closing Relay in the current time,04 is the command for opening Relay in the current time
00 Address of Relay The address of Relay controlled
00 07 Delay The delay time is the data*100ms
Data: 0 x 0007, Delay: 7*100MS = 700MS
8D B0 CRC16 The CRC16 checksum of the first six bytes.

Example:

[Device with address 01]

Open Relay 0: 01 05 02 00 00 07 8D B0 //700MS = 7*100MS = 700MS
Open Relay 1: 01 05 02 01 00 08 9C 74 //800MS
Close Relay 0: 01 05 04 00 00 05 0C F9 //500MS
Close Relay 1: 01 05 04 01 00 06 1D 38 //600MS

Set baud rate

Command: 00 06 20 00 00 05 43 D8

Byte Meaning Description
00 Device address 0 x 00 is the boradcast address; 0 x 01-0 x FF are device addresses
06 06 Command Set baud rate or device address
20 00 Command register 0x2000: Set baud rate,0 x 4000:Set device address
00 Parity 0x00: None; 0 x 01: Even; 0 x 02: Odd
05 Baud rate Baudrate:
0 x 00: 4800
0 x 01: 9600
0 x 02: 19200
0 x 03: 38400
0 x 04: 57600
0 x 05: 115200
0 x 06: 128000
0 x 07: 256000
43 D8 CRC16 The CRC16 checksum of the first six bytes.

Answer: 00 06 20 00 00 05 43 D8

Byte Meaning Description
00 Device address 0 x 00 is the boradcast address; 0 x 01-0xFF are device addresses
06 06 Command Set baud rate or device address
20 00 Command register 0 x 2000: Set baud rate, 0 x 4000 Set device address
00 Parity 0 x 00: None; 0 x 01: Even; 0 x 02: Odd
05 Baud rate The baud rate
0 x 0000: 4800
0 x 0001: 9600
0 x 0002: 19200
0 x 0003: 38400
0 x 0004: 57600
0 x 0005: 115200
0 x 0006: 128000
0 x 0007: 256000
43 D8 CRC16 The CRC16 checksum of the first six bytes.

Example:

[Device with address 0 x 01]

Set baud rate as 4800: 00 06 20 00 00 00 83 DB
Set baud rate as 9600: 00 06 20 00 00 01 42 1B
Set baud rate as 115200: 00 06 20 00 00 05 43 D8

Set device address

Command: 00 06 40 00 00 01 5C 1B

Byte Meaning Description
00 Device address 0 x 00 is the boradcast address; 0 x 01-0 x FF are device addresses
06 06 Command Set baud rate or device address
40 00 Command register 0 x 2000: Set baud rate, 0 x 4000: Set device address
00 01 Device address The device address,0 x 0001-0 x 00FF
5C 1B CRC16 The CRC16 checksum of the first six bytes.

Answer: 00 06 40 00 00 01 5C 1B

Byte Meaning Description
00 Device address 0x00 is the boradcast address;0 x 01-0 x FF are device addresses
06 06 Command Set baud rate or device address
40 00 Command register 0 x 2000: Set baud rate,0 x 4000: Set device address
00 01 Device address Set device address, 0 x 0001-0 x 00FF
5C 1B CRC16 The CRC16 checksum of first six bytes.

Example:

[Device with address 0 x 01]

Set device address as 0 x 01: 00 06 40 00 00 01 5C 1b
Set device address as 0 x 02: 00 06 40 00 00 02 1C 1A
Set device address as 0 x 03: 00 06 40 00 00 03 DD DA

Read device address

Command: 00 03 40 00 00 01 90 1B

Byte Meaning Description
00 Device address 0 x 00 is the boradcast address; 0 x 01-0 x FF are device addresses
03 03 Command Read Device address
40 00 Command register 0 x 0200: Read software revision, 0 x 0040: Read device address
00 01 Device address Device address
90 1B CRC16 The CRC16 checksum of the first six bytes.

Answer: 01 03 02 00 01 79 84

Byte Meaning Description
01 Device address 0 x 00 is the boradcast address; 0 x 01-0 x FF are device addresses
03 03 commands Read software revision or device address
02 Number of bytes Number of bytes returned
00 01 Device address Devicess
79 84 CRC16 The CRC16 checksum of the first six bytes.

Example:

[Device with address 01]

Command: 00 03 40 00 00 01 90 1B
Answer: 01 03 02 00 01 79 84 //Device address 0x01
[Device with address 02]

Command: 00 03 40 00 00 01 90 1B
Answer: 02 03 02 00 02 7D 85 //Device address 0x02
[Device with address 03]

Command: 00 03 40 00 00 01 90 1B
Answer: 03 03 02 00 03 81 85 //Device address 0x03

Read software revision

Command: 00 03 80 00 00 01 AC 1B

Byte Meaning Description
01 device address 0 x 00 is the boradcast address; 0 x 01-0 x FF are device addresses
03 03 Command Read software revision or device address
80 00 Command register 0 x 8000: Read software revision, 0 x 4000: Read device address.
00 01 number of bytes Fixed 0 x 0001
AC 1B CRC16 The CRC16 checksum of the first six bytes.

Answer:01 03 02 00 C8 F0 B8

Byte Meaning Description
01 Device address 0 x 00 is the boradcast address; 0 x 01-0 x FF are device addresses
03 03 Command Read software revision, read device address
02 Number of bytes number of bytes returned
00 C8 Software revision It should be converted to DEC and divided with 100,
for example 0 x 00C8 = 200 = V2.00
F0 B8 CRC16 The CRC16 checksum of the first six bytes.

Example:

Command: 00 03 80 00 00 01 AC 1B
Answer: 03 03 02 00 C8 F1 00 //0 x 00C8 = 200 =V2.00