Documentation ¶
Overview ¶
Package usb provides a wrapper around libusb-1.0.
Index ¶
- Constants
- Variables
- type BCD
- type Class
- type ConfigInfo
- type Context
- type Descriptor
- type DescriptorType
- type Device
- func (d *Device) ActiveConfig() (uint8, error)
- func (d *Device) Close() error
- func (d *Device) Control(rType, request uint8, val, idx uint16, data []byte) (int, error)
- func (d *Device) GetStringDescriptor(desc_index int) (string, error)
- func (d *Device) OpenEndpoint(conf, iface, setup, epoint uint8) (Endpoint, error)
- func (d *Device) Reset() error
- func (d *Device) SetConfig(cfg uint8) error
- type Endpoint
- type EndpointDirection
- type EndpointInfo
- type ID
- type InterfaceInfo
- type InterfaceSetup
- type IsoSyncType
- type IsoUsageType
- type RequestType
- type Transfer
- type TransferStatus
- type TransferType
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 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 )
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 (*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.
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
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 ¶
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 ¶
ActiveConfig returns the config id (not the index) of the active configuration. This corresponds to the ConfigInfo.Config field.
func (*Device) GetStringDescriptor ¶
func (*Device) OpenEndpoint ¶
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 = 0x03 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 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 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
Click to show internal directories.
Click to hide internal directories.