Code Monkey home page Code Monkey logo

Comments (6)

nicovell3 avatar nicovell3 commented on August 15, 2024 3

Hi zagrodzki. I have already tried that function and I was calling it. I'm attaching part of my code:

// Pick the first device found.
dev := devs[0]
err = dev.SetAutoDetach(true)
if err != nil {
    log.Fatalf("%s.SetAutoDetach(true): %v", dev, err)
}

//dev.DetachKernelDriver()
//defer dev.AttachKernelDriver()

//Need to call libusb_detach_kernel_driver first
// Switch the configuration to #1.
cfg, err := dev.Config(1)

And when I run the dev.Config(1) line, it breaks with the error I mentioned, libusb: device or resource busy [code -6].

By now, I've already ported the kernel_driver code from jpoirier to this library and when I uncomment the dev.DetachKernelDriver(), my application works perfectly. Could this code be added to the repository, please? In that case, I could make the pull request...

from gousb.

zagrodzki avatar zagrodzki commented on August 15, 2024

See https://godoc.org/github.com/google/gousb#Device.SetAutoDetach

from gousb.

zagrodzki avatar zagrodzki commented on August 15, 2024

I see. I checked libusb and it seems like detach is called only when an interface is claimed, which doesn't occur when you switch the config. I would like to think this is a bug in libusb that we could fix. Let me see what I can find there.

Although, TBH, looking at the libusb code, I could find more issues with the detachment code there.

In the meantime - I don't think we really need to introduce a new interface. How about we call libusb detach on Config() if autodetach is set? That would actually make auto detach behavior correct for gousb, without modifying the user-visible surface.

Looking at the libusb code, handle->auto_detach_kernel_driver is used only in op_claim_interface and op_release_interface. That suggests we could skip the libusb_set_auto_detach_kernel_driver entirely in gousb, and instead just call attach/detach manually on config claim if autodetach is set.
As an added bonus, that would actually allow us whether reattach is needed or not, based on the result of detach call. And it would avoid the weird interaction where releasing an interface results in reattaching the kernel driver when you switch configurations.

Does that sound ok for your use case? Can you structure your changes around the internals of gousb's SetAutoDetach?

from gousb.

zagrodzki avatar zagrodzki commented on August 15, 2024

My reading of http://comments.gmane.org/gmane.comp.lib.libusb.devel.general/21876 is that the dev team is aware of the problem, but there are no plans to change the behavior. Manually detaching the driver on config change seems like the best option, I think.

from gousb.

nicovell3 avatar nicovell3 commented on August 15, 2024

This is my first time developing with the libusb interface, but I'll try to do my best. I'll make a pull request soon structuring my changes around the internals of gousb.

from gousb.

zagrodzki avatar zagrodzki commented on August 15, 2024

Resolved by PR #6

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.