Hi, I'm trying to read data from device. Code seems work, but I receive a empty data filled with 0. Its no mater if I use hight level API or low. In low level I get ByteBuffer with 0. What am I doing wrong? I'm using Ubuntu Linux 64-bit, and I gave in udev proper rights for user.
My simple code for high level API:
import javax.usb.UsbConfiguration;
import javax.usb.UsbDevice;
import javax.usb.UsbDeviceDescriptor;
import javax.usb.UsbEndpoint;
import javax.usb.UsbHostManager;
import javax.usb.UsbHub;
import javax.usb.UsbInterface;
import javax.usb.UsbInterfacePolicy;
import javax.usb.UsbPipe;
import javax.usb.UsbServices;
import org.usb4java.Device;
import org.usb4java.DeviceHandle;
import org.usb4java.LibUsb;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
System.setProperty("javax.usb.services", "org.usb4java.javax.Services");
UsbServices services = UsbHostManager.getUsbServices();
UsbHub rootHub = services.getRootUsbHub();
UsbDevice device = findDevice( rootHub, (short) 0x10c4, (short) 0xea60);
System.out.println(device.getUsbDeviceDescriptor().toString());
UsbConfiguration configuration = device.getActiveUsbConfiguration();
UsbInterface iface = configuration.getUsbInterface((byte) 0);
System.out.println("iface active " + iface.isActive());
iface.claim(new UsbInterfacePolicy()
{
@Override
public boolean forceClaim(UsbInterface usbInterface)
{
return true;
}
});
try
{
// UsbEndpoint endpoint = iface.getUsbEndpoint((byte) 0x02);
// UsbPipe pipe = endpoint.getUsbPipe();
// pipe.open();
// try
// {
// int sent = pipe.syncSubmit(new byte[] { 65, 66, 67, 68, 69, 70, 71, 72 });
// System.out.println(sent + " bytes sent");
// }
// finally
// {
// pipe.close();
// }
UsbEndpoint endpoint = iface.getUsbEndpoint((byte) 0x01);
UsbPipe pipe = endpoint.getUsbPipe();
pipe.open();
try
{
byte[] data = new byte[8];
int received = pipe.syncSubmit(data);
System.out.println(received + " bytes received " + new String(data));
}
finally
{
pipe.close();
}
}
finally
{
iface.release();
}
}
public static UsbDevice findDevice(UsbHub hub, short vendorId, short productId)
{
for (UsbDevice device : (List<UsbDevice>) hub.getAttachedUsbDevices())
{
UsbDeviceDescriptor desc = device.getUsbDeviceDescriptor();
if (desc.idVendor() == vendorId && desc.idProduct() == productId) return device;
if (device.isUsbHub())
{
device = findDevice((UsbHub) device, vendorId, productId);
if (device != null) return device;
}
}
return null;
}
}
Thank you for advance,
Nikolas.