T
T
tayanov2016-04-08 11:49:43
linux
tayanov, 2016-04-08 11:49:43

How to set a specific dev for each of two identical webcams in Linux?

There are two cheap cameras. So cheap that the output
of udevadm info -a -n /dev/video0
and
udevadm info -a -n /dev/video1 is identical
. There is no difference in vid, pid, SN, etc.
But you need to be sure that after a reboot, video1 and video0 will not change places.
The implementation was planned through the rules in /etc/udev/rules.d
With the replacement of the standard dev with video0 for say cam0.
Here are different lines, but I think that they cannot be hooked on.

looking at device '/devices/pci0000:00/0000:00:1d.7/usb2/2-6/2-6.3/2-6.3:1.0/video4linux/video0'                                              :
   KERNEL=="video0"
  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb2/2-6/2-6.3/2-6.3:1.0':
   KERNELS=="2-6.3:1.0"
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb2/2-6/2-6.3':
   KERNELS=="2-6.3"
 ATTRS{devpath}=="6.3"
ATTRS{devnum}=="9"

the difference goes to unity. let's say KERNEL=="video0" changes to KERNEL=="video1"
ATTRS{devpath}=="6.3" to ATTRS{devpath}=="6.4"
And if this is important, the connection is made through 1 usb port, then a hub for 4 ports. There are no plans to remove cameras from the hub. Can this be hooked on?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin ™, 2016-04-09
@tayanov

I had a similar task: a bunch of tokens, sometimes with the same vid and pid, are placed on usb ports, including through a usb hub. OS Linux Debian 8.
It is impossible to uniquely identify the token, since there is no unique serial number. But the serial number is present for each usb root hub built into the motherboard. This means that you can hard-code its busnum for each root hub, and if you do not pull out tokens, then their devnum will be constant.
I pulled out all the tokens and, using lsusb, found out that I have 8 usb root hubs, each occupies device number 1:

Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

After that, I found out the serial number of each root hub, changing 005 in the range from 001 to 008:
[email protected]:~# udevadm info -a /dev/bus/usb/005/001 | grep serial
    ATTR{serial}=="0000:00:1a.2"

Based on the serials, I made a rule for udev (created a file in /etc/udev/rules.d/ file 10-usb.rules):
SUBSYSTEM=="usb", ATTR{devnum}=="1", ATTR{serial}=="0000:00:1a.7", ATTR{busnum}="1"
SUBSYSTEM=="usb", ATTR{devnum}=="1", ATTR{serial}=="0000:00:1d.7", ATTR{busnum}="2"
SUBSYSTEM=="usb", ATTR{devnum}=="1", ATTR{serial}=="0000:00:1a.0", ATTR{busnum}="3"
SUBSYSTEM=="usb", ATTR{devnum}=="1", ATTR{serial}=="0000:00:1a.1", ATTR{busnum}="4"
SUBSYSTEM=="usb", ATTR{devnum}=="1", ATTR{serial}=="0000:00:1a.2", ATTR{busnum}="5"
SUBSYSTEM=="usb", ATTR{devnum}=="1", ATTR{serial}=="0000:00:1d.0", ATTR{busnum}="6"
SUBSYSTEM=="usb", ATTR{devnum}=="1", ATTR{serial}=="0000:00:1d.1", ATTR{busnum}="7"
SUBSYSTEM=="usb", ATTR{devnum}=="1", ATTR{serial}=="0000:00:1d.2", ATTR{busnum}="8"

I rebooted, the tokens remained in their places.
You can also add rules for creating named symlinks based on the busnum and devnum of each camera.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question