SoCTest working!
This commit is contained in:
parent
6f1b8927f2
commit
5d56df7c0e
2 changed files with 32 additions and 6 deletions
|
@ -7,7 +7,7 @@ from enum import Enum
|
||||||
|
|
||||||
from pymodbus.constants import Endian
|
from pymodbus.constants import Endian
|
||||||
from pymodbus.payload import BinaryPayloadDecoder
|
from pymodbus.payload import BinaryPayloadDecoder
|
||||||
from pymodbus.client.tcp import ModbusTcpClient as ModbusClient
|
#from pymodbus.client.tcp import ModbusTcpClient as ModbusClient
|
||||||
#from pymodbus.diag_message import *
|
#from pymodbus.diag_message import *
|
||||||
#from pymodbus.file_message import *
|
#from pymodbus.file_message import *
|
||||||
#from pymodbus.other_message import *
|
#from pymodbus.other_message import *
|
||||||
|
@ -71,12 +71,12 @@ class registerReadError(Exception):
|
||||||
class FroniusReg:
|
class FroniusReg:
|
||||||
def __init__(self, address, datatype, unit, description):
|
def __init__(self, address, datatype, unit, description):
|
||||||
self.address = address
|
self.address = address
|
||||||
self.datatype = DataType(datatype)
|
self.datatype = datatype
|
||||||
self.unit = unit
|
self.unit = unit
|
||||||
self.description=description
|
self.description=description
|
||||||
|
|
||||||
def getValue(self, modbusClient):
|
def getValue(self, modbusClient):
|
||||||
self.__getRegisterValue(modbusClient,
|
return self.__getRegisterValue(modbusClient,
|
||||||
self.address,
|
self.address,
|
||||||
self.datatype,
|
self.datatype,
|
||||||
self.unit)
|
self.unit)
|
||||||
|
@ -87,7 +87,8 @@ class FroniusReg:
|
||||||
slave=unit)
|
slave=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):
|
||||||
|
raise registerReadError("It's NONE!")
|
||||||
return dataType.decode(modbusValue)
|
return dataType.decode(modbusValue)
|
||||||
|
|
||||||
class ScaledFroniusReg:
|
class ScaledFroniusReg:
|
||||||
|
@ -95,6 +96,15 @@ class ScaledFroniusReg:
|
||||||
self.valueReg=valueReg
|
self.valueReg=valueReg
|
||||||
self.scaleReg=scaleReg
|
self.scaleReg=scaleReg
|
||||||
|
|
||||||
def getValue(self):
|
def getValue(self, modbusClient):
|
||||||
return self.valueReg.getValue() * 10 ** self.scaleReg.getValue()
|
return self.valueReg.getValue(modbusClient) * 10 ** self.scaleReg.getValue(modbusClient)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
storageStateOfCharge = FroniusReg(40362, DataType.UInt16, 1, "Storage State of Charge")
|
||||||
|
storageStateOfChargeSF = FroniusReg(40376, DataType.Int16, 1, "Storage State of Charge Scaling Factor")
|
||||||
|
scaledStateOfCharge = ScaledFroniusReg(storageStateOfCharge, storageStateOfChargeSF)
|
||||||
|
|
16
SoCtest.py
Executable file
16
SoCtest.py
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import FroniusReg
|
||||||
|
|
||||||
|
from pymodbus.client.tcp import ModbusTcpClient
|
||||||
|
|
||||||
|
fronius1 = ModbusTcpClient("172.19.107.211", port=502, timeout=10)
|
||||||
|
fronius1.connect()
|
||||||
|
|
||||||
|
raw_soc = FroniusReg.storageStateOfCharge.getValue(fronius1)
|
||||||
|
print(" raw: %s" % raw_soc)
|
||||||
|
|
||||||
|
soc = FroniusReg.scaledStateOfCharge.getValue(fronius1)
|
||||||
|
print(" SOC: %s%%" % soc)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue