Update 2/21/2024
1. I use the threading to see if this can solve the problem.
2. As shown in the following code, it does not work.
3. Looks like the problem is on the lower layer such as Linux kernel or hardware limitation.
1. I use the threading to see if this can solve the problem.
2. As shown in the following code, it does not work.
3. Looks like the problem is on the lower layer such as Linux kernel or hardware limitation.
Code:
import threadingimport serialimport time# Function to handle each Arduino connectiondef handle_arduino(port): with serial.Serial(port, 9600, timeout=1) as arduino: while True: print(f"{port} is running!\n") time.sleep(1)# List of your Arduino portsarduino_ports = ['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyUSB4', '/dev/ttyUSB5', '/dev/ttyUSB6']# Creating and starting a new thread for each Arduino connectionfor port in arduino_ports: thread = threading.Thread(target=handle_arduino, args=(port,)) thread.start()# Main loop can continue doing something else or just waitwhile True: print("Main program can still run.") time.sleep(1)
Statistics: Posted by 2e8ee5eb — Wed Feb 21, 2024 11:36 am