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

后端 未结 1 709
轮回少年
轮回少年 2021-01-29 15:03

I\'m IoT newbie and I have a project with Schneider Power Meter. I read voltage raw data from registers using pymodbus but I don\'t know how to convert it to the co

相关标签:
1条回答
  • 2021-01-29 15:32

    Still, I'm waiting for your code, but with my guess, you will need like the following stuff:

    Reading and decoding:

    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')
    

    [NOTE]:

    Your data either is float32 or float32_inverse.

    • Thus, with the float32 you will have:

       wordorder=Endian.Big
      
    • And with the float32_inverse you will have:

       wordorder=Endian.Little
      
    0 讨论(0)
提交回复
热议问题