Computer Locking Up While Using PySerial

15 views Asked by At

While using this code if the functions are ran too often/for too long the entire computer will lock up and the program will close

import serial

# Define the serial port and baud rate
ser = serial.Serial(port = 'COM8', baudrate = 115200)  # Replace 'COM3' with the appropriate port name
# time.sleep(2)  # Allow some time for the serial connection to be established
ser.reset_input_buffer()
ser.reset_output_buffer()

x,y = 10,10
def move_mouse(x, y):
    ser.write(f"M{x} {y}\n".encode())
    ser.flush()

def send_mouse_click():
    ser.write("C".encode())
    ser.flush()

I run the script (slightly different but condensed for readability) which runs the functions over and over and after a few seconds it will lock up the computer and crash the program.

0

There are 0 answers