Comments (7)
This is what I tried:
data := make([]byte, 5000)
n, err := usbdevice.Control(gousb.ControlClass | gousb.ControlIn | gousb.ControlInterface, 0, uint16(usbconfig.Desc.Number), (uint16(usbinterface.Setting.Number)<< 8) | uint16(usbinterface.Setting.Alternate), data)
Sadly, this results in libusb: invalid param [code -2]
from gousb.
I managed to get it to work! The trick is to use a smaller buffer, 1024 bytes worked for me.
from gousb.
That seems correct, the maximum size of a control transfer in libusb is 4KB (also see libusb/libusb#110).
from gousb.
@zagrodzki would you appreciate / accept a pull request that adds functionality to read the PnP identifier?
from gousb.
Hm. Maybe. I'm not sure, we don't have a good place to fit something like this right now. I would imagine it could be useful to have class-specific types that could be used to represent any of the common operations on a given class. So perhaps something like ".../gousb/printer" package with a wrapper that would take a *gousb.Configuration and return a Printer type with methods that make sense for a printer... If you feel like taking on the work, and spending time with me to figure out how that should all be organized, then feel free to start a PR. Fair warning - it's going to take some work, it'll be more than adding a simple function with the code you've listed above. I'm going to ask for tests, and perhaps it will require some additions in the core gousb to work nicely with interfaces you'd need for tests...
from gousb.
Sounds fair. I didn't really dig that deep into USB yet, so I didn't realize those control transfers are different per class. Right now I added it as method on the Interface struct (https://github.com/jerbob92/gousb/tree/feature/1284-pnp-string), but should be added in a class specific package indeed. I'm willing to put some time into this, but only for the printer class. Someplace we could chat about this?
from gousb.
For starters, read through http://www.usb.org/developers/docs/devclass_docs/usbprint11a021811.pdf (this describes all features of the printer class). Specifically section 4.2 lists the control requests. Section 5.3 shows interface descriptor that is expected of a printer class (this maps to gousb.Interface in a particular device configuration).
My first idea was something like that:
type Printer struct {
*gousb.Device
}
// these will send control interfaces
func (Printer) DeviceId() (string, error) ...
func (Printer) PortStatus() (PortStatus, error) ...
func (Printer) SoftReset() error
func Open(dev *gousb.Device) (*Printer, error)
Things I don't like about it already: printers in theory may have multiple configurations (gousb.Config) and each configuration might have multiple interfaces. Of these the first interface must be the data interface, other interfaces are unspecified. The first interface may have multiple alternates. Presumably, users should have a way of selecting different configurations, so maybe Printer should be built around gousb.gousb.Interface instead? But Control() works on a gousb.Device, even if the control request is for a particular interface. Maybe Interface should re-export Control() from Config.dev and allow non-device control requests. Also the printer interface should have different modes for different alternates (each alternate will specify a particular type - unidir, bidir, ieee 1284.4 bidir) and that should be presented to the user in some nice way. Depending on the type of the interface, In() and Out() should open the right endpoint, since endpoints are defined by the printer class.
Start with a PR with something and then we can discuss on the review thread.
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 5
- why connect printer return code -5? HOT 1
- Linux: How to get block devices list provided by usb stick? HOT 1
- incorrect device class HOT 2
- 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
- Cannot claim interface even when there are no other apps are using the device HOT 2
- Status of the tag v2.1.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.