Comments (6)
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.
See https://godoc.org/github.com/google/gousb#Device.SetAutoDetach
from gousb.
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.
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.
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.
Resolved by PR #6
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
- 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 6
- Status of the tag v2.1.0 HOT 1
- Error claiming interface HOT 5
- 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.