ESP3D/tools/serial_test/serial_test.py
Luc fe23f0cb1e
Grbl grblHAL better support for realtime commands (#1064)
* Add a realtime command detector 
* Move `\r` as printable char and not replaced as `\n`
* Refactorize Serial service code to avoid redondant code between esp32 and esp8266
* Implement isrealtimeCommand check for serial and centralize function in string helper
* Add new type message : realtimecmd
* Update simulator to handle commands and realtime commands
* Add simple serial test tool
*  Generate error if use HAS_DISPLAY with grbl/grblHAL
* Implement isRealTimeCommand for BT client
* Simplify BT push2buffer code
* Implement support for realtimecommand in telnet
* Implement isRealTimeCommand on websocket RX
* Simplify push2RXbuffer for websocket
* Implement isRealTimeCommand for USB serial
* Bump version
2024-12-08 17:26:19 +08:00

33 lines
900 B
Python

import serial
import time
# Configuration du port série
ser = serial.Serial(
port='COM4', # Port série Windows
baudrate=115200, # Vitesse en bauds
timeout=1 # Timeout en secondes
)
def format_char(c):
# Convertit un caractère en sa représentation lisible
if c == b'\r':
return '\\r'
elif c == b'\n':
return '\\n'
else:
return f"{c.decode('ascii', errors='replace')}({ord(c)})"
try:
print("Lecture du port série COM4. Ctrl+C pour arrêter.")
while True:
if ser.in_waiting > 0:
# Lire un caractère à la fois
char = ser.read(1)
print(format_char(char), end=' ', flush=True)
time.sleep(0.01) # Petit délai pour ne pas surcharger le CPU
except KeyboardInterrupt:
print("\nArrêt du programme")
finally:
ser.close()
print("Port série fermé")