Comments (2)
So the answer is:
package main
import (
"fmt"
"github.com/google/gousb"
)
func main() {
ctx := gousb.NewContext()
defer ctx.Close()
devices, err := ctx.OpenDevices(func(desc *gousb.DeviceDesc) bool {
for _, config := range desc.Configs {
for _, inter := range config.Interfaces {
for _, setting := range inter.AltSettings {
// Check if the interface class of USB is `Printer`
if setting.Class == gousb.ClassPrinter {
return true
}
}
}
}
return false
})
if err != nil {
panic(err)
}
// Check if printers exists
if len(devices) == 0 {
fmt.Println("No Printer Found!")
return
}
fmt.Println("Printers: ")
for _, device := range devices {
name, _ := device.Product()
vid := device.Desc.Vendor
pid := device.Desc.Product
port := device.Desc.Port
fmt.Println(name, vid, pid, port)
}
}
Output:
❯ go run .
Printers:
USB Printing Support 0483 070b 2
Finally!
from gousb.
This is as expected (presumably). In the Go code you're looking at the class of the device (Class
field in https://pkg.go.dev/github.com/google/gousb#DeviceDesc). "per-interface" means that different interfaces of this device have different classes. See the description of class 00h
in https://www.usb.org/defined-class-codes#anchor_BaseClass00h
What you're looking at in the lsusb
output is the interface class of a particular setting of a particular interface on that USB device, which would be reflected in the Class
field of https://pkg.go.dev/github.com/google/gousb#InterfaceSetting (that's a different type). See the intro to devices, configurations and interfaces in https://pkg.go.dev/github.com/google/gousb#hdr-A_Short_Tutorial.
from gousb.
Related Issues (20)
- Clear installation of Gosub on the Windows 10 - using msys64 HOT 3
- Latest package not picked up by go get HOT 9
- I can't open hp printer device with gousb HOT 7
- why connect printer return code -5? HOT 1
- Linux: How to get block devices list provided by usb stick? HOT 1
- WinUSB drivers HOT 3
- libusb: bad access [code -3] HOT 8
- Windows: go build github.com/google/gousb: C:\Program Files\Go\pkg\tool\windows_amd64\cgo.exe: exit status 2 HOT 1
- Can't detach kernel driver. Invalid param [code -2] for iOS 16 devices HOT 5
- How to use in a Docker container without --privileged HOT 1
- CDC device HOT 5
- A lot of interrupted errors on MacOSX: handle_events: error: libusb: interrupted [code -10] HOT 8
- Failed to claim interface 0 HOT 1
- Errors on install; macos HOT 3
- Error when WriteContext is called HOT 10
- Device detach: libusb: error [darwin_claim_interface] USBInterfaceOpen: another process has device opened for exclusive access HOT 3
- Memory Leak in CGO part HOT 1
- Memory Leak HOT 4
- Android Support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gousb.