You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
918 B
27 lines
918 B
from pymodbus.client import ModbusTcpClient
|
|
import time
|
|
from datetime import datetime
|
|
|
|
input_zone = input("Bereich [0, 11, ...]: ")
|
|
input_client = input("Client [101, 102, ...]: ")
|
|
print("\n")
|
|
|
|
client = ModbusTcpClient(f'192.168.{input_zone}.{input_client}')
|
|
|
|
if client.connect():
|
|
print(f"✅ Verbindung Hergestellt: [192.168.{input_zone}.{input_client}] \n")
|
|
try:
|
|
while True:
|
|
r_ist = client.read_holding_registers(address=12, count=2)
|
|
if not r_ist.isError():
|
|
# aktuellen Zeitstempel erzeugen
|
|
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
# Ausgabe in derselben Zeile
|
|
print(f"\r{timestamp} | Ist: {r_ist.registers}", end="", flush=True)
|
|
time.sleep(0.5)
|
|
except KeyboardInterrupt:
|
|
print("\nBeendet.")
|
|
finally:
|
|
client.close()
|
|
else:
|
|
print("Verbindung fehlgeschlagen") |