You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When using the UsbDk, opening the Device within two threads for a short period of time will fail. errorCode : -99 Other error #89
Bug description
When using the UsbDk, opening the Device within two threads for a short period of time will fail. errorCode : -99 Other error.
Reproduction
public class Usb4JavaUseUsbdkIssue {
public static void main(String[] args) throws Exception{
Context context = new Context();
int result = LibUsb.init(context);
if (result != LibUsb.SUCCESS) {
throw new LibUsbException("Unable to initialize libusb", result);
}
// use UsbDk
result = LibUsb.setOption(context, LibUsb.OPTION_USE_USBDK);
if (result != LibUsb.SUCCESS) {
throw new LibUsbException("Unable to use UsbDk", result);
}
DeviceList deviceList = new DeviceList();
int deviceCount = LibUsb.getDeviceList(context, deviceList);
if (deviceCount > 0) {
try {
// Two printer's idVendor and idProduct is same
int idVendor = 0x1fc9;
int idProduct = 0x2016;
Device device1 = null;
Device device2 = null;
for (Device device : deviceList) {
DeviceDescriptor descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result != LibUsb.SUCCESS) {
throw new LibUsbException("Unable to read device descriptor", result);
}
if (device1 == null
&& (descriptor.idVendor() & 0xffff) == idVendor
&& (descriptor.idProduct() & 0xffff) == idProduct) {
device1 = device;
} else if (device2 == null
&& (descriptor.idVendor() & 0xffff) == idVendor
&& (descriptor.idProduct() & 0xffff) == idProduct) {
device2 = device;
}
}
assert device1 != null;
assert device2 != null;
testConcurrentOpen(device1);
testConcurrentOpen(device2);
// wait for completion ...
Thread.sleep(5000);
} catch (Exception e) {
e.printStackTrace();
} finally {
LibUsb.freeDeviceList(deviceList, true);
}
}
}
private static void testConcurrentOpen(final Device device) throws Exception {
Thread thread = new Thread(() -> {
try {
DeviceHandle handle = new DeviceHandle();
// This will fail if use UsbDk, errorCode : -99 Other error
int result = LibUsb.open(device, handle);
if (result != LibUsb.SUCCESS) {
throw new LibUsbException("Unable to open device", result);
}
// do something ...
Thread.sleep(1000);
LibUsb.close(handle);
} catch (Exception e) {
e.printStackTrace();
}
});
thread.setDaemon(true);
thread.start();
}
}
Expected behavior
org.usb4java.LibUsbException: USB error 99: Unable to open device: Other error
at top.torr.topos.hardware.Usb4JavaUseUsbdkIssue$1.run(Usb4JavaUseUsbdkIssue.java:72)
at java.lang.Thread.run(Thread.java:750)
Activity