第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

pymodbus:從 Modbus 設(shè)備發(fā)出讀取字符串和多種類型的數(shù)據(jù)

pymodbus:從 Modbus 設(shè)備發(fā)出讀取字符串和多種類型的數(shù)據(jù)

慕勒3428872 2021-11-09 20:00:12
我正在嘗試從Modbus TCP設(shè)備讀取String(Usecase-1) & multiple type of data in one request(Usecase-2) 數(shù)據(jù),但未能正確解碼。系統(tǒng)配置:Python 3.6.5Pymodbus:2.1.0平臺(tái):Windows 10 64 位Modbus TCP 服務(wù)器: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貢獻(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)



查看完整回答
反對(duì) 回復(fù) 2021-11-09
  • 1 回答
  • 0 關(guān)注
  • 274 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)