亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

pymodbus:從 Modbus 設備發出讀取字符串和多種類型的數據

pymodbus:從 Modbus 設備發出讀取字符串和多種類型的數據

慕勒3428872 2021-11-09 20:00:12
我正在嘗試從Modbus TCP設備讀取String(Usecase-1) & multiple type of data in one request(Usecase-2) 數據,但未能正確解碼。系統配置:Python 3.6.5Pymodbus:2.1.0平臺:Windows 10 64 位Modbus TCP 服務器:import loggingfrom pymodbus.constants import Endianfrom pymodbus.datastore import ModbusSequentialDataBlockfrom pymodbus.datastore import ModbusSlaveContext, ModbusServerContextfrom pymodbus.device import ModbusDeviceIdentificationfrom pymodbus.payload import BinaryPayloadBuilderfrom pymodbus.server.sync import StartTcpServerclass ModbusTCPServer(object):    # initialize your data store:    hrBuilder = BinaryPayloadBuilder(byteorder=Endian.Big, wordorder=Endian.Big)    # Usecase-1    hrBuilder.add_string("abcdefghij")    #Uncomment below three lines for usecase-2    # hrBuilder.add_32bit_float(20.5)     # hrBuilder.add_32bit_int(45)     # hrBuilder.add_bits([1, 0, 0, 0, 0, 0, 0, 0])    hrBlock = ModbusSequentialDataBlock(0, hrBuilder.to_registers() * 100)    store = ModbusSlaveContext(hr=hrBlock, ir=hrBlock, di=hrBlock, co=hrBlock)    slaves = {        1: store,    }    context = ModbusServerContext(slaves=slaves, single=False)    # initialize the server information        identity = ModbusDeviceIdentification()    modbusDeviceAddress = "127.0.0.1"    modbusDevicePort = 501    # run the TCP server    # TCP:    print("Modbus TCP Server started.")    StartTcpServer(context, identity=identity, address=(modbusDeviceAddress, modbusDevicePort))if __name__ == "__main__":    print("Reading application configurations...")    ModbusTCPServer();
查看完整描述

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)



查看完整回答
反對 回復 2021-11-09
  • 1 回答
  • 0 關注
  • 291 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號