Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions readreg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#!/usr/bin/env python3
import minimalmodbus
import serial
import struct

#Support functions

def convertToFloat(input_int):
#read_long returns a 32-bit int, convert to float...
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem to be correct. From the datasheet the integer returned should be divided by 100 to get the floating point value.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packed_v = struct.pack('>l', input_int)
output_float = struct.unpack('>f', packed_v)[0]
return output_float


# Set to true to edit values
WRITE = True
Expand Down Expand Up @@ -34,6 +44,26 @@
BAT_SOC = 0x311A
BAT_RATED_VOLTAGE = 0x9067

BAT_VOLTAGE_MAX_DAY = 0x3302# 00: 00 Refresh every day V 100
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be some copy/paste garbage? Please remove.

BAT_VOLTAGE_MIN_DAY = 0x3303# 00: 00 Refresh every day V 100
CONS_ENERGY_TODAY_L = 0x3304# 00: 00 Clear every day KWH 100
CONS_ENERGY_TODAY_H = 0x3305# 100
CONS_ENERGY_MONTH_L = 0x3306# 00: 00 Clear on the first day of month 100
CONS_ENERGY_MONTH_H = 0x3307# KWH 100
CONS_ENERGY_YEAR_L = 0x3308# 00: 00 Clear on 1, Jan. 100
CONS_ENERGY_YEAR_H = 0x3309# 100
CONS_ENERGY_TOTAL_L = 0x330A# 100
CONS_ENERGY_TOTAL_H = 0x330B# KWH 100
GEN_ENERGY_TODAY_L = 0x330C# 00: 00 Clear every day. 100
GEN_ENERGY_TODAY_H = 0x330D# 100
GEN_ENERGY_MONTH_L = 0x330E# 00: 00 Clear on the first day of month. 100
GEN_ENERGY_MONTH_H = 0x330F# KWH 100
GEN_ENERGY_YEAR_L = 0x3310# 00: 00 Clear on 1, Jan. 100
GEN_ENERGY_YEAR_H = 0x3311# KWH 100
GEN_ENERGY_TOTAL_L = 0x3312# KWH 100
GEN_ENERGY_TOTAL_H = 0x3313# 100


# Print panel info
pv_voltage = instrument.read_register(
PV_VOLTAGE, 2, 4, False
Expand All @@ -54,6 +84,22 @@
) # Registernumber, number of decimals
print("Batt. temp:\t" + str(temperature) + "C")

gen_energy_day=instrument.read_long(
GEN_ENERGY_TODAY_L, 4, False, 0) # Registernumber, number of decimals
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated comment. Please remove.

f = convertToFloat(gen_energy_day)
print("Energy today:\t" + str(f) + str("kWh"))

gen_energy_month=instrument.read_long(
GEN_ENERGY_MONTH_L, 4, False, 0) # Registernumber, number of decimals
f = convertToFloat(gen_energy_month)
print("Energy month:\t" + str(f) + str("kWh"))

gen_energy_year=instrument.read_long(
GEN_ENERGY_YEAR_L, 4, False, 0) # Registernumber, number of decimals
f = convertToFloat(gen_energy_year)
print("Energy year:\t" + str(f) + str("kWh"))


if WRITE:
# Set battery type, 1 = Sealed
sealed = 1
Expand Down Expand Up @@ -102,3 +148,4 @@
print("Voltage configuration:")
val = instrument.read_register(0x900E, 2, 3, False)
print(val)