Skip to content

Commit

Permalink
Bug fix for #1661 (#1664)
Browse files Browse the repository at this point in the history
  • Loading branch information
fhydralisk authored Jul 18, 2023
1 parent 9c425aa commit 6f85486
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pymodbus/datastore/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def build_registers_from_value(cls, value, is_int):
if is_int:
value_bytes = int.to_bytes(value, 4, "big")
else:
value_bytes = struct.pack("f", value)
value_bytes = struct.pack(">f", value)
regs[0] = int.from_bytes(value_bytes[:2], "big")
regs[1] = int.from_bytes(value_bytes[-2:], "big")
return regs
Expand All @@ -781,5 +781,5 @@ def build_value_from_registers(cls, registers, is_int):
if is_int:
value = int.from_bytes(value_bytes, "big")
else:
value = struct.unpack("f", value_bytes)[0]
value = struct.unpack(">f", value_bytes)[0]
return value
20 changes: 10 additions & 10 deletions test/test_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ class TestSimulator:
type=CellType.UINT32, action=2, action_kwargs={"minval": 10, "maxval": 80}
),
Cell(type=CellType.NEXT, value=50),
Cell(type=CellType.FLOAT32, access=True, value=72),
Cell(type=CellType.NEXT, access=True, value=17221),
Cell(type=CellType.FLOAT32, access=True, value=34161),
Cell(type=CellType.NEXT, access=True, value=45381),
Cell(type=CellType.FLOAT32, access=True, value=34161),
Cell(type=CellType.NEXT, access=True, value=45381),
Cell(type=CellType.FLOAT32, value=1653, action=1),
Cell(type=CellType.NEXT, value=43080), # 40
Cell(type=CellType.FLOAT32, value=1653, action=1),
Cell(type=CellType.NEXT, value=43080),
Cell(type=CellType.FLOAT32, access=True, value=17731),
Cell(type=CellType.NEXT, access=True, value=18432),
Cell(type=CellType.FLOAT32, access=True, value=17841),
Cell(type=CellType.NEXT, access=True, value=29061),
Cell(type=CellType.FLOAT32, access=True, value=17841),
Cell(type=CellType.NEXT, access=True, value=29061),
Cell(type=CellType.FLOAT32, value=18600, action=1),
Cell(type=CellType.NEXT, value=29958), # 40
Cell(type=CellType.FLOAT32, value=18600, action=1),
Cell(type=CellType.NEXT, value=29958),
Cell(type=CellType.STRING, value=int.from_bytes(bytes("St", "utf-8"), "big")),
Cell(type=CellType.NEXT, value=int.from_bytes(bytes("r ", "utf-8"), "big")),
Cell(type=CellType.STRING, value=int.from_bytes(bytes("St", "utf-8"), "big")),
Expand Down

0 comments on commit 6f85486

Please sign in to comment.