rohdaten plotten
This commit is contained in:
16
main.py
16
main.py
@@ -2,9 +2,6 @@ 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
|
||||
@@ -33,13 +30,14 @@ try:
|
||||
print(f"Fehler beim Lesen von Adresse {address}: {result}")
|
||||
continue
|
||||
|
||||
print(f"Adresse {address} - Rohdaten: {result.registers}")
|
||||
|
||||
if reg_type == 'REAL':
|
||||
decoder = BinaryPayloadDecoder.fromRegisters(
|
||||
result.registers,
|
||||
byteorder=Endian.BIG,
|
||||
wordorder=Endian.LITTLE # ← Das ist der Trick!
|
||||
)
|
||||
value = decoder.decode_32bit_float()
|
||||
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]
|
||||
else:
|
||||
value = result.registers[0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user