Move to go-serial
This commit is contained in:
9
go.mod
9
go.mod
@@ -2,4 +2,11 @@ module go-scsupdate
|
|||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require github.com/google/gousb v1.1.1
|
require github.com/albenik/go-serial v1.2.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/creack/goselect v0.1.0 // indirect
|
||||||
|
go.uber.org/atomic v1.4.0 // indirect
|
||||||
|
go.uber.org/multierr v1.1.0 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect
|
||||||
|
)
|
||||||
|
20
go.sum
20
go.sum
@@ -1,2 +1,18 @@
|
|||||||
github.com/google/gousb v1.1.1 h1:2sjwXlc0PIBgDnXtNxUrHcD/RRFOmAtRq4QgnFBE6xc=
|
github.com/albenik/go-serial v1.2.0 h1:VhEIWqP5tbWtsWoCjeBHHQEf6qeXpsJXvZBP9px5F84=
|
||||||
github.com/google/gousb v1.1.1/go.mod h1:b3uU8itc6dHElt063KJobuVtcKHWEfFOysOqBNzHhLY=
|
github.com/albenik/go-serial v1.2.0/go.mod h1:9NHUOwCBJER+lAaitTWLJda/GnYoP4Vga7KU3vn1lmM=
|
||||||
|
github.com/creack/goselect v0.1.0 h1:4QiXIhcpSQF50XGaBsFzesjwX/1qOY5bOveQPmN9CXY=
|
||||||
|
github.com/creack/goselect v0.1.0/go.mod h1:gHrIcH/9UZDn2qgeTUeW5K9eZsVYCH6/60J/FHysWyE=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
|
||||||
|
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||||
|
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
|
||||||
|
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||||
|
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI=
|
||||||
|
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
43
usb.go
43
usb.go
@@ -4,8 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/google/gousb"
|
"github.com/albenik/go-serial/enumerator"
|
||||||
"github.com/google/gousb/usbid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -21,34 +20,20 @@ import (
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
func lsusb() {
|
func lsusb() {
|
||||||
// Only one context should be needed for an application. It should always be closed.
|
ports, err := enumerator.GetDetailedPortsList()
|
||||||
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 {
|
if err != nil {
|
||||||
log.Fatalf("list: %s", err)
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(ports) == 0 {
|
||||||
|
fmt.Println("No serial ports found!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, port := range ports {
|
||||||
|
fmt.Printf("Found port: %s\n", port.Name)
|
||||||
|
if port.IsUSB {
|
||||||
|
fmt.Printf(" USB ID %s:%s\n", port.VID, port.PID)
|
||||||
|
fmt.Printf(" USB serial %s\n", port.SerialNumber)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, dev := range devs {
|
|
||||||
// Once the device has been selected from OpenDevices, it is opened
|
|
||||||
// and can be interacted with.
|
|
||||||
_ = dev
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user