Is there a way to force a specific serial/USB device to a specifc TTY?

Red Squirrel

No Lifer
May 24, 2003
63,247
10,018
126
twitter.com
I have a relay/temp sensor controller that plugs into my enviromental control server. Currently it is the only device so my program just tries the first ttyACM and if it fails it tries the next until it can connect. I plan to add another device so this method wont work anymore and will actually cause issues if I leave it that way. So I would like to be able to just set the TTY in the device's config file and have that device always appear as that TTY when it's plugged in. I know the order will always stick as long as they are all plugged in, but if one is not plugged in or fails then the rest will shift.

This is a box that will always have various devices added to it over time as I add more home automation/monitoring stuff, so I want a solid way of managing them. In dmesg to me it seems devices give enough info that would allow them to be distinguished even if I did happen to plug two idential ones:

usb 6-2: new full speed USB device using uhci_hcd and address 3
usb 6-2: New USB device found, idVendor=2341, idProduct=0043
usb 6-2: New USB device strings: Mfr=1, Product=2, SerialNumber=220
usb 6-2: Manufacturer: Arduino (www.arduino.cc)
usb 6-2: SerialNumber: 74934303030351C04081
usb 6-2: configuration #1 chosen from 1 choice
cdc_acm 6-2:1.0: ttyACM1: USB ACM device


So is this possible in any way to force a specific device to a specific TTY?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
I would think the best method would be to create a udev rule to create a symlink with a meaningful name to you that will point to the device regardless of what device name is actually chosen.
 

Red Squirrel

No Lifer
May 24, 2003
63,247
10,018
126
twitter.com
Did a bit of research and got it working. I created a file in /etc/udev/rules.d called 00-rules and added these entries:


Code:
SUBSYSTEMS=="usb", ATTRS{serial}=="74934303030351C04081", KERNEL=="ttyACM*", NAME="arduino-0"
SUBSYSTEMS=="usb", ATTRS{product}=="CANA KIT UK1104", KERNEL=="ttyACM*", NAME="uk1104-0"
The info I got from unplugging and plugging it back in. There's also a command that can do it:

Code:
udevadm info -a -p $(udevadm info -q path -n /dev/ttyACM0)
Replacing ttyACM0 with the device you want to get info from.

Oddly, the uk1104 device I'm using has no serial number, it showed up as 0, so I had to go by the product name. Probably wont buy another anyway, it is a neat device, but now that I discovered arduino I'll probably just use that as I could easily make it turn on/off relays too.
 

ASK THE COMMUNITY