Under Windows 8.1, with LibUsb.getDeviceList(null,connectedDevices)
, I successfully get each and every USB device connected to my PC with the following code :
connectedDevices= new DeviceList();
if(LibUsb.getDeviceList(null,connectedDevices){
selectedDevices= new LinkedList<Device>();
deviceDescriptor= new DeviceDescriptor();
pos=connectedDevices.iterator();
while(pos.hasNext()){
device=pos.next();
if(LibUsb.getDeviceDescriptor(device,deviceDescriptor)==LibUsb.SUCCESS){
selectedDevices.add(device);
LibUsb.refDevice(device);
}
}
}
LibUsb.freeDeviceList(connectedDevices,false);
but when I want to retrieve a string descriptor for a specific device whose "iManufacturer" is not null with :
StringBuffer buffer=new StringBuffer(1000);
device=selectedDevices.getFirst();
LibUsb.getDeviceDescriptor(device, deviceDescriptor);
handle=new DeviceHandle();
if (LibUsb.open(device,handle)==LibUsb.SUCCESS) {
LibUsb.getStringDescriptorAscii(handle,deviceDescriptor.iManufacturer(),buffer);
manufacturerDescription=buffer.toString();
LibUsb.close(handle);
}
I either get the LIBUSB.ERROR_NO_DEVICE
error code in return to the open
function, which I find strange for a device discovered only a few milliseconds before or the LIBSUSB.ERROR_INVALID_PARAM
error code in return to getDescriptor
. And using LibUsb.getStringDescriptor(handle,deviceDescriptor.iManufacturer(),(short)0x409,buffer)
fails as well with the same error code...
With LibUsb.getStringDescriptor(handle,deviceDescriptor...)
, I succeed in getting the string for the manufacturer and the product for two out of seventeen devices which returns a non-null value for iManufacturer
and iProduct
. I thought the reason others weren't retrieved was linked to the 127 bytes limitation but using getStringDescriptorAscii(handle,deviceDesriptor...,buffer)
, with a buffer sized at 1000 bytes, isn't better.
What am I missing?
I think you got the methods wrong. Using
getStringDescriptor
instead should fix it. But I am not aware of a language id 1000. Nevertheless the casting to byte of a short should have been a dead giveaway. ;)