usb

package
Version: v0.0.0-...-38255c2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package usb provides a wrapper around libusb-1.0.

Index

Constants

View Source
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
)
View Source
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

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

Functions

This section is empty.

Types

type BCD

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

func (BCD) Int

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

func (BCD) String

func (d BCD) String() string

type Class

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

func (c Class) String() string

type ConfigInfo

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

func (ConfigInfo) String

func (c ConfigInfo) String() string

type Context

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

func NewContext

func NewContext() *Context

func (*Context) Close

func (c *Context) Close() error

func (*Context) Debug

func (c *Context) Debug(level int)

func (*Context) ListDevices

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

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

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

type DescriptorType uint8

func (DescriptorType) String

func (dt DescriptorType) String() string

type Device

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

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

func (d *Device) Close() error

Close the device.

func (*Device) Control

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

func (*Device) GetStringDescriptor

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

func (*Device) OpenEndpoint

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

func (*Device) Reset

func (d *Device) Reset() error

func (*Device) SetConfig

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

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

type EndpointDirection

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

func (ed EndpointDirection) String() string

type EndpointInfo

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

func (EndpointInfo) Direction

func (e EndpointInfo) Direction() EndpointDirection

func (EndpointInfo) Number

func (e EndpointInfo) Number() int

func (EndpointInfo) String

func (e EndpointInfo) String() string

type ID

type ID uint16

func (ID) String

func (id ID) String() string

type InterfaceInfo

type InterfaceInfo struct {
	Number uint8
	Setups []InterfaceSetup
}

func (InterfaceInfo) String

func (i InterfaceInfo) String() string

type InterfaceSetup

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

func (InterfaceSetup) String

func (a InterfaceSetup) String() string

type IsoSyncType

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

func (ist IsoSyncType) String() string

type IsoUsageType

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

func (iut IsoUsageType) String() string

type RequestType

type RequestType uint8

func (RequestType) String

func (rt RequestType) String() string

type Transfer

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

func (*Transfer) Close

func (t *Transfer) Close() error

func (*Transfer) Submit

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

func (*Transfer) Wait

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

type TransferStatus

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

func (ts TransferStatus) Error() string

func (TransferStatus) String

func (ts TransferStatus) String() string

type TransferType

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

func (tt TransferType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto