diff --git a/pymodbus/datastore/simulator.py b/pymodbus/datastore/simulator.py index 5275fa5a7..8d8560586 100644 --- a/pymodbus/datastore/simulator.py +++ b/pymodbus/datastore/simulator.py @@ -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 @@ -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 diff --git a/test/test_simulator.py b/test/test_simulator.py index 5366a5605..89f86cdca 100644 --- a/test/test_simulator.py +++ b/test/test_simulator.py @@ -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")),