3

I have a USB RFID device that appears on /dev/hidraw for my serial devices they appear on /dev/ttyUSB* i used pyserial and it works like charm but for this one i couldn't read from it using cat /dev/hidraw0 need root privileges plus i need to read one line and not keep on listening

I used evdev library but my device doesn't appear at all :

import evdev
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
for device in devices:
    print(device.fn, device.name, device.phys)

So is there a proper way to read from the device programmatically ?

Safwen Daghsen
  • 145
  • 1
  • 4
  • 13
  • Your question is hard to read. Have a look at pyusb (of course you still need access rights to the device). – handle Jun 26 '16 at 11:42
  • If `cat /dev/hidraw0` can't see it, it doesn't sound good: you may have a defective device. Does it show up when you do `lsusb` in the terminal? Also check `dmesg | tail` after you plug it in. Note that even if lsusb can see it that doesn't necessarily imply that you can actually do anything useful with the device. But if lsusb _can't_ see it, it's probably dead. – PM 2Ring Jun 26 '16 at 11:54
  • i can read with the cat function but it needs root permission is there a way to read as normal user ? – Safwen Daghsen Jun 26 '16 at 11:58
  • The sudo cat /dev/hidrawX (hidraw3 in my case) worked nicely for me! Everytime the scanner recognized a barcode with the trigger, a string would pop out on terminal. Now that I did that sanity check, i can continue. Keep in mind I first used the Zebra config tool on windows to setup the scanner, I don't know if that helped or not. – jerrylogansquare Jan 08 '20 at 23:28

1 Answers1

3

By default evdev.list_devices() look only to /dev/input

And you need permissions to work with your device. You can add your user to group which own your device (see $ ls -l /dev/hidraw0 )

Then you need to listen your device in loop

#!/usr/bin/python3
import evdev

devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
for device in devices:
  print(device.fn, device.name, device.phys)

device = evdev.InputDevice("/dev/input/event4")
print(device)
for event in device.read_loop(): 
  print(event)
5n00py
  • 199
  • 2
  • 7
  • I have connected my Beurere BC 58 to raspberry pi 3 and saw the device is detected as /dev/hidraw3. But unfortunately I'm unable to locate the input events in the "dev". I have list of 3 events /dev/input/event0, event1, event2. In which event 1 and 2 are displayed as keyboards and one mouse. But my Blood pressure monitors is not part of any event. Is there any other of locating it? – Kiran Jun 05 '17 at 10:01