Assigning an unique name to USB CDC device in /dev
Dear All, We have a USB CDC device which we are connecting it to the Ubuntu system. Then, we are accessing the device using an application by opening the device with /dev/ttyACM0 node. The system may have multiple USB CDC devices already connected before connecting my device, sometimes. In such cases, my application fails to open the device, because, this time the assigned node is other than /dev/ttyAMC0, but in my application the device node is /dev/ttyAMC0 only. Due to these reasons, I want to assign my own device node in the /dev directory like /dev/mydev. This will enable my application to identify my device very easily. The requirement is same as described in the link - http://marc.info/?l=linux-usb&m=130216901901572&w=2 The answer is available at http://marc.info/?l=linux-usb&m=130217684009490&w=2 I have tried in different ways as I have also looked at the following sources. But, still, there is NO luck. When I insert another USB CDC device, it got /dev/ttyACM0 instead of getting ttyACM1. http://www.reactivated.net/writing_udev_rules.html https://www.kernel.org/pub/linux/utils/kernel/hotplug/udev/udev.html http://unix.stackexchange.com/questions/77476/point-usb-phone-to-specific-de... https://www.pjrc.com/teensy/49-teensy.rules The kernel version and distribution details are as follows. Kernel Version --- 3.5.0-17-generic Distribution details are as follows. RELEASE=14 CODENAME=nadia EDITION="MATE 64-bit" DESCRIPTION="Linux Mint 14 Nadia" I have created a file, named 11-ttyACM.rules, under /etc/udev/rules.d directory. The contents of the file as follows. KERNEL=="ttyAMC0", SUBSYSTEM=="tty", ATTRS{serial}=="__0X00124B000148CC78", SYMLINK+="mydev" I got the above information from the following command udevadm info -q all -n /dev/ttyACM0 --attribute-walk This is what I did. But, no luck. If I insert a different serial numbered device, then it is assigning ttyACM0 to that device. But, after this udev rule, it should not assign, I think. Please someone, who already used/knows udev rules, suggest me. Thanks. Regards, Srinivas.
You need persistent device naming rules in udev. The udev rules will basically match cretain device attributes you specify in the rules file and then create device nodes/symlinks for it. So, first you need to find what those _unique_ attributes are for your device, and then write it as a udev rule. See this link for an example on how to do it for usb devices: http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/ Thats just one example. I'm sure there are many howtos out there which explain how to write udev rules. HTH, -mandeep On Wed, Mar 5, 2014 at 12:18 PM, Srinivas Ganji <srinivasganji.kernel@gmail.com> wrote:
Dear All,
We have a USB CDC device which we are connecting it to the Ubuntu system. Then, we are accessing the device using an application by opening the device with /dev/ttyACM0 node. The system may have multiple USB CDC devices already connected before connecting my device, sometimes. In such cases, my application fails to open the device, because, this time the assigned node is other than /dev/ttyAMC0, but in my application the device node is /dev/ttyAMC0 only. Due to these reasons, I want to assign my own device node in the /dev directory like /dev/mydev. This will enable my application to identify my device very easily.
The requirement is same as described in the link - http://marc.info/?l=linux-usb&m=130216901901572&w=2 The answer is available at http://marc.info/?l=linux-usb&m=130217684009490&w=2
I have tried in different ways as I have also looked at the following sources. But, still, there is NO luck. When I insert another USB CDC device, it got /dev/ttyACM0 instead of getting ttyACM1. http://www.reactivated.net/writing_udev_rules.html https://www.kernel.org/pub/linux/utils/kernel/hotplug/udev/udev.html http://unix.stackexchange.com/questions/77476/point-usb-phone-to-specific-de... https://www.pjrc.com/teensy/49-teensy.rules
The kernel version and distribution details are as follows. Kernel Version --- 3.5.0-17-generic Distribution details are as follows. RELEASE=14 CODENAME=nadia EDITION="MATE 64-bit" DESCRIPTION="Linux Mint 14 Nadia"
I have created a file, named 11-ttyACM.rules, under /etc/udev/rules.d directory. The contents of the file as follows. KERNEL=="ttyAMC0", SUBSYSTEM=="tty", ATTRS{serial}=="__0X00124B000148CC78", SYMLINK+="mydev"
I got the above information from the following command udevadm info -q all -n /dev/ttyACM0 --attribute-walk
This is what I did. But, no luck. If I insert a different serial numbered device, then it is assigning ttyACM0 to that device. But, after this udev rule, it should not assign, I think.
Please someone, who already used/knows udev rules, suggest me.
Thanks.
Regards, Srinivas.
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Srinivas Ganji <srinivasganji.kernel@gmail.com> writes:
I have created a file, named 11-ttyACM.rules, under /etc/udev/rules.d directory. The contents of the file as follows. KERNEL=="ttyAMC0", SUBSYSTEM=="tty", ATTRS{serial}=="__0X00124B000148CC78", SYMLINK+="mydev"
So this rule will create a symlink from /dev/mydev -> /dev/ttyAMC0 if all these conditions are met: a) KERNEL=="ttyAMC0" b) SUBSYSTEM=="tty" c) ATTRS{serial}=="__0X00124B000148CC78" I believe the a) condition is not exactly what you want. Firstly, the spelling makes it likely to never match... Secondly, even if you correct it to ACM, you really want this rule to match regardless of which ttyACMx device is assigned. That way you can ignore the device name and use the static /dev/mydev symlink. So you'd want to do something like this instead: KERNEL=="ttyACM*", SUBSYSTEM=="tty", ATTRS{serial}=="__0X00124B000148CC78", SYMLINK+="mydev"
I got the above information from the following command udevadm info -q all -n /dev/ttyACM0 --attribute-walk
This is what I did. But, no luck. If I insert a different serial numbered device, then it is assigning ttyACM0 to that device.
Yes. There is nothing in the rule controlling which name the kernel assigns. You cannot change this in any case. It's already decided at the point where the udev rule runs. Bjørn
Hi Bjorn, Yes. It was a TYPO. It should be ttyACM0, but not ttyAMC0. After changing to ttyACM0, it is working fine without any issues. Thanks. As you said, yes, if we assign ttyACM*, then it works fine even if we insert our device later, after inserting other ttyACM devices, also. If we do not use * then it won't work if we insert our device after inserting other ttyACM devices. My issue was resolved by changing the KERNEL=="ttyACM0" instead of KERNEL=="ttyAMC0". This is a simple TYPO and my overlooking while reading the rules. Anyhow, I have changed the rule as shown below. KERNEL=="ttyACM*", SUBSYSTEM=="tty", ATTRS{serial}=="__0X00124B000148CC78", SYMLINK+="mydev" Then, all issues were resolved. It works fine irrespective of the device insertion, too. Thank you all. Regards, Srinivas. On Wed, Mar 5, 2014 at 4:29 PM, Bjørn Mork <bjorn@mork.no> wrote:
Srinivas Ganji <srinivasganji.kernel@gmail.com> writes:
I have created a file, named 11-ttyACM.rules, under /etc/udev/rules.d directory. The contents of the file as follows. KERNEL=="ttyAMC0", SUBSYSTEM=="tty", ATTRS{serial}=="__0X00124B000148CC78", SYMLINK+="mydev"
So this rule will create a symlink from /dev/mydev -> /dev/ttyAMC0 if all these conditions are met:
a) KERNEL=="ttyAMC0" b) SUBSYSTEM=="tty" c) ATTRS{serial}=="__0X00124B000148CC78"
I believe the a) condition is not exactly what you want. Firstly, the spelling makes it likely to never match...
Secondly, even if you correct it to ACM, you really want this rule to match regardless of which ttyACMx device is assigned. That way you can ignore the device name and use the static /dev/mydev symlink.
So you'd want to do something like this instead:
KERNEL=="ttyACM*", SUBSYSTEM=="tty", ATTRS{serial}=="__0X00124B000148CC78", SYMLINK+="mydev"
I got the above information from the following command udevadm info -q all -n /dev/ttyACM0 --attribute-walk
This is what I did. But, no luck. If I insert a different serial numbered device, then it is assigning ttyACM0 to that device.
Yes. There is nothing in the rule controlling which name the kernel assigns. You cannot change this in any case. It's already decided at the point where the udev rule runs.
Bjørn
participants (3)
-
Bjørn Mork -
Mandeep Sandhu -
Srinivas Ganji