gousb provides low-level interface for accessing USB devices
Switch branches/tags
Nothing to show
Clone or download
Permalink
Failed to load latest commit information.
.appveyor Appveyor support (#2) Jun 20, 2017
lsusb Update uses of List/OpenDevices Jun 13, 2017
rawread Allocate libusb buffers in C (#11) Aug 29, 2017
usbid Add missing argument to Fatalf. Nov 12, 2017
.gitignore Appveyor support (#2) Jun 20, 2017
.travis.yml travis: update go versions (#24) Nov 12, 2017
AUTHORS Add Device.Manufacturer(), .Product() and .SerialNumber() (#14) Sep 3, 2017
CONTRIBUTING.md Define the contribution process. Feb 7, 2017
LICENSE Update LICENSE Aug 15, 2013
README.md Add AppVeyor badge. (#41) May 23, 2018
appveyor.yml Appveyor support (#2) Jun 20, 2017
config.go Set alternate setting for the interface only if required. (#38) May 23, 2018
constants.go Add more device classes, based on libusb.h enumeration. (#51) Oct 5, 2018
debug.go lint fixes May 6, 2017
device.go Add the number of the USB port in the DeviceDesc structure (#18) Sep 7, 2017
device_test.go Parallelize tests (#17) Sep 4, 2017
endpoint.go Parallelize tests (#17) Sep 4, 2017
endpoint_stream.go Write stream implementation (#19) Sep 8, 2017
endpoint_stream_test.go Write stream implementation (#19) Sep 8, 2017
endpoint_test.go Write stream implementation (#19) Sep 8, 2017
error.go Remove "libusb" from the comments. May 5, 2017
example_test.go Add missing endpoint argument to Fatalf. Nov 12, 2017
fakelibusb_devices.go Add the number of the USB port in the DeviceDesc structure (#18) Sep 7, 2017
fakelibusb_test.go Write stream implementation (#19) Sep 8, 2017
fixlibusb_darwin.sh Add script to fix libusb on darwin Apr 7, 2013
interface.go Parallelize tests (#17) Sep 4, 2017
libusb.go Use gousb_set_debug instead of libusb_set_debug in one more place. (#44) Jun 16, 2018
libusb_cgo_benchmark_test.go Move files from gousb/usb to gousb May 5, 2017
misc.go more comment updates, rename "intf" parameter of Interface to "num" Jun 13, 2017
misc_test.go Config and interface description (#16) Sep 4, 2017
transfer.c Allocate libusb buffers in C (#11) Aug 29, 2017
transfer.go Parallelize tests (#17) Sep 4, 2017
transfer_stream.go Write stream implementation (#19) Sep 8, 2017
transfer_stream_test.go Write stream implementation (#19) Sep 8, 2017
transfer_test.go Write stream implementation (#19) Sep 8, 2017
usb.c Support libusb_set_option in additon to libusb_set_debug. (#39) May 23, 2018
usb.go Support libusb_set_option in additon to libusb_set_debug. (#39) May 23, 2018
usb_test.go Parallelize tests (#17) Sep 4, 2017

README.md

Introduction

Build Status GoDoc Coverage Status Build status

The gousb package is an attempt at wrapping the libusb library into a Go-like binding.

Supported platforms include:

  • linux
  • darwin
  • windows

This is the release 2.0 of the package github.com/kylelemons/gousb. Its API is not backwards-compatible with version 1.0. As of 2017-07-13 the 2.0 API is considered stable and 1.0 is deprecated.

Documentation

The documentation can be viewed via local godoc or via the excellent godoc.org:

Installation

Dependencies

You must first install libusb-1.0. This is pretty straightforward on linux and darwin. The cgo package should be able to find it if you install it in the default manner or use your distribution's package manager. How to tell cgo how to find one installed in a non-default place is beyond the scope of this README.

Note: If you are installing this on darwin, you will probably need to run fixlibusb_darwin.sh /usr/local/lib/libusb-1.0/libusb.h because of an LLVM incompatibility. It shouldn't break C programs, though I haven't tried it in anger.

Example: lsusb

The gousb project provides a simple but useful example: lsusb. This binary will list the USB devices connected to your system and various interesting tidbits about them, their configurations, endpoints, etc. To install it, run the following command:

go get -v github.com/google/gousb/lsusb

gousb

If you installed the lsusb example, both libraries below are already installed.

Installing the primary gousb package is really easy:

go get -v github.com/google/gousb

There is also a usbid package that will not be installed by default by this command, but which provides useful information including the human-readable vendor and product codes for detected hardware. It's not installed by default and not linked into the gousb package by default because it adds ~400kb to the resulting binary. If you want both, they can be installed thus:

go get -v github.com/google/gousb{,/usbid}

Notes for installation on Windows

You'll need:

Make sure the libusb-1.0.pc pkg-config file from libusb was installed and that the result of the pkg-config --cflags libusb-1.0 command shows the correct include path for installed libusb.

After that you can continue with instructions for lsusb/gousb above.

Contributing

Contributing to this project will require signing the Google CLA. This is the same agreement that is required for contributing to Go itself, so if you have already filled it out for that, you needn't fill it out again.