Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch !!, funny thing is that I am on a M1 MacMini and did not see it.

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