23 lines
585 B
Python
23 lines
585 B
Python
import serial
|
|
import time
|
|
import sys
|
|
|
|
port = "COM5"
|
|
baudrate = 115200
|
|
|
|
print(f"Waiting for {port}...")
|
|
while True:
|
|
try:
|
|
with serial.Serial(port, baudrate, timeout=1) as ser:
|
|
print("Connected! Reading...")
|
|
while True:
|
|
line = ser.readline()
|
|
if line:
|
|
try:
|
|
print(line.decode('utf-8', errors='replace'), end='', flush=True)
|
|
except:
|
|
pass
|
|
except serial.SerialException as e:
|
|
print(f"Exception: {e}")
|
|
time.sleep(0.5)
|