Giter Club home page Giter Club logo

usb's Introduction

Hackage Build Status

This library enables you to communicate with USB devices from userspace. It is implemented as a high-level wrapper around bindings-libusb which is a low-level binding to the C library: libusb-1.*.

The USB transfer functions in this library have a simple synchronous interface (they block) but are implemented using the libusb asynchronous interface. They integrate with the GHC event manager making them efficient (no busy-loops) and interruptible (throwing an exception to the thread executing a transfer immediately cancels the transfer).

If the GHC event manager is not available (because you're either not using GHC or because you're on Windows) the library degrades gracefully to the libusb synchronous implementation.

The documentation assumes knowledge of how to operate USB devices from a software standpoint (descriptors, configurations, interfaces, endpoints, control/bulk/interrupt/isochronous transfers, etc). Full information can be found in the USB 2.0 Specification.

For an example how to use this library see either the usb-example or ls-usb package.

Also see the usb-safe package which wraps this package and provides some strong safety guarantees for working with USB devices.

Finally have a look at the usb-iteratee package which provides iteratee enumerators for enumerating bulk, interrupt and isochronous endpoints.

Besides the API documentation the following sources might be interesting:

usb's People

Contributors

basvandijk avatar roelvandijk avatar ndtimofeev avatar tfausak avatar bgamari avatar mkeeter avatar ryantm avatar

Stargazers

Kevin Brubeck Unhammer avatar Rowan Goemans avatar  avatar  avatar James Brock avatar Jeff Ciesielski avatar  avatar Alex Zolotko avatar Adam Lučanský avatar Travis Whitaker avatar  avatar Ian Kane avatar  avatar Elliot Cameron avatar Cortland Walker avatar Tatsuya Hirose avatar Poon Wu avatar Utkarsh Upadhyay avatar Joven A. Barola avatar Aaron Robson avatar  avatar Jason Hickner avatar  avatar Rehno Lindeque avatar  avatar Vincent Hanquez avatar David Terei avatar

Watchers

Ian Kane avatar  avatar  avatar Adam Lučanský avatar James Cloos avatar  avatar j0h avatar  avatar  avatar

usb's Issues

Potential memory issues with 1.3

While testing 1.3 with a package of mine I noticed some strange behavior and occassional crashes. Running in valgrind made it very clear that there were some object lifetime issues introduced between 1.2.0.1 (which works well) and eba5bcc,

$ sudo valgrind dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host
==5254== Memcheck, a memory error detector
==5254== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==5254== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==5254== Command: dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host
==5254== 
Just "Hello World!"
==5254== Thread 3:
==5254== Invalid read of size 4
==5254==    at 0x6958414: pthread_mutex_lock (pthread_mutex_lock.c:66)
==5254==    by 0x4E3B672: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010930 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6953A03: __pthread_mutex_lock_full (pthread_mutex_lock.c:177)
==5254==    by 0x4E3B672: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010930 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x4E3B673: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010948 is 40 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid write of size 4
==5254==    at 0x4E3B67C: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010948 is 40 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x69597C0: pthread_mutex_unlock (pthread_mutex_unlock.c:41)
==5254==    by 0x4E3B683: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010930 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6953F8F: __pthread_mutex_unlock_full (pthread_mutex_unlock.c:102)
==5254==    by 0x4E3B683: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010930 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6958414: pthread_mutex_lock (pthread_mutex_lock.c:66)
==5254==    by 0x4E3B672: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6953A03: __pthread_mutex_lock_full (pthread_mutex_lock.c:177)
==5254==    by 0x4E3B672: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x4E3B673: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013988 is 40 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid write of size 4
==5254==    at 0x4E3B67C: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013988 is 40 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x69597C0: pthread_mutex_unlock (pthread_mutex_unlock.c:41)
==5254==    by 0x4E3B683: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6953F8F: __pthread_mutex_unlock_full (pthread_mutex_unlock.c:102)
==5254==    by 0x4E3B683: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6958414: pthread_mutex_lock (pthread_mutex_lock.c:66)
==5254==    by 0x4E3B672: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6953A03: __pthread_mutex_lock_full (pthread_mutex_lock.c:177)
==5254==    by 0x4E3B672: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x4E3B673: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013988 is 40 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid write of size 4
==5254==    at 0x4E3B67C: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013988 is 40 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x69597C0: pthread_mutex_unlock (pthread_mutex_unlock.c:41)
==5254==    by 0x4E3B683: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6953F8F: __pthread_mutex_unlock_full (pthread_mutex_unlock.c:102)
==5254==    by 0x4E3B683: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x4E3B6BE: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6958414: pthread_mutex_lock (pthread_mutex_lock.c:66)
==5254==    by 0x4E3B672: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x57A13A: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010930 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6953A03: __pthread_mutex_lock_full (pthread_mutex_lock.c:177)
==5254==    by 0x4E3B672: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x57A13A: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010930 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x4E3B673: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x57A13A: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010948 is 40 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid write of size 4
==5254==    at 0x4E3B67C: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x57A13A: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010948 is 40 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x69597C0: pthread_mutex_unlock (pthread_mutex_unlock.c:41)
==5254==    by 0x4E3B683: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x57A13A: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010930 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6953F8F: __pthread_mutex_unlock_full (pthread_mutex_unlock.c:102)
==5254==    by 0x4E3B683: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x57A13A: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe010930 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579E02: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6958414: pthread_mutex_lock (pthread_mutex_lock.c:66)
==5254==    by 0x4E3B672: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6953A03: __pthread_mutex_lock_full (pthread_mutex_lock.c:177)
==5254==    by 0x4E3B672: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x4E3B673: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013988 is 40 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid write of size 4
==5254==    at 0x4E3B67C: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013988 is 40 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x69597C0: pthread_mutex_unlock (pthread_mutex_unlock.c:41)
==5254==    by 0x4E3B683: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 
==5254== Invalid read of size 4
==5254==    at 0x6953F8F: __pthread_mutex_unlock_full (pthread_mutex_unlock.c:102)
==5254==    by 0x4E3B683: libusb_unref_device (in /lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254==  Address 0xe013970 is 16 bytes inside a block of size 152 free'd
==5254==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5254==    by 0x579CF5: ??? (in /home/bgamari/trees/tracker-host/dist/dist-sandbox-1cbac515/build/tracker-host/tracker-host)
==5254== 

Fix cbFnPtr leak

When a hotplug callback returns DeregisterThisCallback the callback FunPtr cbFnPtr is not finalized using freeHaskellFunPtr.

hotplug event segfault and other problem

Hello.

Thanks for making this library, it has been helpful for learning how to use libusb and talk to USB devices. Here is a bug report:

I compiled this program with usb-1.3.0.4 and ghc 7.10.3, using ghc with no options:

import Control.Concurrent
import Control.Exception
import Control.Monad
import Data.Functor
import Data.Word
import System.USB

main = do
  ctx <- newCtx
  forever $ do
    d <- waitForMyDevice ctx (Just 8187) Nothing Nothing
    print d
    threadDelay 1000000

waitForMyDevice :: Ctx
                -> Maybe VendorId
                -> Maybe ProductId
                -> Maybe Word8
                -> IO Device
waitForMyDevice ctx mbVendorId mbProductId mbDevClass = do
  mv <- newEmptyMVar
  -- We mask asynchronous exceptions to ensure that the callback
  -- gets properly deregistered when an asynchronous exception is
  -- thrown during the interruptible takeMVar operation.
  mask_ $ do
    h <- registerHotplugCallback ctx
                                 deviceArrived
                                 enumerate
                                 mbVendorId
                                 mbProductId
                                 mbDevClass
                                 (\ dev event ->
                                    tryPutMVar mv (dev, event) $>
                                      DeregisterThisCallback)
    (dev, _event) <- takeMVar mv
                       `onException`
                         deregisterHotplugCallback h
    return dev

waitForMyDevice is copied verbatim from: https://hackage.haskell.org/package/usb-1.3.0.4/docs/System-USB-Enumeration.html#t:HotplugCallback

I am running the program on Ubuntu inside of VirtualBox

$ uname -a
Linux ryantm-1604.pololu.internal 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

First, I was a bit surprised that, if I start the program with the USB device selected, it keeps printing out the device. I expected it to only print the device when the device was plugged in.

I noticed two problems:

  1. When I disconnect the device it stops printing. When I reconnect the device, it does not start printing the device again. Given that it prints out the device connected continuously, I expected it to start again when the device was plugged back in.
  2. If I have two devices with the same Vendor ID connected when I start the program, the program outputs "Segmentation fault (core dumped)". I expected it to be able to handle multiple similar devices.

Ryan

Asyncronous communicatin fails, but synchronous works

I'm not familiar enough to know whether this is an issue in libusb itself, in bindings-libusb, or in usb. Hopefully you'll easily see if this bug report is misplaced.

I'm working on communicating with an i.MX device, and so far the work has basically been to translate the relevant pats of sbloader to Haskell.

The initial command succeeded, but the sending of the first block of data failed:

libusb: warning [handle_timeout] async cancel failed -5 errno=22

Since all communication in sbloader is synchronous, and it succeeds, I recompiled usb with some parts of the Cabal file commented out in order to get a synchronous library:

Index: habs/haskell-usb/src/usb-1.2.0.1/usb.cabal
===================================================================
--- habs.orig/haskell-usb/src/usb-1.2.0.1/usb.cabal
+++ habs/haskell-usb/src/usb-1.2.0.1/usb.cabal
@@ -80,11 +80,6 @@ Library
                    System.USB.Internal
   other-modules: System.USB.Base, Utils

-  if impl(ghc>7) && !os(windows)
-    cpp-options: -DHAS_EVENT_MANAGER
-    other-modules: Poll, Event, SystemEventManager, Timeval
-    build-depends: containers >= 0.1 && < 0.6
-
   if impl(ghc >= 7.2.1)
     cpp-options: -DGENERICS
     build-depends: ghc-prim >= 0.2 && < 0.4

After that my own code successfully sends all data. I'm guessing there is some problem in the asynchronous code.

I'm on ArchLinux with these versions installed:

  • libusb 1.0.19
  • bindings-dsl 1.0.21
  • bindings-libusb 1.4.4.1
  • usb 1.2.0.1

(In my naivete I was wondering if this issue in libusbx might be lingering in libusb and causes this behaviour.)

Add function name to HandleUSBException

Hello,

When there is an USB exception, the message is ": NotFoundException", without a line number or which function is causing the issue.

Is there any way to get such details other than having to add a bunch of printf statements?

Thanks
Joe

`readControl` doesn't set request direction correctly

To construct the USB setup packet's bmRequestType byte, readControl uses marshallControlSetup, which in turn calls marshalRequestType.

Nothing in this function touches bit 7 of the bmRequestType byte, so the transfer is always sent out as a host-to-device transfer (rather than device-to-host), effectively writing rather than reading.

Segmentation fault when enumerating devices on Windows xp

After installing usb and bindings-libusb with libusbx, http://sourceforge.net/projects/libusbx/files/releases/, I tried enumerating the devices:

Prelude Bindings.Libusb Foreign System.USB> ctx <- newCtx
Loading package array-0.4.0.0 ... linking ... done.
Loading package bytestring-0.9.2.1 ... linking ... done.
Loading package deepseq-1.3.0.0 ... linking ... done.
Loading package text-0.11.2.3 ... linking ... done.
Loading package base-unicode-symbols-0.2.2.4 ... linking ... done.
Loading package usb-1.1.0.3 ... linking ... done.
Prelude Bindings.Libusb Foreign System.USB> getDevices ctx
*** Exception: NotFoundException
Prelude Bindings.Libusb Foreign System.USB> getDevices ctx
*** Exception: NotFoundException
Segmentation fault/access violation in generated code

Although the accompanying libusbx binaries can perfectly list the devices.

C:\Program Files\libusb\examples\bin32>listdevs
106b:003f (bus 1, device 1)
8086:265c (bus 2, device 1)
10cf:5500 (bus 1, device 2)

Manually trying with lowest level bindings-usb, I can enumerate the basic device info:

import Bindings.Libusb
import Foreign


printDevice :: Ptr C'libusb_device -> IO ()
printDevice dev = do
  alloca $ \descr_p -> do
    c'libusb_get_device_descriptor dev descr_p
    descr <- peek descr_p
    print descr


printDeviceList :: [Ptr C'libusb_device] -> IO ()
printDeviceList devlist = do
  print $ length devlist
  mapM_ printDevice devlist


main :: IO ()
main = do
  r <- c'libusb_init nullPtr
  -- r should be 0

  alloca $ \devl_p -> do
    nod <- c'libusb_get_device_list nullPtr devl_p
    devl <- peek devl_p
    dev_array <- peekArray (fromIntegral nod) devl
    printDeviceList dev_array
    c'libusb_free_device_list devl 1
    return ()

  c'libusb_exit nullPtr

Gives me:

3
C'libusb_device_descriptor {c'libusb_device_descriptor'bLength = 18, c'libusb_device_descriptor'bDescriptorType = 1, c'libusb_device_descriptor'bcdUSB = 0, c'li
busb_device_descriptor'bDeviceClass = 0, c'libusb_device_descriptor'bDeviceSubClass = 0, c'libusb_device_descriptor'bDeviceProtocol = 0, c'libusb_device_descrip
tor'bMaxPacketSize0 = 0, c'libusb_device_descriptor'idVendor = 4203, c'libusb_device_descriptor'idProduct = 63, c'libusb_device_descriptor'bcdDevice = 0, c'libu
sb_device_descriptor'iManufacturer = 0, c'libusb_device_descriptor'iProduct = 0, c'libusb_device_descriptor'iSerialNumber = 0, c'libusb_device_descriptor'bNumCo
nfigurations = 1}
C'libusb_device_descriptor {c'libusb_device_descriptor'bLength = 18, c'libusb_device_descriptor'bDescriptorType = 1, c'libusb_device_descriptor'bcdUSB = 0, c'li
busb_device_descriptor'bDeviceClass = 0, c'libusb_device_descriptor'bDeviceSubClass = 0, c'libusb_device_descriptor'bDeviceProtocol = 0, c'libusb_device_descrip
tor'bMaxPacketSize0 = 0, c'libusb_device_descriptor'idVendor = 32902, c'libusb_device_descriptor'idProduct = 9820, c'libusb_device_descriptor'bcdDevice = 0, c'l
ibusb_device_descriptor'iManufacturer = 0, c'libusb_device_descriptor'iProduct = 0, c'libusb_device_descriptor'iSerialNumber = 0, c'libusb_device_descriptor'bNu
mConfigurations = 1}
C'libusb_device_descriptor {c'libusb_device_descriptor'bLength = 18, c'libusb_device_descriptor'bDescriptorType = 1, c'libusb_device_descriptor'bcdUSB = 272, c'
libusb_device_descriptor'bDeviceClass = 0, c'libusb_device_descriptor'bDeviceSubClass = 0, c'libusb_device_descriptor'bDeviceProtocol = 0, c'libusb_device_descr
iptor'bMaxPacketSize0 = 8, c'libusb_device_descriptor'idVendor = 4303, c'libusb_device_descriptor'idProduct = 21760, c'libusb_device_descriptor'bcdDevice = 0, c
'libusb_device_descriptor'iManufacturer = 1, c'libusb_device_descriptor'iProduct = 2, c'libusb_device_descriptor'iSerialNumber = 0, c'libusb_device_descriptor'b
NumConfigurations = 1}

ghc-7.10.1 compatibility

Hi!

I have tried to port usb to base-4.8.0.0 and have got a trable. New registerFd takes extra Lifetime argument. Lifetime is ADT that does not exported from GHC.Event.Internal.

Is it possible to workaround using of registerFd?

cabal can't install usb or usb-safe, base issues

what version of "base" work for this project? I have 4.6
(cabal newb here.) Also, where can I get a working version of base?

:~/$ cabal install usb-safe
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: usb-safe-0.14 (user goal)
next goal: base (dependency of usb-safe-0.14)
rejecting: base-4.6.0.1/installed-8aa... (conflict: usb-safe => base>=4 &&
<4.5)
rejecting: base-4.7.0.2, 4.7.0.1, 4.7.0.0, 4.6.0.1, 4.6.0.0, 4.5.1.0, 4.5.0.0,
4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0, 4.1.0.0,
4.0.0.0, 3.0.3.2, 3.0.3.1 (global constraint requires installed instance)
Dependency tree exhaustively searched.

so then, I tried installing using verbose output:
pastebin.com/W1yUXVdL

I hope that helps.
I was able to install the usb library using $cabal install usb-1.2

Don't store the DeviceDesc in the Device

@jputcu wrote in issue #1:

After installing usb and bindings-libusb with libusbx, http://sourceforge.net/projects/libusbx/files/releases/, I tried enumerating the devices:

Prelude Bindings.Libusb Foreign System.USB> ctx <- newCtx
Prelude Bindings.Libusb Foreign System.USB> getDevices ctx
*** Exception: NotFoundException

This I think is caused because on Windows not all devices support getting their descriptors.

The right way to solve this is to remove the DeviceDesc from the Device and turn deviceDesc into an IO operation:

deviceDesc :: Device -> IO DeviceDesc

This is a better choice anyway since it involves less I/O when enumerating devices using getDevices.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.