edt1
edt1

Reputation: 3

Lagging for multiple HID devices when one is not moving (PyUSB)

I am using two HID devices (Logitech Attack 3 controllers) with the same product and vendor IDs, so they are differentiated using their Bus and Device numbers.

When I move both devices at once, they operate without any lag, but when I only move one of them, it is extremely laggy. I think that this might be due to some lag in the processing of the USBError exception, which is triggered every time one of the devices is not moving. The code works fine if the second device is taken out.

I believe this is the problematic code:

while True:
  print "Hi"
  try:
    rData = rDev.read(endpointR.bEndpointAddress,endpointR.wMaxPacketSize)
    print "right"
    print rData
  except usb.core.USBError as e:
    rData = None
  try:
    lData = lDev.read(endpointL.bEndpointAddress,endpointL.wMaxPacketSize)
    print "left"
    print lData
  except usb.core.USBError as e:
    lData = None

Thanks in advance.

Upvotes: 0

Views: 314

Answers (1)

Paul Cornelius
Paul Cornelius

Reputation: 10936

According to the docs the read function takes an optional keyword argument, timeout, which specifies the timeout in milliseconds. The default is 1000. Since you aren't providing this argument the function may take as long as 1 second to return. Apparently this device doesn't send data to the host (the OS) unless it moves, which means that in such cases the read function will timeout. So you need to set the timeout keyword. An alternative might be to move this code to another thread where the timeouts won't be evident to the user.

Upvotes: 1

Related Questions