mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-07-28 21:52:00 +08:00

* 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
33 lines
900 B
Python
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é") |