Skip to content

Commit

Permalink
Modify Endian enum for 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudd2 committed Aug 30, 2023
1 parent 340dce3 commit fd965d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions productivity/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ async def _write_register_value(self, key: str,
"""
start_address = self.tags[key]['address']['start'] - 400001
builder = BinaryPayloadBuilder(byteorder=Endian.Big,
wordorder=Endian.Little)
bigendian = Endian.BIG if self.pymodbus35plus else Endian.Big # type:ignore[attr-defined]
lilendian = Endian.BIG if self.pymodbus35plus else Endian.Big # type:ignore[attr-defined]
builder = BinaryPayloadBuilder(byteorder=bigendian,
wordorder=lilendian)
data_type = self.tags[key]['type']
if data_type == 'float':
builder.add_32bit_float(float(value))
Expand Down Expand Up @@ -222,9 +224,11 @@ async def _read_discrete(self, addresses: dict, output=True) -> dict:
async def _read_registers(self, a_type: str) -> dict:
"""Handle reading input or holding registers from the PLC."""
r = await self.read_registers(**self.addresses[a_type], type=a_type)
bigendian = Endian.BIG if self.pymodbus35plus else Endian.Big # type:ignore[attr-defined]
lilendian = Endian.BIG if self.pymodbus35plus else Endian.Big # type:ignore[attr-defined]
decoder = BinaryPayloadDecoder.fromRegisters(r,
byteorder=Endian.Big,
wordorder=Endian.Little)
byteorder=bigendian,
wordorder=lilendian)
current = self.addresses[a_type]['address'] + TYPE_START[a_type] + 1
end = current + self.addresses[a_type]['count']
result = {}
Expand Down
1 change: 1 addition & 0 deletions productivity/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def _detect_pymodbus_version(self) -> None:
self.pymodbus30plus = int(pymodbus.__version__[0]) == 3
self.pymodbus32plus = self.pymodbus30plus and int(pymodbus.__version__[2]) >= 2
self.pymodbus33plus = self.pymodbus30plus and int(pymodbus.__version__[2]) >= 3
self.pymodbus35plus = self.pymodbus30plus and int(pymodbus.__version__[2]) >= 5

async def _connect(self):
"""Start asynchronous reconnect loop."""
Expand Down

0 comments on commit fd965d3

Please sign in to comment.