Modbus frame builder and decoderModbus 报文构建与解析
Build a request for any common function code, then decode whatever comes back.
按功能码生成请求报文,再解析设备返回的任何应答。
Request请求
Addresses are protocol addresses (0-based). If your manual says 40001, enter 0; if it says 40011, enter 10. 地址填协议地址(0 基址)。手册写 40001 就填 0,写 40011 就填 10。
Bytes to send待发送字节
——
Decode a frame解析报文
auto-detects RTU / TCP / ASCII自动识别 RTU / TCP / ASCIITalk to a device (Web Serial)连接真实设备(Web Serial)
not connected未连接How the builder decides what to emit构建规则说明
- RTU:
unit + PDU + CRC-16, CRC low byte first, no start or end delimiter. Silence of 3.5 character times separates frames. - TCP:
transaction + protocol(0) + length + unit + PDU. Length counts the unit byte plus the PDU; there is no checksum. - ASCII:
':' + hex(unit + PDU) + LRC, terminated by CR LF. Each byte becomes two printable characters, so the frame is twice as long. - Quantities are clamped to the specification: 2000 coils, 125 registers per read, 1968 coils / 123 registers per write, 121 registers for the write half of FC23.
- For FC05 only
0xFF00(ON) and0x0000(OFF) are legal — anything else is rejected by the device with exception 03.
- RTU:
从站地址 + PDU + CRC-16,CRC 低字节在前,没有起始/结束符;帧之间靠 3.5 个字符时间的静默分隔。 - TCP:
事务号 + 协议号(0) + 长度 + 从站地址 + PDU,长度字段包含从站地址与 PDU;没有校验码。 - ASCII:
':' + hex(从站地址 + PDU) + LRC,以回车换行结束。每个字节变成两个可打印字符,帧长翻倍。 - 数量按规范限制:读线圈 2000、读寄存器 125、写线圈 1968、写寄存器 123,FC23 的写部分最多 121 个寄存器。
- FC05 只接受
0xFF00(合)与0x0000(分),其它值设备会回异常码 03。