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)
添加回答
舉報