Pymodbus寄存器无法正确解码

2024-06-07 13:32:08 发布

您现在位置:Python中文网/ 问答频道 /正文

from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.constants import Endian
from pymodbus.client.sync import ModbusTcpClient

def convertINT32(data):
       decoder = BinaryPayloadDecoder.fromRegisters(data, Endian.Big, wordorder=Endian.Little)
       return decoder.decode_32bit_int()

client = ModbusTcpClient(host="176.219.182.106", port="502")
client.connect()
data = client.read_holding_registers(address=230,count=10,unit=1)

eaPlus = convertINT32(data.registers[0:2]) # kWh Del
eaNeg = convertINT32(data.registers[2:4])  # kWh Rec
erPlus = convertINT32(data.registers[4:6]) #VARh Del
erNeg = convertINT32(data.registers[6:8])  #kVAR Rec

client.close()

print("Active Energy Plus: %s \nActive Energy Negative: %s \nReactive Energy Plus: %s \nReactive Energy Negative: %s" %(eaPlus,eaNeg, erPlus, erNeg))
print("----------------------------")
print("Register List: %s" % data.registers)
print("----------------------------")
print("Actual values are APPROXİMATE:\nActive Energy Plus: 989 \nActive Energy Negative: 3879077 \nReactive Energy Plus: 268384 \nReactive Energy Negative: 361")

我正在从Schneider ION7650读取仪表值(如果您不知道,我不在乎),以下是modbus寄存器列表:

enter image description here

我知道确切的值,我将结果与它们进行比较,我的代码看起来是错误的。IP地址和端口是可访问的,因此您可以访问仪表。这里怎么了

和输出:

Active Energy Plus: 3867613 
Active Energy Negative: 275048
Reactive Energy Plus: 6270
Reactive Energy Negative: 3866985
----------------------------
Register List: [989, 59, 12904, 4, 6270, 0, 361, 59, 23532, 65535]
----------------------------
Actual values are APPROXİMATE:
Active Energy Plus: 989
Active Energy Negative: 3879077
Reactive Energy Plus: 268384
Reactive Energy Negative: 361

您还可以检查here中的值实时值,然后单击“消耗”


Tags: fromimportclientdatapluspymodbusenergyactive
2条回答

Modbus Protocol and Register Map for ION Devices documentation(第12页)开始:

According to the Modbus protocol, in response to a request for register 4xxxx of a particular slave device, the Modbus master reads register xxxx-1 from the slave. For example, register 40011 corresponds to holding register 10.

因此,将address设置为229而不是230,以从地址230开始读取10个寄存器。此外,字节顺序和字顺序都是big-endian

我试了一下,得到了预期的值

我找到了解决办法。当我从BinaryDecoder中删除WordOrder时,from会注册它的工作。我还看到Modbus轮询中的订单列表。有很多像这样的选择

  • A B C D(字节顺序:大端)
  • D C B A
  • C D A B
  • B A D C(字节顺序:小端)

如果我错了,请纠正我。如何读取其他选项。还有词序是什么?有没有一个像wordorder=Endian.Big byteorder=Endian.Little这样的组合读作“C D a B”呢

相关问题 更多 >

    热门问题