This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
first_steps:start [2015/05/27 16:13] – created akalberer | first_steps:start [2016/07/12 10:37] (current) – akalberer | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== First Steps with LibusbJava ====== | ====== First Steps with LibusbJava ====== | ||
+ | |||
+ | <box 35% red right | **Important note for Windows**> | ||
+ | * getDeviceList() of libusb and Device.search() of LibusbJava return the first device with the corresponding VID, PID. In Windows a composite device is represented by multiple devices with the same VID, PID, so you will have to search for the one you want to use (see [[http:// | ||
+ | </ | ||
+ | |||
The following short example will show you how to use LibusbJava in your Java-Project. | The following short example will show you how to use LibusbJava in your Java-Project. | ||
The following code describes the required steps to do a bulk transfer to your device. | The following code describes the required steps to do a bulk transfer to your device. | ||
Line 14: | Line 19: | ||
Device usbDev = null; | Device usbDev = null; | ||
try { | try { | ||
- | useCtx = new Context(); | + | useCtx = new Context(); |
} catch (LibusbException e) { | } catch (LibusbException e) { | ||
System.out.println(" | System.out.println(" | ||
Line 33: | Line 38: | ||
try { | try { | ||
usbDev.open(); | usbDev.open(); | ||
- | usbDev.claimInterface(0); | + | usbDev.claimInterface(0); |
byte[] data = {(byte)0x40, | byte[] data = {(byte)0x40, | ||
- | int res = usbDev.bulkTransfer(2, | + | int res = usbDev.bulkTransfer(2, |
if(res == data.length){ | if(res == data.length){ | ||
System.out.println(" | System.out.println(" | ||
Line 44: | Line 49: | ||
usbDev.reset(); | usbDev.reset(); | ||
res = 0; | res = 0; | ||
- | res = usbDev.bulkTransfer(2, | + | res = usbDev.bulkTransfer(2, |
if(res == data.length){ | if(res == data.length){ | ||
System.out.println(" | System.out.println(" | ||
Line 51: | Line 56: | ||
System.out.println(" | System.out.println(" | ||
} | } | ||
- | usbDev.releaseInterface(0); | + | usbDev.releaseInterface(0); |
usbDev.close(); | usbDev.close(); | ||
System.out.println(" | System.out.println(" |