50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Loopback-Test des seriellen Adapters.
|
|
|
|
Sendet ein paar Bytes und prueft, ob sie zurueckkommen. Dazu auf der TTL-Seite
|
|
des Adapters TXD und RXD bruecken.
|
|
|
|
- Kommen die Bytes zurueck -> Adapter-RX + Software + Port sind in Ordnung,
|
|
das Problem liegt in der Verdrahtung MAX232 <-> Anzeige.
|
|
- Kommt nichts zurueck -> Adapter-RX, Port oder Bruecke pruefen.
|
|
|
|
python3 loopback.py
|
|
"""
|
|
|
|
import sys
|
|
import config
|
|
from transport import SerialTransport
|
|
|
|
|
|
def main():
|
|
t = SerialTransport(port=config.PORT, baudrate=config.BAUDRATE,
|
|
parity=config.PARITY, bytesize=config.BYTESIZE,
|
|
stopbits=config.STOPBITS, timeout=1.0)
|
|
probe = bytes([0x55, 0xAA, 0x02, ord("A"), 0x03])
|
|
print("Port:", config.PORT)
|
|
print("TX:", " ".join("%02X" % b for b in probe))
|
|
t.write(probe)
|
|
|
|
import time
|
|
deadline = time.monotonic() + 1.0
|
|
buf = bytearray()
|
|
while time.monotonic() < deadline and len(buf) < len(probe):
|
|
chunk = t._port.read(len(probe))
|
|
if chunk:
|
|
buf.extend(chunk)
|
|
t.close()
|
|
|
|
print("RX:", " ".join("%02X" % b for b in buf) if buf else "(nichts)")
|
|
if bytes(buf) == probe:
|
|
print("OK -> Adapter-Empfang funktioniert. Fehler liegt in der Verkabelung zur Anzeige.")
|
|
return 0
|
|
if buf:
|
|
print("Teilweise/verfaelscht -> Baudrate/Parity oder Wackelkontakt pruefen.")
|
|
return 1
|
|
print("Nichts empfangen -> Bruecke TXD<->RXD sitzt nicht, oder Adapter-RX defekt.")
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|