2017-02-07 08:04:38 +01:00
2012-07-22 23:37:31 -07:00
2016-04-03 10:27:53 -07:00
2013-08-14 19:22:55 -07:00
2016-04-03 10:38:12 -07:00

Introduction

Build Status GoDoc

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

Supported platforms include:

  • linux
  • darwin
  • windows

Contributing

Because I am a Google employee, 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. You will need to send me the email address that you used to sign the agreement so that I can verify that it is on file before I can accept pull requests.

Installation on Linux

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/kylelemons/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/kylelemons/gousb/usb

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 usb 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/kylelemons/gousb/usb{,id}

Installation on Windows

Dependencies

Build

  • After downloaded, extract them to some directory; such as D:\lib\libusb-1.0.xx\
  • Remember two path which "libusb.h" file and "libusb-1.0.a" inside

Note For MinGW32, use MinGW32/static/libusb-1.0.a while MinGW64 use MinGW64/static/libusb-1.0.a for linker

  • Open $(GOPATH)/src/github.com/kylelemons/gousb/usb/usb.go.

Then edit #cgo directive, such as

    // #cgo CFLAGS: -ID:/lib/libusbx-1.0.xx/include
    // #cgo LDFLAGS: D:/lib/libusbx-1.0.xx/MinGW64/static/libusb-1.0.a

to your libusb-1.0 installed path before the line:

// #include <libusb-1.0/libusb.h>

This flag will tell the linker the exact path of static library. Then install gousb:

  • Go to $(GOPATH)/src/github.com/kylelemons/gousb/. Run:

      $ go install ./...
    

    lsusb can run under $GOBIN/lsusb

Documentation

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

Description
gousb provides low-level interface for accessing USB devices
Readme Apache-2.0 3.9 MiB
Languages
Go 99.2%
C 0.6%
Smarty 0.1%