1 回答

TA贡献1798条经验 获得超3个赞
使用zero_mode=True在ModbusSlaveContext。
如果要将[0..n]客户端中的寄存器映射到[0..n]服务器中。默认情况下,pymodbus 服务器将寄存器读取地址映射[0..n]到[1..n]其内部存储中的寄存器。这是为了遵守 modbus 规范。引用 pymodbus 源代码。
#The slave context can also be initialized in zero_mode which means that a
# request to address(0-7) will map to the address (0-7). The default is
# False which is based on section 4.4 of the specification, so address(0-7)
# will map to (1-8)::
因此,在您的情况下,您可以设置ModbusSequentialDataBlockto的起始地址1或ModbusSlaveContext使用zero_mode=True.
hrBlock = ModbusSequentialDataBlock(1, hrBuilder.to_registers() * 100)
# Or
store = ModbusSlaveContext(hr=hrBlock, ir=hrBlock, di=hrBlock, co=hrBlock, zero_mode=True)
添加回答
举报