0

I have a raspberry pi and two QR code scanners, scanner1, and scanner2, I want to connect both scanners with the raspberry pi but at specific ports. Rasberry pi has four USB ports 1, 2, 3, and 4 respectively.

I want scanner 1 to always connect to port one, not any other port.

Both scanners have the same productId.

Any suggestions? How can i achieve the same !

4
  • 2
    why do you want to do this? ... this looks like an XY question ... asking for help with a perceived solution to an unspecified problem
    – jsotola
    Sep 24, 2022 at 23:33
  • Its my own project Sep 25, 2022 at 6:25
  • 1
    color code the connectors ... your question is not about Raspberry Pi ... it is about restricting a cable to a specific connector
    – jsotola
    Sep 25, 2022 at 15:39
  • Do you want a USB device to have a stable name? In this case refer to raspberrypi.stackexchange.com/q/70083/33476 Oct 10, 2022 at 12:35

1 Answer 1

0

Run udevadm info --attribute-walk --path=/sys/bus/path/to/device and see if there are attributes which allow you to distinguish the scanners, like a serial number or a product revision. This would allow you to distinguish the scanners regardless in which ports they are plugged.

If both scanners are identical, you can distinguish them by the USB port in which they are plugged using KERNELS=="1-2.3" attribute, which refers to a device connected to USB bus 1, hub on port 2 and finally, port 3 of the said hub. The correct attribute values for your system can also be discovered with the udevadm info command.

In both cases, you need to write an udev rule as described here which either sets a certain name for each device (e.g. NAME="ttyUSB0" and NAME="ttyUSB1"), or creates symlinks with meaningful names (e.g. SYMLINK+="/dev/scanner1" and SYMLINK+="/dev/scanner2") and make sure to use these names in your applications. Symlinks avoid issues when you have a third device which occupies one of the names you want to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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