简体   繁体   中英

Noob trying to get values from his EnergyMeter via Modbus RTU RS485 in python

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 EnergyMeter 1

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM