start of register writing
This commit is contained in:
parent
5d56df7c0e
commit
10e03f927d
2 changed files with 25 additions and 14 deletions
|
@ -76,20 +76,27 @@ class FroniusReg:
|
||||||
self.description=description
|
self.description=description
|
||||||
|
|
||||||
def getValue(self, modbusClient):
|
def getValue(self, modbusClient):
|
||||||
return self.__getRegisterValue(modbusClient,
|
return self.__getRegisterValue(modbusClient)
|
||||||
self.address,
|
|
||||||
self.datatype,
|
|
||||||
self.unit)
|
|
||||||
|
|
||||||
def __getRegisterValue(self, modbusClient, address, dataType, unit):
|
def setValue(self, modbusClient):
|
||||||
modbusValue = modbusClient.read_holding_registers(address-1,
|
return self.__setRegisterValue(modbusClient)
|
||||||
dataType.getRegisterLength(),
|
|
||||||
slave=unit)
|
def __getRegisterValue(self, modbusClient):
|
||||||
|
modbusValue = modbusClient.read_holding_registers(self.address-1,
|
||||||
|
self.datatype.getRegisterLength(),
|
||||||
|
slave=self.unit)
|
||||||
if(modbusValue.isError()):
|
if(modbusValue.isError()):
|
||||||
raise registerReadError("Unable to read from Fronius Register: %d, %s" % (self.id, self.description))
|
raise registerReadError("Unable to read from Fronius Register: %d, %s" % (self.id, self.description))
|
||||||
if(modbusValue is None):
|
if(modbusValue is None):
|
||||||
raise registerReadError("It's NONE!")
|
raise registerReadError("It's NONE!")
|
||||||
return dataType.decode(modbusValue)
|
return self.datatype.decode(modbusValue)
|
||||||
|
|
||||||
|
def __setRegisterValue(self, modbusClient):
|
||||||
|
modbusValue = modbusClient.write_holding_registers(self.address-1,
|
||||||
|
self.datatype.getRegisterLength(),
|
||||||
|
slave=self.unit)
|
||||||
|
return modbusValue
|
||||||
|
|
||||||
|
|
||||||
class ScaledFroniusReg:
|
class ScaledFroniusReg:
|
||||||
def __init__(self, valueReg, scaleReg):
|
def __init__(self, valueReg, scaleReg):
|
||||||
|
@ -99,7 +106,8 @@ class ScaledFroniusReg:
|
||||||
def getValue(self, modbusClient):
|
def getValue(self, modbusClient):
|
||||||
return self.valueReg.getValue(modbusClient) * 10 ** self.scaleReg.getValue(modbusClient)
|
return self.valueReg.getValue(modbusClient) * 10 ** self.scaleReg.getValue(modbusClient)
|
||||||
|
|
||||||
|
def setValue(self, modbusClient):
|
||||||
|
return self.valueReg.setValue(modbusClient, self.scaleReg.getValue(modbusClient))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,3 +116,8 @@ class ScaledFroniusReg:
|
||||||
storageStateOfCharge = FroniusReg(40362, DataType.UInt16, 1, "Storage State of Charge")
|
storageStateOfCharge = FroniusReg(40362, DataType.UInt16, 1, "Storage State of Charge")
|
||||||
storageStateOfChargeSF = FroniusReg(40376, DataType.Int16, 1, "Storage State of Charge Scaling Factor")
|
storageStateOfChargeSF = FroniusReg(40376, DataType.Int16, 1, "Storage State of Charge Scaling Factor")
|
||||||
scaledStateOfCharge = ScaledFroniusReg(storageStateOfCharge, storageStateOfChargeSF)
|
scaledStateOfCharge = ScaledFroniusReg(storageStateOfCharge, storageStateOfChargeSF)
|
||||||
|
|
||||||
|
OutWRte = FroniusReg(40367, DataType.Int16, 1, "DischargeRate, Negative means Charging")
|
||||||
|
WRteSF = FroniusReg(40379, DataType.Int16, 1, "ScalingFactor for storage Watts")
|
||||||
|
|
||||||
|
scaledDischarge = ScaledFroniusReg(OutWRte, WRteSF)
|
||||||
|
|
|
@ -7,10 +7,8 @@ from pymodbus.client.tcp import ModbusTcpClient
|
||||||
fronius1 = ModbusTcpClient("172.19.107.211", port=502, timeout=10)
|
fronius1 = ModbusTcpClient("172.19.107.211", port=502, timeout=10)
|
||||||
fronius1.connect()
|
fronius1.connect()
|
||||||
|
|
||||||
raw_soc = FroniusReg.storageStateOfCharge.getValue(fronius1)
|
|
||||||
print(" raw: %s" % raw_soc)
|
|
||||||
|
|
||||||
soc = FroniusReg.scaledStateOfCharge.getValue(fronius1)
|
soc = FroniusReg.scaledStateOfCharge.getValue(fronius1)
|
||||||
print(" SOC: %s%%" % soc)
|
print(" SOC: %s%%" % soc)
|
||||||
|
|
||||||
|
discharge = FroniusReg.scaledDischarge.getValue(fronius1)
|
||||||
|
print(" Rate: %dW" % discharge)
|
||||||
|
|
Loading…
Reference in a new issue