1 回答

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊
使用zero_mode=True在ModbusSlaveContext。
如果要將[0..n]客戶端中的寄存器映射到[0..n]服務(wù)器中。默認(rèn)情況下,pymodbus 服務(wù)器將寄存器讀取地址映射[0..n]到[1..n]其內(nèi)部存儲(chǔ)中的寄存器。這是為了遵守 modbus 規(guī)范。引用 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)::
因此,在您的情況下,您可以設(shè)置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)
添加回答
舉報(bào)