add tools for serial stress

This commit is contained in:
Luc 2024-09-08 17:53:11 +08:00
parent 4b01d89095
commit ea07b30b04
2 changed files with 49 additions and 2 deletions

View 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.")

View File

@ -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