Git Product home page Git Product logo

Comments (7)

jerbob92 avatar jerbob92 commented on May 4, 2024

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.

jerbob92 avatar jerbob92 commented on May 4, 2024

I managed to get it to work! The trick is to use a smaller buffer, 1024 bytes worked for me.

from gousb.

zagrodzki avatar zagrodzki commented on May 4, 2024

That seems correct, the maximum size of a control transfer in libusb is 4KB (also see libusb/libusb#110).

from gousb.

jerbob92 avatar jerbob92 commented on May 4, 2024

@zagrodzki would you appreciate / accept a pull request that adds functionality to read the PnP identifier?

from gousb.

zagrodzki avatar zagrodzki commented on May 4, 2024

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.

jerbob92 avatar jerbob92 commented on May 4, 2024

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.

zagrodzki avatar zagrodzki commented on May 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.