# mPy - Serial loop back test
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 0.10  2026-07-09  initial release

from	drivers	import	Serial
import	time

# ======================== test UART communication ============================

# observe tx-rx connected and disconnected
def testLoopback(rx, tx):
    serial = Serial(rx=rx, tx=tx)
    count = 1
    try:
        while True:
            for _ in range(20):
                time.sleep_ms(100)
                if obj := serial.readLn():
                    print('Rx:  ', type(obj), obj)
            serial.writeLn(dict(count=count))			# @ 2 Sec
            count += 1
    finally: serial.close()
        

testLoopback(rx=16, tx=17)

# ================================== end =====================================

