Move gen24 specific registers to own file

This commit is contained in:
Paul Warren 2024-10-11 14:59:57 +11:00
parent 4a284d1341
commit 4bbb92ba29
2 changed files with 48 additions and 38 deletions

View file

@ -23,30 +23,45 @@ class DataType():
def encode_to_buffer(self, value):
encoder = BinaryPayloadBuilder(byteorder=Endian.BIG, wordorder=Endian.BIG)
print(type(value))
self._add(encoder, value)
return encoder.build()
# helper function for DataType constructors
# helper functions for DataType constructors
def decode_string(decoder, value):
return str(decoder.decode_string(16).decode('utf-8'))
def encode_16bit_int(encoder, value):
return encoder.add_16bit_int(int(value))
# The various data types that the fronius inverters use
string8 = DataType(4, decode_string, BinaryPayloadBuilder.add_string)
string16 = DataType(8, decode_string, BinaryPayloadBuilder.add_string)
string32 = DataType(16, decode_string, BinaryPayloadBuilder.add_string)
int16 = DataType(1,BinaryPayloadDecoder.decode_16bit_int, BinaryPayloadBuilder.add_16bit_int)
uint16 = DataType(1,BinaryPayloadDecoder.decode_16bit_uint, BinaryPayloadBuilder.add_16bit_uint)
int32 = DataType(2,BinaryPayloadDecoder.decode_32bit_int, BinaryPayloadBuilder.add_32bit_int)
uint32 = DataType(2,BinaryPayloadDecoder.decode_32bit_uint, BinaryPayloadBuilder.add_32bit_uint)
float32 = DataType(2,BinaryPayloadDecoder.decode_32bit_float, BinaryPayloadBuilder.add_32bit_float)
uint64 = DataType(4,BinaryPayloadDecoder.decode_64bit_uint, BinaryPayloadBuilder.add_64bit_uint)
int16 = DataType(1, BinaryPayloadDecoder.decode_16bit_int, encode_16bit_int)
uint16 = DataType(1, BinaryPayloadDecoder.decode_16bit_uint, encode_16bit_int)
int32 = DataType(2, BinaryPayloadDecoder.decode_32bit_int, BinaryPayloadBuilder.add_32bit_int)
uint32 = DataType(2, BinaryPayloadDecoder.decode_32bit_uint, BinaryPayloadBuilder.add_32bit_uint)
float32 = DataType(2, BinaryPayloadDecoder.decode_32bit_float, BinaryPayloadBuilder.add_32bit_float)
uint64 = DataType(4, BinaryPayloadDecoder.decode_64bit_uint, BinaryPayloadBuilder.add_64bit_uint)
class registerReadError(Exception):
pass
# Finally our fronius modbus register object.
# Fronius modbus register object.
#
# the 'spreadsheet' refers to the various spreadsheets in the 'gen24-modbus-api-external-docs.zip'
# file, available by going to https://www.fronius.com/en/photovoltaics/downloads and searching for
# 'gen24 modbus'
#
# Constructor parameters:
# address: address as specified in the spreadsheet
# datatype: One of the above datatypes, as specified for the address in the spreadsheet
# unit: the modbus unit, either '1' for the fronius inverter or 200 for the attached fronius smart meter.
# description: free text to describe the register's purpose
class FroniusReg:
def __init__(self, address, datatype, unit, description):
self.address = address
@ -89,33 +104,3 @@ class ScaledFroniusReg:
def setValue(self, modbusClient, value):
return self.valueReg.setValue(modbusClient, value / 10 ** self.scaleReg.getValue(modbusClient))
MaxChaRte = FroniusReg(40155, uint16, 1, "Max Charge Rate")
MaxChaRte_SF = FroniusReg(40156, int16, 1, "Max Charge Rate SF")
wChaGra = FroniusReg(40357, uint16, 1, "Max Charge Power")
storageStateOfCharge = FroniusReg(40362, uint16, 1, "Storage State of Charge")
storageStateOfChargeSF = FroniusReg(40376, int16, 1, "Storage State of Charge Scaling Factor")
scaledStateOfCharge = ScaledFroniusReg(storageStateOfCharge, storageStateOfChargeSF)
OutWRte = FroniusReg(40366, int16, 1, "DischargeRate")
InWRte = FroniusReg(40367, int16, 1, "ChargeRate")
WRteSF = FroniusReg(40379, int16, 1, "ScalingFactor for storage Watts")
StorCtl_Mode = FroniusReg(40359, uint16, 1, "Hold/Charge/Discharge enable")
MinRsvPct = FroniusReg(40361, uint16, 1, "Reserve Percentage")
InOutWRte_RvrtTms = FroniusReg(40369, uint16, 1, "Revert timer for charge settings")
ChaGriSet = FroniusReg(40371, uint16, 1, "enum16, 0 = PV only, 1 = Grid enabled")
WChaDisChaGra_SF = FroniusReg(40373, int16, 1, "Charge/Discharge Power SF")
MinRsvPct_SF = FroniusReg(40375, int16, 1, "Reserve Percentage Scaling")
scaledOutWRte = ScaledFroniusReg(OutWRte, WRteSF)
scaledInWRte = ScaledFroniusReg(InWRte, WRteSF)
scaledReserve = ScaledFroniusReg(MinRsvPct, MinRsvPct_SF)
scaledMaxChaRte = ScaledFroniusReg(MaxChaRte, MaxChaRte_SF)
scaledMaxWChaGra = ScaledFroniusReg(wChaGra, WChaDisChaGra_SF)

View file

@ -0,0 +1,25 @@
from pyfroniusreg import froniusreg
MaxChaRte = froniusreg.FroniusReg(40155, froniusreg.uint16, 1, "Max Charge Rate")
MaxChaRte_SF = froniusreg.FroniusReg(40156, froniusreg.int16, 1, "Max Charge Rate SF")
wChaGra = froniusreg.FroniusReg(40357, froniusreg.uint16, 1, "Max Charge Power")
storageStateOfCharge = froniusreg.FroniusReg(40362, froniusreg.uint16, 1, "Storage State of Charge")
storageStateOfChargeSF = froniusreg.FroniusReg(40376, froniusreg.int16, 1, "Storage State of Charge Scaling Factor")
scaledStateOfCharge = froniusreg.ScaledFroniusReg(storageStateOfCharge, storageStateOfChargeSF)
OutWRte = froniusreg.FroniusReg(40366, froniusreg.int16, 1, "DischargeRate")
InWRte = froniusreg.FroniusReg(40367, froniusreg.int16, 1, "ChargeRate")
WRteSF = froniusreg.FroniusReg(40379, froniusreg.int16, 1, "ScalingFactor for storage Watts")
StorCtl_Mode = froniusreg.FroniusReg(40359, froniusreg.uint16, 1, "Hold/Charge/Discharge limit")
MinRsvPct = froniusreg.FroniusReg(40361, froniusreg.uint16, 1, "Reserve Percentage")
InOutWRte_RvrtTms = froniusreg.FroniusReg(40369, froniusreg.uint16, 1, "Revert timer for charge settings")
ChaGriSet = froniusreg.FroniusReg(40371, froniusreg.uint16, 1, "enum16, 0 = PV only, 1 = Grid enabled")
WChaDisChaGra_SF = froniusreg.FroniusReg(40373, froniusreg.int16, 1, "Charge/Discharge Power SF")
MinRsvPct_SF = froniusreg.FroniusReg(40375, froniusreg.int16, 1, "Reserve Percentage Scaling")
scaledOutWRte = froniusreg.ScaledFroniusReg(OutWRte, WRteSF)
scaledInWRte = froniusreg.ScaledFroniusReg(InWRte, WRteSF)
scaledReserve = froniusreg.ScaledFroniusReg(MinRsvPct, MinRsvPct_SF)
scaledMaxChaRte = froniusreg.ScaledFroniusReg(MaxChaRte, MaxChaRte_SF)
scaledMaxWChaGra = froniusreg.ScaledFroniusReg(wChaGra, WChaDisChaGra_SF)