diff --git a/tools/fw_simulator/comtest.py b/tools/fw_simulator/comtest.py new file mode 100644 index 00000000..cd5b16ec --- /dev/null +++ b/tools/fw_simulator/comtest.py @@ -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.") diff --git a/tools/fw_simulator/fw_simulator.py b/tools/fw_simulator/fw_simulator.py index efe4a30c..a8477ffd 100644 --- a/tools/fw_simulator/fw_simulator.py +++ b/tools/fw_simulator/fw_simulator.py @@ -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