1

fist Post as i normaly find the answers if i search long enough. But today is the day... I bought a EnergyMeter from Aliexpress with MODBUS RTU connection and im trying to read it out. I already tried a lot of stuff from all over the Internet.

This is the Datasheet of the EnergyMeter1

I tried pyModbus and minimalmodbus.

My both Scripts:

#!/usr/bin/env python3
from pymodbus.client.sync import ModbusSerialClient as ModbusClient

client = ModbusClient(method='rtu', port='/dev/ttyUSB0', timeout=1, stopbits = 1, bytesize = 8,  parity='N', baudrate= 9600)
client.connect()
request = client.read_holding_registers(0x00,0x01,unit=2)
print (request.registers)`

and

#!/usr/bin/env python3

import time
import minimalmodbus

rs485 = minimalmodbus.Instrument('/dev/ttyUSB0', 2)
rs485.serial.baudrate = 9600
rs485.serial.bytesize = 8
rs485.serial.parity = minimalmodbus.serial.PARITY_NONE
rs485.serial.stopbits = 1
rs485.serial.timeout = 1
rs485.debug = False
rs485.mode = minimalmodbus.MODE_RTU
print (rs485)
print(rs485.read_register(0, functioncode=4,))
#Volts_A = rs485.read_float(0, functioncode=4, number_of_registers=4)
#print ('Voltage: {0:.1f} Volts'.format(Volts_A))

It seems i can read Data (first script puts out 17942 and second 17248. But honestly, i have no clue what to do with it. Also i dont understand that code... The manual states that I have to send a Hi and a Low Adress, but how can i do that? 0x00 is hexa - do i have to convert this? How?

The Manual stats that i have to send Adress+functioncode+data+crc - how to do this, or is pymod/minimod doing this automatically? How does it now the right Function Code etc? Iam totally confused, would be happy if someone could help me...

Thanks

Marv21
  • 21
  • 3
  • 1
    Much of what the manual manual says is implemented for you by the the modbus libraries (correctly formatting the request etc). The manual says FC4 (input register) however you will need to retrieve two registers (registers are 16 bit; the data you are retrieving is 32 bit IEEE-754 floating point so is encoded over two registers) and convert the result (some libraries do this for you; try [`read_float(0, functioncode=4, number_of_registers=2)`](https://minimalmodbus.readthedocs.io/en/stable/apiminimalmodbus.html#minimalmodbus.Instrument.read_float) using minimal modbus). – Brits May 14 '21 at 03:20
  • That worked ! Thank you so much! 0 is the register 0 then, do i have to sum up the low and high to get the right digit there? Thanks again mate. – Marv21 May 14 '21 at 11:42
  • Okay. hi and lo are hex and i have to convert it to decimal so 001A = 26. – Marv21 May 14 '21 at 11:57

1 Answers1

1

Thanks to @Brits i got it running. I had to use read_float(0, functioncode=4, number_of_registers=2) where 0 is decimal. If i want to read 001A i had to convert from hex to dec = 26. Works very good

HV_A_Phase_Spannung = Hausverbrauch.read_float(0, functioncode=4, number_of_registers=2)
print(str(f'{HV_A_Phase_Spannung :.2f}')+"V -Phase A") 

First row i read out and in the second i print with decimals only 2 digits long.

Marv21
  • 21
  • 3