0

I am working on ROS under Ubuntu 14.04 on an Odroid XU3 (ARM dev board).

I connect two USB devices to my dev board which are recognized as ttyACM0 and ttyACM1 according to the time when they are connected.

Since thoses devices (Arduino & PixHawk) have different PID / VID, I would like to bind them to a certain "custom name" tty like ttyController0 & ttyPosition0 for example.

According to this subject, we can simlink the device depending on PID & VID to ttyUSB0.

How should I do to simlink to a deterministic name? Would 4 rules in /etc/udev/rules.d/99-custom.rules with a simlink work ?

ACTION=="add", ATTRS{idVendor}=="0123", ATTRS{idProduct}=="0001", RUN+="/bin/ln -s /dev/ttyACM0 /dev/ttyController"


ACTION=="remove", ATTRS{idVendor}=="0123", ATTRS{idProduct}=="0001", RUN+="/bin/rm /dev/ttyController"


ACTION=="add", ATTRS{idVendor}=="3210", ATTRS{idProduct}=="0002", RUN+="/bin/ln -s /dev/ttyACM0 /dev/ttyPosition"


ACTION=="remove", ATTRS{idVendor}=="3210", ATTRS{idProduct}=="0002", RUN+="/bin/rm /dev/ttyPosition"

Or can I use Udev with custom PID & VID ?

2

Your configuration should basically work, but I'd like to make a few suggestions:

First off, I think you want to use ATTR, not ATTRS. ATTRS searches the whole device tree upwards to a matching (parent) device. This is most likely not what you intend. With using ATTR the device actually triggering the event has to have the specified attribute.

Second, as creating symlinks to device nodes is a rather common task, there is a dedicated statement to do so, i.e. SYMLINK+="newname". This way you won't be dependent on "external" commands. Even more important, by using this directive, you only need to match the "add" event as udevd will automatically removes associated symlinks when a device vanishes.

Thus, your rules should be

ACTION=="add", ATTR{idVendor}=="0123", ATTR{idProduct}=="0001", SYMLINK+="ttyController"
ACTION=="add", ATTR{idVendor}=="3210", ATTR{idProduct}=="0002", SYMLINK+="ttyPosition"

And last, I would suggest narrowing down the match by adding a further SUBSYSTEM constraint, i.e. adding SUBSYSTEM=="usb". As device and vendor IDs are only (hopefully) unique in their scope, leaving out the subsystem match could result in your rules matching on other device classes, like PCI devices. Even though this is rather unlikely, it is commonly seen as good style in udev rules:

SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="0123", ATTR{idProduct}=="0001", SYMLINK+="ttyController"
SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="3210", ATTR{idProduct}=="0002", SYMLINK+="ttyPosition"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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