Chhavi Goenka
2016-01-21 20:17:34 UTC
Hi,
I am trying to interface raspberry pi with a custom HID device via USB. I
am using PYUSB for this. But once I run my program i get a timeout error.
Here is my program:
import os
import sys
import time
import usb.core
import usb.util
packet_len = 64
# packet request function
def pack_request(*arguments):
packet = [0x0] * packet_len
i = 0
for arg in arguments:
packet[i] = arg
i+=1
return ''.join([chr(c) for c in packet])
def show_result(bytes):
sys.stdout.write("Result:")
sys.stdout.write(''.join(['%d ' % abyte for abyte in bytes]))
def main():
dev = usb.core.find(idVendor = 0x04d8, idProduct = 0xf2a6)
if dev is None:
raise ValueError('Device not found')
#dev.set_configuration()
if dev.is_kernel_driver_active(0):
reattach = True
dev.detach_kernel_driver(0)
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
assert ep is not None
raw = pack_request(0x00, 0x81)
dev.write(1, raw, 100)
bytes = dev.read(0x81,packet_len, 10000)
show_result(bytes)
#print(bytes)
if __name__ == '__main__':
main()
and Here is the error:
***@raspberrypi:~/Documents $ sudo python multispec_usbcode_jan21.py
Traceback (most recent call last):
File "multispec_usbcode_jan21.py", line 66, in <module>
main()
File "multispec_usbcode_jan21.py", line 58, in main
dev.write(1, raw,100)
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 878, in
write
self.__get_timeout(timeout)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py",
line 778, in intr_write
timeout)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py",
line 856, in __write
_check(retval)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py",
line 552, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 110] Operation timed out
Please let me know how to get around this?
Thanks,
Chhavi
I am trying to interface raspberry pi with a custom HID device via USB. I
am using PYUSB for this. But once I run my program i get a timeout error.
Here is my program:
import os
import sys
import time
import usb.core
import usb.util
packet_len = 64
# packet request function
def pack_request(*arguments):
packet = [0x0] * packet_len
i = 0
for arg in arguments:
packet[i] = arg
i+=1
return ''.join([chr(c) for c in packet])
def show_result(bytes):
sys.stdout.write("Result:")
sys.stdout.write(''.join(['%d ' % abyte for abyte in bytes]))
def main():
dev = usb.core.find(idVendor = 0x04d8, idProduct = 0xf2a6)
if dev is None:
raise ValueError('Device not found')
#dev.set_configuration()
if dev.is_kernel_driver_active(0):
reattach = True
dev.detach_kernel_driver(0)
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
assert ep is not None
raw = pack_request(0x00, 0x81)
dev.write(1, raw, 100)
bytes = dev.read(0x81,packet_len, 10000)
show_result(bytes)
#print(bytes)
if __name__ == '__main__':
main()
and Here is the error:
***@raspberrypi:~/Documents $ sudo python multispec_usbcode_jan21.py
Traceback (most recent call last):
File "multispec_usbcode_jan21.py", line 66, in <module>
main()
File "multispec_usbcode_jan21.py", line 58, in main
dev.write(1, raw,100)
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 878, in
write
self.__get_timeout(timeout)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py",
line 778, in intr_write
timeout)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py",
line 856, in __write
_check(retval)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py",
line 552, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 110] Operation timed out
Please let me know how to get around this?
Thanks,
Chhavi