1

Is their a command that returns what /dev/ttyACM* is open. At some stage in the script it disconnects the usb and reconnects but the ACM increments after this so the variable port = /dev/ttyACM0 now is /dev/ttyACM1. I want to detect which /dev/ttyACM* is open. So port = return (command to find ACM)

1 Answer 1

4

Using glob and serial, this should do the trick:

import glob
import serial

def find_ports():
    ports = glob.glob('/dev/ttyACM[0-9]*')

    res = []
    for port in ports:
        try:
            s = serial.Serial(port)
            s.close()
            res.append(port)
        except:
            pass
    return res
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.