问题
I'm curently working on a testbench for some pcbs. They can be controlled though USB. I wrote some python code to send (using pySerial) orders to one card via the serial device "/dev/ttyACM0" The problem is that I need to test 5 cards at a time which means I need to differentiate which card is controlled with “/dev/ttyACM*” and * depends on the pluging order (which I don’t control).
I used “usb-devices” command to have the name of each physical usb port but I need to send orders to these via pySerial. Is there a way to make that work?
Another solution I found is to use the “Dev: n” number from “usb-devices” to communicate with “/dev/ttyn” but the permission to communicate through pySerial is denied, any idea?
回答1:
Look in directory /dev/serial/by-path/
. You should find a link to each tty eg ../../dev/ttyACM0
. The path should be stable. You can open these links just like /dev/ttyACM0
.
来源:https://stackoverflow.com/questions/62779186/associate-physical-usb-port-to-device