Hi, Chhavi!

I'll defer to other opinions on the matter, but I think pyusb might be too
low-level for your purposes, Chhavi. I've been able to interface with a HID
scale on a Raspberry Pi using the python 'hidapi' package. See
https://github.com/libretees/silverscale for an example project.

--contracode


On Thu, Jan 21, 2016 at 3:17 PM, Chhavi Goenka <cgoe...@gmail.com> wrote:

> 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:
>
> pi@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
>
>
>
>
> ------------------------------------------------------------------------------
> Site24x7 APM Insight: Get Deep Visibility into Application Performance
> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
> Monitor end-to-end web transactions and take corrective actions now
> Troubleshoot faster and improve end-user experience. Signup Now!
> http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
> _______________________________________________
> pyusb-users mailing list
> pyusb-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyusb-users
>
>
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to