Vanlon
Vanlon

Reputation: 27

Evdev error correction for lost usb connection

I am using Evdev to get the input from a USB barcode scanner. I am using a Zebra one and sometimes when you put it back on the cradle it looses connection for a split second. Which just happens to be long enough to error out my code. Does anyone know how to put error correction in this code to handle a device not being detected and try until it is?

from evdev import InputDevice

from select import select

# A mapping of file descriptors (integers) to InputDevice instances.

devices = map(InputDevice, ('/dev/input/event1', '/dev/input/event2'))

devices = {dev.fd: dev for dev in devices}

while True:

   r, w, x = select(devices, [], [])

   for fd in r:

       for event in devices[fd].read():

           print(event)

I'm thinking some code that could map all devices rather than specific ones may work

Upvotes: 1

Views: 21

Answers (0)

Related Questions