t-oster / LibLaserCut

a platform independant library to control Lasercutters. This is the base library for VisiCut
http://visicut.org
Other
59 stars 55 forks source link

K40NanoDriver: LibUsbException: USB error 6: Could not claim the interface.: Resource busy #172

Open mgmax opened 2 years ago

mgmax commented 2 years ago

Discussed in https://github.com/t-oster/VisiCut/discussions/605

Originally posted by **papapingouin-be** April 21, 2021 Hello, I use visicut with my K40 lasercutter on a raspberry pi3b from 1year and all is ok but after updates i have this message and i can't rollback ... pi@raspberrypi:~ $ visicut openjdk version "11.0.9.1" 2020-11-04 ... org.usb4java.LibUsbException: USB error 6: Could not claim the interface.: Resource busy at de.thomas_oster.liblasercut.drivers.K40NanoDriver$K40Usb.claimInterface(K40NanoDriver.java:1762) at de.thomas_oster.liblasercut.drivers.K40NanoDriver$K40Usb.open(K40NanoDriver.java:1433) at de.thomas_oster.liblasercut.drivers.K40NanoDriver$K40Queue.open(K40NanoDriver.java:1272) at de.thomas_oster.liblasercut.drivers.K40NanoDriver$K40Device.open(K40NanoDriver.java:469) at de.thomas_oster.liblasercut.drivers.K40NanoDriver$K40Device.open(K40NanoDriver.java:463) at de.thomas_oster.liblasercut.drivers.K40NanoDriver.sendJob(K40NanoDriver.java:109) at de.thomas_oster.visicut.VisicutModel.sendJob(VisicutModel.java:778) at de.thomas_oster.visicut.gui.MainView.lambda$executeOrSaveJob$7(MainView.java:2209) at java.base/java.lang.Thread.run(Thread.java:834) org.usb4java.LibUsbException: USB error 6: Could not claim the interface.: Resource busy at de.thomas_oster.liblasercut.drivers.K40NanoDriver$K40Usb.claimInterface(K40NanoDriver.java:1762) at de.thomas_oster.liblasercut.drivers.K40NanoDriver$K40Usb.open(K40NanoDriver.java:1433) at de.thomas_oster.liblasercut.drivers.K40NanoDriver$K40Queue.open(K40NanoDriver.java:1272) at de.thomas_oster.liblasercut.drivers.K40NanoDriver$K40Device.open(K40NanoDriver.java:469) at de.thomas_oster.liblasercut.drivers.K40NanoDriver$K40Device.open(K40NanoDriver.java:463) at de.thomas_oster.liblasercut.drivers.K40NanoDriver.sendJob(K40NanoDriver.java:109) at de.thomas_oster.visicut.VisicutModel.sendJob(VisicutModel.java:778) at de.thomas_oster.visicut.gui.MainView.lambda$executeOrSaveJob$7(MainView.java:2209) at java.base/java.lang.Thread.run(Thread.java:834) root@raspberrypi:/home/pi# lsusb Bus 001 Device 004: ID 1a86:5512 QinHeng Electronics CH341 in EPP/MEM/I2C mode, EPP/I2C adapter Bus 001 Device 005: ID 0424:7800 Standard Microsystems Corp. Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Thanks for your help Laurent
mgmax commented 2 years ago

As discussed here https://github.com/t-oster/VisiCut/discussions/605#discussioncomment-643395 , the error disappears if K40Whisperer is started (and probably closed again) before using VisiCut.

So the problem is that VisiCut does not detach the USB driver of the CH341 device. Probable solution is something like "int r = LibUsb.detachKernelDriver(handle, interfaceNum); " somewhere near claimInterface in https://github.com/t-oster/LibLaserCut/blob/master/src/main/java/de/thomas_oster/liblasercut/drivers/K40NanoDriver.java

@tatarize Could you maybe have a look? Or someone else who has access to such a lasercutter?

tatarize commented 2 years ago

Okay, cloned a fresh repo. Ran it.

LibUsbException: USB error 3: Could not claim the interface: Access denied (insufficient permissions)

Trying again, running netbeans as Administrator. Apparently not good enough I need to run Visicut directly as administrator.

-- Loading files suddenly broke.


In Raspberry pi, I believe there might be an issue with the order of operations a deep dive by a contributor in the MeerK40t project had the order there shifted a bit. As for windows I might have to figure out he proper method for DLL calls (to code a secondary default windows driver using the CH341DLL) because the need to run in admin mode is really really annoying.

tatarize commented 2 years ago

Attempted again, after uninstalling and reinstalling viscut. Gave another insufficient permission error, even from root.

I ran it successfully during testing. Not sure if anything changed or if it's just being weird.


Orderwise:


For some linux installs:

Depending on things it might need the rule to permit you to access the K40. You can test this if it works with sudo visicut and works.

mgmax commented 2 years ago

It sounds like the "access denied" is a separate issue that will also affect any other lasercutting program (as far as it uses libusb). Also discussed in https://stackoverflow.com/questions/28884817/usb4java-library-error-while-claiming-an-interface

Regarding "Loading files suddenly broke": Opening SVG files works for me, so can you please create an issue with more details (which file, which OS)?

tatarize commented 2 years ago

Even with windows being weird raspberry pi should work, but sometimes the permission error is actually a permission error and the OS doesn't have access. If sudo fixes it, then it's actually permission.

My error recovered after reinstall. I think it was an old config file or something and didn't give me a highly specific error.


The access thing is a bit weird. Python code doesn't have that requirement. If I could call a little python script I could run this stuff without hitting any permissions issues. Though rPi would still need a rule (or sudo) to access the USB, as posted above. But, windows is fine with access without any USB snafus, for Python but not for Java.

I could add in lhyserver devices, where they accept TCP data and just send it over the USB to the device. Though this might be a somewhat rare construction. And it seems like it would need to be compiled or run in a venv or stored in the drivers or stored as a frozen .exe (which is even less desirable).

The network capabilities are desirable enough. Rig up a raspberry pi zero and control the M2 Nano by just TCP sending data to that server. Though asking that folks use a second program to get the first program to work isn't very helpful.