On 10/3/22 17:22, Michael Wimble wrote:
> I now have two LIDARs in Puck, instead of one, and they are both
> identical pieces of hardware. When I plug them in, they get mounted as
> /dev/ttyUSB0 and /dev/ttyUSB1. But, as is usual for Linux, it is not
> stable as to which LIDAR gets mapped to which dev entry. And, if you
> unplug and replug either LIDAR, it gets assigned a different device
> name. This makes it impossible to write a script that correctly
> references a specific LIDAR using the /dev name entry.
>
> The following assumes you know how the Linux “udev” system works, so I
> won’t expound on how to create the udev files and restart the udev system.
>
> My trick is to plug the two LIDARs into different USB controllers on my
> motherboard, ensuring they get assigned to two different USB busses.
> Note that this solution won’t work for computers that have only a single
> USB controller. Now I can used the “udev” system in Linux to fix the issue.
>
You 'can' use a similar trick as long as you plug your devices into the
same plug all the time. The USB tree knows, which devices is connected
to which controller and all the way to the 'plug';-)
That's how my tree looks like for my laptop right now.
(base) marcow@feather6:~$ sudo lsusb -t
[sudo] password for marcow:
/: Bus 06.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M
|__ Port 2: Dev 2, If 0, Class=Hub, Driver=hub/4p, 10000M
|__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/4p, 10000M
|__ Port 2: Dev 4, If 0, Class=Vendor Specific Class,
Driver=r8152, 5000M
/: Bus 05.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
|__ Port 2: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
|__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 1: Dev 5, If 0, Class=Hub, Driver=hub/2p, 480M
|__ Port 2: Dev 6, If 0, Class=Audio,
Driver=snd-usb-audio, 12M
|__ Port 2: Dev 6, If 1, Class=Audio,
Driver=snd-usb-audio, 12M
|__ Port 2: Dev 6, If 2, Class=Audio,
Driver=snd-usb-audio, 12M
|__ Port 2: Dev 6, If 3, Class=Human Interface Device,
Driver=usbhid, 12M
|__ Port 3: Dev 4, If 2, Class=Audio, Driver=snd-usb-audio, 480M
|__ Port 3: Dev 4, If 0, Class=Video, Driver=uvcvideo, 480M
|__ Port 3: Dev 4, If 3, Class=Audio, Driver=snd-usb-audio, 480M
|__ Port 3: Dev 4, If 1, Class=Video, Driver=uvcvideo, 480M
|__ Port 5: Dev 7, If 0, Class=, Driver=, 480M
/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/10p, 10000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/16p, 480M
|__ Port 2: Dev 2, If 2, Class=Chip/SmartCard, Driver=, 12M
|__ Port 2: Dev 2, If 0, Class=Human Interface Device,
Driver=usbhid, 12M
|__ Port 2: Dev 2, If 1, Class=Human Interface Device,
Driver=usbhid, 12M
|__ Port 8: Dev 3, If 3, Class=Video, Driver=uvcvideo, 480M
|__ Port 8: Dev 3, If 1, Class=Video, Driver=uvcvideo, 480M
|__ Port 8: Dev 3, If 2, Class=Video, Driver=uvcvideo, 480M
|__ Port 8: Dev 3, If 0, Class=Video, Driver=uvcvideo, 480M
|__ Port 9: Dev 4, If 0, Class=Vendor Specific Class, Driver=, 12M
|__ Port 10: Dev 5, If 0, Class=Human Interface Device,
Driver=usbhid, 12M
|__ Port 14: Dev 6, If 0, Class=Wireless, Driver=btusb, 12M
|__ Port 14: Dev 6, If 1, Class=Wireless, Driver=btusb, 12M
And after plugging in a hub with two identical USB-TTL serial
interfaces, I have
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/16p, 480M
|__ Port 2: Dev 2, If 2, Class=Chip/SmartCard, Driver=, 12M
|__ Port 2: Dev 2, If 0, Class=Human Interface Device,
Driver=usbhid, 12M
|__ Port 2: Dev 2, If 1, Class=Human Interface Device,
Driver=usbhid, 12M
|__ Port 6: Dev 7, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 4: Dev 10, If 0, Class=Vendor Specific Class,
Driver=ftdi_sio, 12M
|__ Port 1: Dev 11, If 0, Class=Vendor Specific Class,
Driver=ftdi_sio, 12M
Bus 001 Device 010: ID 0403:6001 Future Technology Devices
International, Ltd FT232 Serial (UART) IC
Bus 001 Device 011: ID 0403:6001 Future Technology Devices
International, Ltd FT232 Serial (UART) IC
>
> Here is what lsusb shows for the two LD06 LIDARs after plugging them in:
>
> lsusb
> Bus 003 Device 002: ID 10c4:ea60 Silicon Labs CP210x UART Bridge
> Bus 001 Device 009: ID 10c4:ea60 Silicon Labs CP210x UART Bridge
>
> So one device is plugged into the USB bus 3, and the other into the USB
> bus 1.
>
> Here are two different ways to write a udev rule to deal with this:
>
> more /etc/udev/rules.d/02-ldrobot.rules
> KERNEL=="ttyUSB*", ATTRS{busnum}=="3", ATTRS{idVendor}=="10c4",
> ATTRS{idProduct}=="ea60", MODE:="0777”, SYMLINK+="lidar_left_front"
>
> ATTRS{busnum}=="1", ATTRS{idVendor}=="10c4", MODE:="0777"
> SYMLINK+="lidar_right_rear"
>
You would add an ATTRS{devpath}=="6.4" or ATTRS{devpath}=="6.1" for my
two little boards;-)
Something like
KERNEL=="ttyUSB*", ATTRS{busnum}=="1" ATTRS{devpath}=="6.4"
ATTRS{idVendor}=="0403" ATTRS{idProduct}=="6001" SYMLINK+="foo4"
KERNEL=="ttyUSB*", ATTRS{busnum}=="1" ATTRS{devpath}=="6.1"
ATTRS{idVendor}=="0403" ATTRS{idProduct}=="6001" SYMLINK+="foo1"
That depends on the same device always being plugged into the same port!
Setting the mode to 777 is usually a bad idea:-( First of, you don't
want to 'execute' those files and even 666 can usually be avoided in
favor of a better 660 with the accessing users in the correct groups;-)
man udevadm gives you a lot of info;-) For instance, something like
udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0)
;-)
I hope, this helps a bit;-) udev is your friend when you need or want to
connect many USB (or other) devices;-)
-- Marco
> --
> You received this message because you are subscribed to the Google
> Groups "HomeBrew Robotics Club" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
hbrobotics+...@googlegroups.com
> <mailto:
hbrobotics+...@googlegroups.com>.
> <
https://groups.google.com/d/msgid/hbrobotics/16E16868-C98D-4D2B-AB61-69B7008E0313%40gmail.com?utm_medium=email&utm_source=footer>.