Remove unused code, add some comments
This commit is contained in:
parent
348febb0d2
commit
d0a3decf1b
1 changed files with 3 additions and 70 deletions
|
@ -3,26 +3,10 @@
|
||||||
# Copyright 2024, Paul Warren <pwarren@pwarren.id.au>
|
# Copyright 2024, Paul Warren <pwarren@pwarren.id.au>
|
||||||
# Licensed under AGPLv3, See LICENSE.md for terms
|
# Licensed under AGPLv3, See LICENSE.md for terms
|
||||||
|
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from pymodbus.constants import Endian
|
from pymodbus.constants import Endian
|
||||||
from pymodbus.payload import BinaryPayloadDecoder, BinaryPayloadBuilder
|
from pymodbus.payload import BinaryPayloadDecoder, BinaryPayloadBuilder
|
||||||
#from pymodbus.client.tcp import ModbusTcpClient as ModbusClient
|
|
||||||
#from pymodbus.diag_message import *
|
|
||||||
#from pymodbus.file_message import *
|
|
||||||
#from pymodbus.other_message import *
|
|
||||||
#from pymodbus.mei_message import *
|
|
||||||
|
|
||||||
class DataType():
|
class DataType():
|
||||||
String8 = 1
|
|
||||||
String16 = 2
|
|
||||||
String32 = 3
|
|
||||||
Int16 = 4
|
|
||||||
UInt16 = 5
|
|
||||||
Int32 = 6
|
|
||||||
UInt32 = 7
|
|
||||||
Float32 = 8
|
|
||||||
UInt64 = 7
|
|
||||||
|
|
||||||
def __init__(self, width, decode, add):
|
def __init__(self, width, decode, add):
|
||||||
self._width = width
|
self._width = width
|
||||||
|
@ -43,61 +27,11 @@ class DataType():
|
||||||
return encoder.build()
|
return encoder.build()
|
||||||
|
|
||||||
|
|
||||||
def old_decode_from_register(self, value):
|
# helper function for DataType constructors
|
||||||
decoder = BinaryPayloadDecoder.fromRegisters(value.registers, byteorder=Endian.BIG, wordorder=Endian.BIG)
|
|
||||||
|
|
||||||
if (self == DataType.String8) or (self == DataType.String16) or (self == DataType.String32):
|
|
||||||
return str(decoder.decode_string(16).decode('utf-8'))
|
|
||||||
|
|
||||||
elif (self == DataType.Int16):
|
|
||||||
return decoder.decode_16bit_int()
|
|
||||||
|
|
||||||
elif (self == DataType.UInt16):
|
|
||||||
return decoder.decode_16bit_uint()
|
|
||||||
|
|
||||||
elif (self == DataType.Int32):
|
|
||||||
return decoder.decode_32bit_int()
|
|
||||||
|
|
||||||
elif (self == DataType.UInt32):
|
|
||||||
return decoder.decode_32bit_uint()
|
|
||||||
|
|
||||||
elif (self == DataType.Float32):
|
|
||||||
return decoder.decode_32bit_float()
|
|
||||||
|
|
||||||
else:
|
|
||||||
return str(decoder.decode_bits())
|
|
||||||
|
|
||||||
def old_encode_to_buffer(self, value):
|
|
||||||
encoder = BinaryPayloadBuilder(byteorder=Endian.BIG, wordorder=Endian.BIG)
|
|
||||||
|
|
||||||
if (self == DataType.String8) or (self == DataType.String16) or (self == DataType.String32):
|
|
||||||
return encoder.add_string(value).build()
|
|
||||||
|
|
||||||
elif (self == DataType.Int16):
|
|
||||||
encoder.add_16bit_int(int(value))
|
|
||||||
return encoder.build()
|
|
||||||
# return int(value)
|
|
||||||
|
|
||||||
elif (self == DataType.UInt16):
|
|
||||||
encoder.add_16bit_uint(int(value))
|
|
||||||
return encoder.build()
|
|
||||||
|
|
||||||
elif (self == DataType.Int32):
|
|
||||||
return encoder.add_32bit_int(value).build()
|
|
||||||
|
|
||||||
elif (self == DataType.UInt32):
|
|
||||||
return encoder.add_32bit_uint(value).build()
|
|
||||||
|
|
||||||
elif (self == DataType.Float32):
|
|
||||||
return encoder.add_32bit_float(value).build()
|
|
||||||
|
|
||||||
else:
|
|
||||||
return encoder.add_bits(value).build()
|
|
||||||
|
|
||||||
|
|
||||||
def decode_string(decoder, value):
|
def decode_string(decoder, value):
|
||||||
return str(decoder.decode_string(16).decode('utf-8'))
|
return str(decoder.decode_string(16).decode('utf-8'))
|
||||||
|
|
||||||
|
# The various data types that the fronius inverters use
|
||||||
string8 = DataType(4, decode_string, BinaryPayloadBuilder.add_string)
|
string8 = DataType(4, decode_string, BinaryPayloadBuilder.add_string)
|
||||||
string16 = DataType(8, decode_string, BinaryPayloadBuilder.add_string)
|
string16 = DataType(8, decode_string, BinaryPayloadBuilder.add_string)
|
||||||
string32 = DataType(16, decode_string, BinaryPayloadBuilder.add_string)
|
string32 = DataType(16, decode_string, BinaryPayloadBuilder.add_string)
|
||||||
|
@ -112,6 +46,7 @@ uint64 = DataType(4,BinaryPayloadDecoder.decode_64bit_uint, BinaryPayloadBuilder
|
||||||
class registerReadError(Exception):
|
class registerReadError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Finally our fronius modbus register object.
|
||||||
class FroniusReg:
|
class FroniusReg:
|
||||||
def __init__(self, address, datatype, unit, description):
|
def __init__(self, address, datatype, unit, description):
|
||||||
self.address = address
|
self.address = address
|
||||||
|
@ -156,8 +91,6 @@ class ScaledFroniusReg:
|
||||||
return self.valueReg.setValue(modbusClient, value / 10 ** self.scaleReg.getValue(modbusClient))
|
return self.valueReg.setValue(modbusClient, value / 10 ** self.scaleReg.getValue(modbusClient))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MaxChaRte = FroniusReg(40155, uint16, 1, "Max Charge Rate")
|
MaxChaRte = FroniusReg(40155, uint16, 1, "Max Charge Rate")
|
||||||
MaxChaRte_SF = FroniusReg(40156, int16, 1, "Max Charge Rate SF")
|
MaxChaRte_SF = FroniusReg(40156, int16, 1, "Max Charge Rate SF")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue