import serial import time print("Opening serial port /dev/cu.usbmodem101...") try: ser = serial.Serial('/dev/cu.usbmodem101', 115200, timeout=1.0) print("Opened successfully!") # Clear input buffer ser.reset_input_buffer() # Send Ctrl-C to interrupt anything print("Sending Ctrl-C...") ser.write(b'\x03') time.sleep(0.2) # Read response if ser.in_waiting: print(f"After Ctrl-C: {ser.read(ser.in_waiting)}") # Send newline print("Sending newline...") ser.write(b'\r\n') time.sleep(0.2) if ser.in_waiting: print(f"After newline: {ser.read(ser.in_waiting)}") # Send test print command print("Sending test print command...") ser.write(b"print('REPL_ACTIVE')\r\n") time.sleep(0.5) if ser.in_waiting: print(f"After command: {ser.read(ser.in_waiting)}") else: print("No response to command.") ser.close() except Exception as e: print(f"Error: {e}")