如何根据功率计上的原始数据计算能量读数

How to calculate Energy readings from the raw data on an Power Meter

我是物联网新手,我有一个使用 Schneider Power Meter 的项目。 我使用 pymodbus 从寄存器中读取电压原始数据,但我不知道如何将其转换为正确的值。

原始数据 [24206, 17242] 来自寄存器地址 3927-3928

这是我的代码:

from pymodbus.client.sync import ModbusSerialClient as ModbusClient

def main():
    try:
        register = int(input("Registers: "))
        modbus = ModbusClient(method='rtu', port='COM4', baudrate=9600, timeout=1, 
            parity='E', bytesize=8
        )
        modbus.connect()
        r = modbus.read_holding_registers(register, 2, unit=1)
        print(r.registers)
        modbus.close()
        return r.registers
    except AttributeError as e:
        print(e)
        return None

if __name__ == "__main__":
    main()

输出:

[24206, 17242]

Registers

Voltage

Raw

大家可以告诉我怎么做吗?

谢谢。

我还在等你的代码,但我猜你需要像下面这样的东西:

读取解码:

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

def validator(instance):
    if not instance.isError():
        '''.isError() implemented in pymodbus 1.4.0 and above.'''
        decoder = BinaryPayloadDecoder.fromRegisters(
            instance.registers,
            byteorder=Endian.Big, wordorder=Endian.Little
        )   
        return float(decoder.decode_32bit_float())

    else:
        # Error handling.
        print("There aren't the registers, Try again.")
        return None


client = ModbusTcpClient('X.X.X.X', port=502)
connection = client.connect()

if connection:
    request = client.read_holding_registers(3927, count=2, unit=1)
    data = validator(request)
    print(data)

    client.close()

else:
    print('Connection lost, Try again')

[注意]:

您的数据是 float32float32_inverse.

  • 因此,使用 float32 你将拥有:

     wordorder=Endian.Big
    
  • 有了 float32_inverse,您将拥有:

     wordorder=Endian.Little