Documentation
¶
Overview ¶
Package usb is the high-level interface to working with USB devices in pure Go.
Getting Started ¶
The first task is finding your device. You can optionally set a configuration if the device has multiple, but this is rare. Before communicating with the device, you need to claim an interface. Then you may send to the endpoints in that interface.
Example ¶
package main
import (
"fmt"
"github.com/Emposat/usb"
)
func main() {
dev, err := usb.VidPid(0x0c45, 0x6300) // opens the first device it finds with these
if err == usb.ErrDeviceNotFound {
fmt.Println("Not found")
return
}
err = dev.Open()
if err != nil {
fmt.Printf("Error opening device: %v\n", err)
return
}
defer dev.Close()
err = dev.ClaimInterface(1)
if err != nil {
fmt.Printf("Error claiming interface: %v\n", err)
return
}
defer dev.ReleaseInterface(1)
// @todo this is super ugly
dev.ActiveConfig.Interfaces[1].Endpoints[1].CtrlTransfer( /*...*/ )
}
Index ¶
- Variables
- type Configuration
- type Device
- func (d *Device) ClaimInterface(intf int) error
- func (d *Device) Close() error
- func (d *Device) Endpoint(num int) (*Endpoint, error)
- func (d *Device) GetDriver(intf int) (string, error)
- func (d *Device) Interface(i int) (*Interface, error)
- func (d *Device) Open() error
- func (d *Device) ReleaseInterface(intf int) error
- func (d *Device) Reset() error
- func (d *Device) SetConfiguration(cfg int) error
- type Endpoint
- type ID
- type Interface
- type Speed
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrDeviceNotFound = errors.New("Device not found")
)
View Source
var ErrNotImplemented = errors.New("not implemented")
Functions ¶
This section is empty.
Types ¶
type Configuration ¶
type Device ¶
type Device struct {
Bus int
Device int
Port int // @todo: keep this up to date with hotplugs, resets?
Ports []int
Vendor ID
Product ID
Parent *Device
Speed Speed
Configs []Configuration
ActiveConfig *Configuration // can read SYSFSPATH/bConfigurationValue
// contains filtered or unexported fields
}
func List ¶
Example ¶
package main
import (
"fmt"
"github.com/Emposat/usb"
)
func main() {
devices, err := usb.List()
if err != nil {
//handle
}
for _, d := range devices {
fmt.Printf("%04x:%04x - %s, %s\n", d.Vendor.ID, d.Product.ID, d.Vendor.Name(), d.Product.Name())
}
}
func Open ¶
Example ¶
package main
import (
"github.com/Emposat/usb"
)
func main() {
dev, err := usb.Open(1, 3)
if err != nil {
//handle error
}
defer dev.Close()
//do something
}
func (*Device) ClaimInterface ¶
func (*Device) ReleaseInterface ¶
func (*Device) SetConfiguration ¶
type Endpoint ¶
type Endpoint struct {
Address int
TransferType int
MaxPacketSize int
MaxISOPacketSize int
// contains filtered or unexported fields
}
func (*Endpoint) CtrlTransfer ¶
func (e *Endpoint) CtrlTransfer()
type ID ¶
type ID struct {
ID uint16 // ID number, e.g. 0xF00D
// contains filtered or unexported fields
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.