Uncategorized

pymodbus – How to read byte order endian BIG with Python?


Hello I try to read data from power meter using pymodbus. After I register the address, I get list of bytes like this
result_ups.registers = [3468, 204, 0, 2080]
I try to convert it to same value as show on power meter like this
20434682080
This is my project for monitoring system.

This is my code

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


client_tcp = ModbusTcpClient('10.123.133.100',port=502)

while True:
    try:
        client_tcp.connect()
        while True:
            result_ups = client_tcp.read_holding_registers(1716,4,units=1,slave=1)
            decoder_ups = BinaryPayloadDecoder.fromRegisters(result_ups.registers,byteorder=Endian.BIG,wordorder=Endian.LITTLE)
            kwh_ups = decoder_ups.decode_32bit_int()
            print(kwh_ups)
            time.sleep(1)
         
    except Exception as e:
        print(e)
        time.sleep(1)



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *