gousb: github.com/jpoirier/gousb/usb Index | Files

package usb

import "github.com/jpoirier/gousb/usb"

Package usb provides a wrapper around libusb-1.0.

Index

Package Files

config.go constants.go debug.go descriptor.go device.go endpoint.go error.go iso.go kerneldriver_linux.go misc.go usb.go

Constants

const (
    REQUEST_TYPE_STANDARD = C.LIBUSB_REQUEST_TYPE_STANDARD
    REQUEST_TYPE_CLASS    = C.LIBUSB_REQUEST_TYPE_CLASS
    REQUEST_TYPE_VENDOR   = C.LIBUSB_REQUEST_TYPE_VENDOR
    REQUEST_TYPE_RESERVED = C.LIBUSB_REQUEST_TYPE_RESERVED
)
const (
    SUCCESS             usbError = C.LIBUSB_SUCCESS
    ERROR_IO            usbError = C.LIBUSB_ERROR_IO
    ERROR_INVALID_PARAM usbError = C.LIBUSB_ERROR_INVALID_PARAM
    ERROR_ACCESS        usbError = C.LIBUSB_ERROR_ACCESS
    ERROR_NO_DEVICE     usbError = C.LIBUSB_ERROR_NO_DEVICE
    ERROR_NOT_FOUND     usbError = C.LIBUSB_ERROR_NOT_FOUND
    ERROR_BUSY          usbError = C.LIBUSB_ERROR_BUSY
    ERROR_TIMEOUT       usbError = C.LIBUSB_ERROR_TIMEOUT
    ERROR_OVERFLOW      usbError = C.LIBUSB_ERROR_OVERFLOW
    ERROR_PIPE          usbError = C.LIBUSB_ERROR_PIPE
    ERROR_INTERRUPTED   usbError = C.LIBUSB_ERROR_INTERRUPTED
    ERROR_NO_MEM        usbError = C.LIBUSB_ERROR_NO_MEM
    ERROR_NOT_SUPPORTED usbError = C.LIBUSB_ERROR_NOT_SUPPORTED
    ERROR_OTHER         usbError = C.LIBUSB_ERROR_OTHER
)

Variables

var DefaultControlTimeout = 250 * time.Millisecond //5 * time.Second
var DefaultReadTimeout = 1 * time.Second
var DefaultWriteTimeout = 1 * time.Second

type BCD Uses

type BCD uint16
const (
    USB_2_0 BCD = 0x0200
    USB_1_1 BCD = 0x0110
    USB_1_0 BCD = 0x0100
)

func (BCD) Int Uses

func (d BCD) Int() (i int)

func (BCD) String Uses

func (d BCD) String() string

type Class Uses

type Class uint8
const (
    CLASS_PER_INTERFACE Class = C.LIBUSB_CLASS_PER_INTERFACE
    CLASS_AUDIO         Class = C.LIBUSB_CLASS_AUDIO
    CLASS_COMM          Class = C.LIBUSB_CLASS_COMM
    CLASS_HID           Class = C.LIBUSB_CLASS_HID
    CLASS_PRINTER       Class = C.LIBUSB_CLASS_PRINTER
    CLASS_PTP           Class = C.LIBUSB_CLASS_PTP
    CLASS_MASS_STORAGE  Class = C.LIBUSB_CLASS_MASS_STORAGE
    CLASS_HUB           Class = C.LIBUSB_CLASS_HUB
    CLASS_DATA          Class = C.LIBUSB_CLASS_DATA
    CLASS_WIRELESS      Class = C.LIBUSB_CLASS_WIRELESS
    CLASS_APPLICATION   Class = C.LIBUSB_CLASS_APPLICATION
    CLASS_VENDOR_SPEC   Class = C.LIBUSB_CLASS_VENDOR_SPEC
)

func (Class) String Uses

func (c Class) String() string

type ConfigInfo Uses

type ConfigInfo struct {
    Config     uint8
    Attributes uint8
    MaxPower   uint8
    Interfaces []InterfaceInfo
}

func (ConfigInfo) String Uses

func (c ConfigInfo) String() string

type Context Uses

type Context struct {
    // contains filtered or unexported fields
}

func NewContext Uses

func NewContext() *Context

func (*Context) Close Uses

func (c *Context) Close() error

func (*Context) Debug Uses

func (c *Context) Debug(level int)

func (*Context) ListDevices Uses

func (c *Context) ListDevices(each func(desc *Descriptor) bool) ([]*Device, error)

ListDevices calls each with each enumerated device. If the function returns true, the device is opened and a Device is returned if the operation succeeds. Every Device returned (whether an error is also returned or not) must be closed. If there are any errors enumerating the devices, the final one is returned along with any successfully opened devices.

func (*Context) OpenDeviceWithVidPid Uses

func (c *Context) OpenDeviceWithVidPid(vid, pid int) (*Device, error)

OpenDeviceWithVidPid opens Device from specific VendorId and ProductId. If there are any errors, it'll returns at second value.

type Descriptor Uses

type Descriptor struct {
    // Bus information
    Bus     uint8 // The bus on which the device was detected
    Address uint8 // The address of the device on the bus

    // Version information
    Spec   BCD // USB Specification Release Number
    Device BCD // The device version

    // Product information
    Vendor  ID  // The Vendor identifer
    Product ID  // The Product identifier

    // Protocol information
    Class    uint8 // The class of this device
    SubClass uint8 // The sub-class (within the class) of this device
    Protocol uint8 // The protocol (within the sub-class) of this device

    // Configuration information
    Configs []ConfigInfo
}

type DescriptorType Uses

type DescriptorType uint8
const (
    DT_DEVICE    DescriptorType = C.LIBUSB_DT_DEVICE
    DT_CONFIG    DescriptorType = C.LIBUSB_DT_CONFIG
    DT_STRING    DescriptorType = C.LIBUSB_DT_STRING
    DT_INTERFACE DescriptorType = C.LIBUSB_DT_INTERFACE
    DT_ENDPOINT  DescriptorType = C.LIBUSB_DT_ENDPOINT
    DT_HID       DescriptorType = C.LIBUSB_DT_HID
    DT_REPORT    DescriptorType = C.LIBUSB_DT_REPORT
    DT_PHYSICAL  DescriptorType = C.LIBUSB_DT_PHYSICAL
    DT_HUB       DescriptorType = C.LIBUSB_DT_HUB
)

func (DescriptorType) String Uses

func (dt DescriptorType) String() string

type Device Uses

type Device struct {

    // Embed the device information for easy access
    *Descriptor

    // Timeouts
    ReadTimeout    time.Duration
    WriteTimeout   time.Duration
    ControlTimeout time.Duration
    // contains filtered or unexported fields
}

func (*Device) ActiveConfig Uses

func (d *Device) ActiveConfig() (uint8, error)

ActiveConfig returns the config id (not the index) of the active configuration. This corresponds to the ConfigInfo.Config field.

func (*Device) Close Uses

func (d *Device) Close() error

Close the device.

func (*Device) Control Uses

func (d *Device) Control(rType, request uint8, val, idx uint16, data []byte) (int, error)

func (*Device) GetStringDescriptor Uses

func (d *Device) GetStringDescriptor(desc_index int) (string, error)

func (*Device) OpenEndpoint Uses

func (d *Device) OpenEndpoint(conf, iface, setup, epoint uint8) (Endpoint, error)

func (*Device) Reset Uses

func (d *Device) Reset() error

func (*Device) SetConfig Uses

func (d *Device) SetConfig(cfg uint8) error

SetConfig attempts to change the active configuration. The cfg provided is the config id (not the index) of the configuration to set, which corresponds to the ConfigInfo.Config field.

type Endpoint Uses

type Endpoint interface {
    Read(b []byte) (int, error)
    Write(b []byte) (int, error)
    Interface() InterfaceSetup
    Info() EndpointInfo
}

type EndpointDirection Uses

type EndpointDirection uint8
const (
    ENDPOINT_NUM_MASK                   = 0x0f
    ENDPOINT_DIR_IN   EndpointDirection = C.LIBUSB_ENDPOINT_IN
    ENDPOINT_DIR_OUT  EndpointDirection = C.LIBUSB_ENDPOINT_OUT
    ENDPOINT_DIR_MASK EndpointDirection = 0x80
)

func (EndpointDirection) String Uses

func (ed EndpointDirection) String() string

type EndpointInfo Uses

type EndpointInfo struct {
    Address       uint8
    Attributes    uint8
    MaxPacketSize uint16
    MaxIsoPacket  uint32
    PollInterval  uint8
    RefreshRate   uint8
    SynchAddress  uint8
}

func (EndpointInfo) Direction Uses

func (e EndpointInfo) Direction() EndpointDirection

func (EndpointInfo) Number Uses

func (e EndpointInfo) Number() int

func (EndpointInfo) String Uses

func (e EndpointInfo) String() string

type ID Uses

type ID uint16

func (ID) String Uses

func (id ID) String() string

type InterfaceInfo Uses

type InterfaceInfo struct {
    Number uint8
    Setups []InterfaceSetup
}

func (InterfaceInfo) String Uses

func (i InterfaceInfo) String() string

type InterfaceSetup Uses

type InterfaceSetup struct {
    Number     uint8
    Alternate  uint8
    IfClass    uint8
    IfSubClass uint8
    IfProtocol uint8
    Endpoints  []EndpointInfo
}

func (InterfaceSetup) String Uses

func (a InterfaceSetup) String() string

type IsoSyncType Uses

type IsoSyncType uint8
const (
    ISO_SYNC_TYPE_NONE     IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_NONE << 2
    ISO_SYNC_TYPE_ASYNC    IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ASYNC << 2
    ISO_SYNC_TYPE_ADAPTIVE IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ADAPTIVE << 2
    ISO_SYNC_TYPE_SYNC     IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_SYNC << 2
    ISO_SYNC_TYPE_MASK     IsoSyncType = 0x0C
)

func (IsoSyncType) String Uses

func (ist IsoSyncType) String() string

type IsoUsageType Uses

type IsoUsageType uint8
const (
    ISO_USAGE_TYPE_DATA     IsoUsageType = C.LIBUSB_ISO_USAGE_TYPE_DATA << 4
    ISO_USAGE_TYPE_FEEDBACK IsoUsageType = C.LIBUSB_ISO_USAGE_TYPE_FEEDBACK << 4
    ISO_USAGE_TYPE_IMPLICIT IsoUsageType = C.LIBUSB_ISO_USAGE_TYPE_IMPLICIT << 4
    ISO_USAGE_TYPE_MASK     IsoUsageType = 0x30
)

func (IsoUsageType) String Uses

func (iut IsoUsageType) String() string

type RequestType Uses

type RequestType uint8

func (RequestType) String Uses

func (rt RequestType) String() string

type Transfer Uses

type Transfer struct {
    // contains filtered or unexported fields
}

func (*Transfer) Close Uses

func (t *Transfer) Close() error

func (*Transfer) Submit Uses

func (t *Transfer) Submit(timeout time.Duration) error

func (*Transfer) Wait Uses

func (t *Transfer) Wait(b []byte) (n int, err error)

type TransferStatus Uses

type TransferStatus uint8
const (
    LIBUSB_TRANSFER_COMPLETED TransferStatus = C.LIBUSB_TRANSFER_COMPLETED
    LIBUSB_TRANSFER_ERROR     TransferStatus = C.LIBUSB_TRANSFER_ERROR
    LIBUSB_TRANSFER_TIMED_OUT TransferStatus = C.LIBUSB_TRANSFER_TIMED_OUT
    LIBUSB_TRANSFER_CANCELLED TransferStatus = C.LIBUSB_TRANSFER_CANCELLED
    LIBUSB_TRANSFER_STALL     TransferStatus = C.LIBUSB_TRANSFER_STALL
    LIBUSB_TRANSFER_NO_DEVICE TransferStatus = C.LIBUSB_TRANSFER_NO_DEVICE
    LIBUSB_TRANSFER_OVERFLOW  TransferStatus = C.LIBUSB_TRANSFER_OVERFLOW
)

func (TransferStatus) Error Uses

func (ts TransferStatus) Error() string

func (TransferStatus) String Uses

func (ts TransferStatus) String() string

type TransferType Uses

type TransferType uint8
const (
    TRANSFER_TYPE_CONTROL     TransferType = C.LIBUSB_TRANSFER_TYPE_CONTROL
    TRANSFER_TYPE_ISOCHRONOUS TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS
    TRANSFER_TYPE_BULK        TransferType = C.LIBUSB_TRANSFER_TYPE_BULK
    TRANSFER_TYPE_INTERRUPT   TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT
    TRANSFER_TYPE_MASK        TransferType = 0x03
)

func (TransferType) String Uses

func (tt TransferType) String() string

Package usb imports 10 packages (graph) and is imported by 3 packages. Updated 2016-08-30. Refresh now. Tools for package owners.