mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-13 10:19:00 +08:00
add tools for serial stress
This commit is contained in:
parent
4b01d89095
commit
ea07b30b04
47
tools/fw_simulator/comtest.py
Normal file
47
tools/fw_simulator/comtest.py
Normal file
@ -0,0 +1,47 @@
|
||||
import serial
|
||||
import time
|
||||
import sys
|
||||
|
||||
# Serial Port Configuration
|
||||
port = 'COM3'
|
||||
baudrate = 1000000
|
||||
|
||||
try:
|
||||
ser = serial.Serial(
|
||||
port=port,
|
||||
baudrate=baudrate,
|
||||
parity=serial.PARITY_NONE,
|
||||
stopbits=serial.STOPBITS_ONE,
|
||||
bytesize=serial.EIGHTBITS,
|
||||
timeout=1 # Add a timeout to the serial port read operation
|
||||
)
|
||||
except serial.SerialException as e:
|
||||
print(f"Error opening {port}: {str(e)}")
|
||||
sys.exit(1) # exit the program with an error code
|
||||
|
||||
# Simulate a response from the printer
|
||||
response = b'ok T:19.91 /0.00 B:19.88 /0.00 @:127 B@:0\r\n'
|
||||
|
||||
print("Serial port opened successfully.")
|
||||
|
||||
try:
|
||||
while True:
|
||||
if ser.in_waiting > 0:
|
||||
data = ser.readline().strip()
|
||||
if data == b'M105' or data == b'M105\r':
|
||||
print(f"Got: {data}")
|
||||
ser.write(response)
|
||||
print(f"Sent: {response}")
|
||||
else:
|
||||
print(f"Ignoring: {data}")
|
||||
|
||||
time.sleep(0.1) # Sleep for 100 milliseconds
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n\nKeyboard Interrupt Detected. Exiting...")
|
||||
except Exception as e:
|
||||
print(f"Error: {str(e)}")
|
||||
finally:
|
||||
if ser.is_open:
|
||||
ser.close()
|
||||
print("Serial port closed successfully.")
|
@ -32,7 +32,7 @@ def main():
|
||||
for port, desc, hwid in sorted(ports):
|
||||
print(common.bcolors.COL_GREEN+" - {}: {} ".format(port, desc)+common.bcolors.END_COL)
|
||||
desc.capitalize()
|
||||
if (desc.find("SERIAL") != -1):
|
||||
if (desc.find("SERIAL") != -1 or desc.find("UART") != -1):
|
||||
portTFT = port
|
||||
print(common.bcolors.COL_GREEN +
|
||||
"Found " + portTFT + " for ESP3D"+common.bcolors.END_COL)
|
||||
@ -41,7 +41,7 @@ def main():
|
||||
if (portTFT == ""):
|
||||
print(common.bcolors.COL_RED+"No serial port found"+common.bcolors.END_COL)
|
||||
exit(0)
|
||||
ser = serial.Serial(portTFT, 115200)
|
||||
ser = serial.Serial(portTFT, 1000000)
|
||||
print(common.bcolors.COL_GREEN+"Now Simulating: " + fw_name + common.bcolors.END_COL)
|
||||
starttime = common.current_milli_time()
|
||||
# loop forever, just unplug the port to stop the program or do ctrl-c
|
||||
|
Loading…
x
Reference in New Issue
Block a user