ModBus协议-功能码-0x05



05 (0x05) Write Single Coil
This function code is used to write a single output to either ON or OFF in a remote device.The requested ON/OFF state is specified by a constant in the request data field. A value of FF 00 hex requests the output to be ON. A value of 00 00 requests it to be OFF. All other values are illegal and will not affect the output. The Request PDU specifies the address of the coil to be forced. Coils are addressed starting at zero. Therefore coil numbered 1 is addressed as 0. The requested ON/OFF state is specified by a constant in the Coil Value field. A value of 0XFF00 requests the coil to be ON.A value of 0X0000 requests the coil to be off. All other values are illegal and will not affect the coil.

The normal response is an echo of the request, returned after the coil state has been written.

ModBus协议-功能码-0x05_第1张图片

Tx:01 05 00 AC FF 00
Rx:01 05 00 AC FF 00

Tx分析
01 从机地址
05 功能码
00 AC 输出地址
FF 00 输出值
Rx分析
01 从机地址
05 功能码
00 AC 输出地址
FF 00 输出值

0xAC = 172
[172] FF 00  ->ON

FF00:ON  0000:OFF



ModBus协议-功能码-0x05_第2张图片


你可能感兴趣的:(ModBus协议)