Files
go-scsupdate/usb.go
2021-12-06 00:21:26 +01:00

55 lines
1.3 KiB
Go

package main
import (
"fmt"
"log"
"github.com/google/gousb"
"github.com/google/gousb/usbid"
)
/*
USB Product IDs of the SCS devices:
0xD010 SCS PTC-IIusb
0xD011 SCS Tracker / DSP TNC
0xD012 SCS P4dragon DR-7800
0xD013 SCS P4dragon DR-7400
0xD014 - not used
0xD015 SCS PTC-IIIusb
0xD016 - not used
0xD017 - not used
*/
func lsusb() {
// Only one context should be needed for an application. It should always be closed.
ctx := gousb.NewContext()
defer ctx.Close()
// OpenDevices is used to find the devices to open.
devs, err := ctx.OpenDevices(func(desc *gousb.DeviceDesc) bool {
// The usbid package can be used to print out human readable information.
fmt.Printf("%03d.%03d %s:%s %s\n", desc.Bus, desc.Address, desc.Vendor, desc.Product, usbid.Describe(desc))
fmt.Printf(" Protocol: %s\n", usbid.Classify(desc))
fmt.Println(desc.Configs)
return false
})
// All Devices returned from OpenDevices must be closed.
defer func() {
for _, d := range devs {
d.Close()
}
}()
// OpenDevices can occasionally fail, so be sure to check its return value.
if err != nil {
log.Fatalf("list: %s", err)
}
for _, dev := range devs {
// Once the device has been selected from OpenDevices, it is opened
// and can be interacted with.
_ = dev
}
}