UPDATE: I added a symbolic link to my .rules file and it is being created every time I unplug/plug the scanner. I believe my issue is more of a permissions issue with my Python code and more applicable to a different forum. Closing this as resolved for now. Updated .rules file below for reference.

KERNEL=="hidraw[0-3]*", SUBSYSTEM=="hidraw", SUBSYSTEMS=="usb", ATTRS{idProduct}=="1000", ATTRS{idVendor}=="e851", SYMLINK+="MyBarcoder1"

I'm trying to build a new rules file to help access and make use of a barcode scanner with the pyusb library. I'm not exactly sure what parameters need to be included in the rules file. I've read just about every thread I can find on the matter to no avail. Also, I'm brand new to Python and Kernels so that doesn't make this any easier. I know I need the idVendor and idProduct to identify the scanner, but I'm not really sure about the Kernel, Subsystem(s), or Group (if that's required). Current 63-scanner.rules

KERNEL=="1-1.4",SUBSYSTEMS=="usb", ATTRS{idProduct}=="1000", ATTRS{idVendor}=="e851"

Output through each hierarchical layer of the kernel.

pi@raspberrypi:/lib/udev/rules.d $ udevadm info -a -p $(udevadm info -q path -n /dev/hidraw2)

Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device.

looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/0003:E851:1000.0026/hidraw/hidraw2': KERNEL=="hidraw2" SUBSYSTEM=="hidraw" DRIVER==""

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/0003:E851:1000.0026': KERNELS=="0003:E851:1000.0026" SUBSYSTEMS=="hid" DRIVERS=="hid-generic" ATTRS{country}=="00"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0': KERNELS=="1-1.4:1.0" SUBSYSTEMS=="usb" DRIVERS=="usbhid" ATTRS{authorized}=="1" ATTRS{bAlternateSetting}==" 0" ATTRS{bInterfaceClass}=="03" ATTRS{bInterfaceNumber}=="00" ATTRS{bInterfaceProtocol}=="01" ATTRS{bInterfaceSubClass}=="01" ATTRS{bNumEndpoints}=="01" ATTRS{interface}=="HID Interface" ATTRS{supports_autosuspend}=="1"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4': KERNELS=="1-1.4" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{authorized}=="1" ATTRS{avoid_reset_quirk}=="0" ATTRS{bConfigurationValue}=="1" ATTRS{bDeviceClass}=="00" ATTRS{bDeviceProtocol}=="00" ATTRS{bDeviceSubClass}=="00" ATTRS{bMaxPacketSize0}=="64" ATTRS{bMaxPower}=="500mA" ATTRS{bNumConfigurations}=="1" ATTRS{bNumInterfaces}==" 1" ATTRS{bcdDevice}=="0233" ATTRS{bmAttributes}=="80" ATTRS{busnum}=="1" ATTRS{configuration}=="" ATTRS{devnum}=="41" ATTRS{devpath}=="1.4" ATTRS{devspec}==" (null)" ATTRS{idProduct}=="1000" ATTRS{idVendor}=="e851" ATTRS{ltm_capable}=="no" ATTRS{manufacturer}=="Manufacturer" ATTRS{maxchild}=="0" ATTRS{product}=="Barcode Reader" ATTRS{quirks}=="0x0" ATTRS{removable}=="removable" ATTRS{speed}=="12" ATTRS{urbnum}=="15" ATTRS{version}==" 1.10"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1': KERNELS=="1-1" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{authorized}=="1" ATTRS{avoid_reset_quirk}=="0" ATTRS{bConfigurationValue}=="1" ATTRS{bDeviceClass}=="09" ATTRS{bDeviceProtocol}=="02" ATTRS{bDeviceSubClass}=="00" ATTRS{bMaxPacketSize0}=="64" ATTRS{bMaxPower}=="2mA" ATTRS{bNumConfigurations}=="1" ATTRS{bNumInterfaces}==" 1" ATTRS{bcdDevice}=="0200" ATTRS{bmAttributes}=="e0" ATTRS{busnum}=="1" ATTRS{configuration}=="" ATTRS{devnum}=="2" ATTRS{devpath}=="1" ATTRS{idProduct}=="9514" ATTRS{idVendor}=="0424" ATTRS{ltm_capable}=="no" ATTRS{maxchild}=="5" ATTRS{quirks}=="0x0" ATTRS{removable}=="unknown" ATTRS{speed}=="480" ATTRS{urbnum}=="1234" ATTRS{version}==" 2.00"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1': KERNELS=="usb1" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{authorized}=="1" ATTRS{authorized_default}=="1" ATTRS{avoid_reset_quirk}=="0" ATTRS{bConfigurationValue}=="1" ATTRS{bDeviceClass}=="09" ATTRS{bDeviceProtocol}=="01" ATTRS{bDeviceSubClass}=="00" ATTRS{bMaxPacketSize0}=="64" ATTRS{bMaxPower}=="0mA" ATTRS{bNumConfigurations}=="1" ATTRS{bNumInterfaces}==" 1" ATTRS{bcdDevice}=="0414" ATTRS{bmAttributes}=="e0" ATTRS{busnum}=="1" ATTRS{configuration}=="" ATTRS{devnum}=="1" ATTRS{devpath}=="0" ATTRS{idProduct}=="0002" ATTRS{idVendor}=="1d6b" ATTRS{interface_authorized_default}=="1" ATTRS{ltm_capable}=="no" ATTRS{manufacturer}=="Linux 4.14.34-v7+ dwc_otg_hcd" ATTRS{maxchild}=="1" ATTRS{product}=="DWC OTG Controller" ATTRS{quirks}=="0x0" ATTRS{removable}=="unknown" ATTRS{serial}=="3f980000.usb" ATTRS{speed}=="480" ATTRS{urbnum}=="26" ATTRS{version}==" 2.00"

looking at parent device '/devices/platform/soc/3f980000.usb': KERNELS=="3f980000.usb" SUBSYSTEMS=="platform" DRIVERS=="dwc_otg" ATTRS{busconnected}=="Bus Connected = 0x1" ATTRS{buspower}=="Bus Power = 0x1" ATTRS{bussuspend}=="Bus Suspend = 0x0" ATTRS{devspeed}=="Device Speed = 0x0" ATTRS{driver_override}=="(null)" ATTRS{enumspeed}=="Device Enumeration Speed = 0x1" ATTRS{fr_interval}=="Frame Interval = 0x1d4b" ATTRS{ggpio}=="GGPIO = 0x00000000" ATTRS{gnptxfsiz}=="GNPTXFSIZ = 0x01000306" ATTRS{gotgctl}=="GOTGCTL = 0x001c0001" ATTRS{gpvndctl}=="GPVNDCTL = 0x00000000" ATTRS{grxfsiz}=="GRXFSIZ = 0x00000306" ATTRS{gsnpsid}=="GSNPSID = 0x4f54280a" ATTRS{guid}=="GUID = 0x2708a000" ATTRS{gusbcfg}=="GUSBCFG = 0x20001700" ATTRS{hcd_frrem}=="HCD Dump Frame Remaining" ATTRS{hcddump}=="HCD Dump" ATTRS{hnp}=="HstNegScs = 0x0" ATTRS{hnpcapable}=="HNPCapable = 0x1" ATTRS{hprt0}=="HPRT0 = 0x00001005" ATTRS{hptxfsiz}=="HPTXFSIZ = 0x02000406" ATTRS{hsic_connect}=="HSIC Connect = 0x1" ATTRS{inv_sel_hsic}=="Invert Select HSIC = 0x0" ATTRS{mode}=="Mode = 0x1" ATTRS{mode_ch_tim_en}=="Mode Change Ready Timer Enable = 0x0" ATTRS{rd_reg_test}=="Time to read GNPTXFSIZ reg 10000000 times: 1230 msecs (123 jiffies)" ATTRS{regdump}=="Register Dump" ATTRS{regoffset}=="0xffffffff" ATTRS{regvalue}=="invalid offset" ATTRS{rem_wakeup_pwrdn}=="" ATTRS{remote_wakeup}=="Remote Wakeup Sig = 0 Enabled = 0 LPM Remote Wakeup = 0" ATTRS{spramdump}=="SPRAM Dump" ATTRS{srp}=="SesReqScs = 0x1" ATTRS{srpcapable}=="SRPCapable = 0x1" ATTRS{wr_reg_test}=="Time to write GNPTXFSIZ reg 10000000 times: 410 msecs (41 jiffies)"

looking at parent device '/devices/platform/soc': KERNELS=="soc" SUBSYSTEMS=="platform" DRIVERS=="" ATTRS{driver_override}=="(null)"

looking at parent device '/devices/platform': KERNELS=="platform" SUBSYSTEMS=="" DRIVERS==""

Tailing the syslog to see what happens when the scanner is unplugged/plugged.

  • Jun 20 15:32:59 raspberrypi kernel: [102427.935608] usb 1-1.4: USB disconnect, device number 41
  • Jun 20 15:33:05 raspberrypi kernel: [102434.154884] usb 1-1.4: new full-speed USB device number 42 using dwc_otg
  • Jun 20 15:33:05 raspberrypi kernel: [102434.288366] usb 1-1.4: New USB device found, idVendor=e851, idProduct=1000
  • Jun 20 15:33:05 raspberrypi kernel: [102434.288377] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
  • Jun 20 15:33:05 raspberrypi kernel: [102434.288381] usb 1-1.4: Product: Barcode Reader
  • Jun 20 15:33:05 raspberrypi kernel: [102434.288386] usb 1-1.4: Manufacturer: Manufacturer
  • Jun 20 15:33:05 raspberrypi kernel: [102434.294652] input: Manufacturer Barcode Reader as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/0003:E851:1000.0027/input/input38
  • Jun 20 15:33:05 raspberrypi kernel: [102434.355736] hid-generic 0003:E851:1000.0027: input,hidraw2: USB HID v1.01 Keyboard [Manufacturer Barcode Reader] on usb-3f980000.usb-1.4/input0
  • Jun 20 15:33:05 raspberrypi mtp-probe: checking bus 1, device 42: "/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4"
  • Jun 20 15:33:05 raspberrypi mtp-probe: bus: 1, device: 42 was not an MTP device
  • Jun 20 15:33:05 raspberrypi systemd-udevd[11633]: Process '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' failed with exit code 1.
  • Your rule doesn't appear to do anything, it lists conditions but no action. Is that intended? – Dmitry Grigoryev Jun 21 '18 at 16:27
  • I don't need it to launch a script of any sort, if that's what you're asking. All I need it to do is allow me to access a barcode scanner, the same way, every time it's plugged in. In order to make use of pyusb (libusb) library, I need to be able to access the scanner and pull configurations. I believe that I should be able to do that if I create the rule file the correct way. Which obviously, I haven't done. – Joshua Watson Jun 21 '18 at 17:47
  • I'm glad you have resolved this. In retrospective, do you think it was possible for someone to deduce from your question that you needed SYMLINK+="MyBarcoder1" as action? – Dmitry Grigoryev Jun 22 '18 at 11:22
  • No, probably not. – Joshua Watson Jun 22 '18 at 15:17

Your Answer

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

Browse other questions tagged or ask your own question.