auf binarypayloaddecoder umgestellt
This commit is contained in:
14
main.py
14
main.py
@@ -2,6 +2,9 @@ from pymodbus.client import ModbusTcpClient
|
||||
import struct
|
||||
import time
|
||||
|
||||
from pymodbus.constants import Endian
|
||||
from pymodbus.payload import BinaryPayloadDecoder
|
||||
|
||||
# Verbindung zur Wärmepumpe
|
||||
ip = '10.0.0.10'
|
||||
port = 502
|
||||
@@ -31,11 +34,12 @@ try:
|
||||
continue
|
||||
|
||||
if reg_type == 'REAL':
|
||||
reg_high = result.registers[0]
|
||||
reg_low = result.registers[1]
|
||||
# Oder falls dein Gerät Low-Word zuerst sendet:
|
||||
decoder = struct.pack('>HH', reg_low, reg_high)
|
||||
value = struct.unpack('>f', decoder)[0]
|
||||
decoder = BinaryPayloadDecoder.fromRegisters(
|
||||
result.registers,
|
||||
byteorder=Endian.Big,
|
||||
wordorder=Endian.Little # ← Das ist der Trick!
|
||||
)
|
||||
value = decoder.decode_32bit_float()
|
||||
else:
|
||||
value = result.registers[0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user