Categorygithub.com/google/gousb
modulepackage
2.1.0+incompatible
Repository: https://github.com/google/gousb.git
Documentation: pkg.go.dev

# README

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.

# Packages

lsusb lists attached USB devices.
rawread attempts to read from the specified USB device.
Package usbid provides human-readable text output for the usb package.

# Functions

NewContext returns a new Context instance.
Version returns a BCD version number with given major/minor.

# Structs

Config represents a USB device set to use a particular configuration.
ConfigDesc contains the information about a USB device configuration, extracted from the device descriptor.
Context manages all resources related to USB device handling.
Device represents an opened USB device.
DeviceDesc is a representation of a USB device descriptor.
EndpointDesc contains the information about an interface endpoint, extracted from the descriptor.
InEndpoint represents an IN endpoint open for transfer.
Interface is a representation of a claimed interface with a particular setting.
InterfaceDesc contains information about a USB interface, extracted from the descriptor.
InterfaceSetting contains information about a USB interface with a particular alternate setting, extracted from the descriptor.
OutEndpoint represents an OUT endpoint open for transfer.
ReadStream is a buffer that tries to prefetch data from the IN endpoint, reducing the latency between subsequent Read()s.
WriteStream is a buffer that will send data asynchronously, reducing the latency between subsequent Write()s.

# Type aliases

BCD is a binary-coded decimal version number.
EndpointAddress is a unique identifier for the endpoint, combining the endpoint number and direction.
ID represents a vendor or product ID.