- constants moved to TestImplementation.java

- set the default values according to this constants

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@156 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
schlaepfer
2006-08-09 13:49:28 +00:00
parent be8cedc232
commit 059df21ceb
3 changed files with 142 additions and 419 deletions

View File

@@ -14,7 +14,7 @@ import org.eclipse.swt.widgets.Text;
public class TestGUI {
private static final int HEX_WIDTH = 5;
private Shell rootShell = null; // @jve:decl-index=0:visual-constraint="10,10"
private Shell rootShell = null; // @jve:decl-index=0:visual-constraint="10,10"
private Group vendorIDGroup = null;
private Text vendorID = null;
private Group productIDGroup = null;
@@ -45,28 +45,28 @@ public class TestGUI {
private Group dataFieldGoup = null;
private Text dataField = null;
private Button resetButton = null;
/**
* This method initializes sShell
*/
private int parseInt(String s){
if (s == "") return 0;
private int parseInt(String s) {
if (s == "")
return 0;
if (s.indexOf('x') > 0) {
// is hex number
if (s.length() <= 2){ // exception for "0x"
if (s.length() <= 2) { // exception for "0x"
return 0;
}
return Integer.parseInt(s.substring(s.indexOf('x') + 1, s.length()), 16);
return Integer.parseInt(
s.substring(s.indexOf('x') + 1, s.length()), 16);
} else {
// is decimal number
return Integer.parseInt(s);
}
}
private byte[] parseByteArray(String s){
private byte[] parseByteArray(String s) {
StringBuffer sb = new StringBuffer();
int stringIndex = 0, spaceIndex = 0;
String ss;
while (stringIndex + 3 < s.length()){
while (stringIndex + 3 < s.length()) {
ss = s.substring(spaceIndex, spaceIndex + 4);
spaceIndex = s.indexOf(' ', stringIndex) + 1;
sb.append((char) parseInt(ss));
@@ -74,7 +74,7 @@ public class TestGUI {
}
return sb.toString().getBytes();
}
private void createSShell() {
RowLayout rowLayout = new RowLayout();
rowLayout.type = org.eclipse.swt.SWT.VERTICAL;
@@ -85,99 +85,113 @@ public class TestGUI {
rootShell.setLayout(rowLayout);
createDeviceGroup();
createDataGroup();
rootShell.setSize(new org.eclipse.swt.graphics.Point(466,315));
rootShell.setSize(new org.eclipse.swt.graphics.Point(466, 315));
}
/**
* This method initializes vendorIDGroup
*
* This method initializes vendorIDGroup
*
*/
private void createVendorIDGroup() {
vendorIDGroup = new Group(deviceGroup2, SWT.NONE);
vendorIDGroup.setText("VendorID");
vendorID = new Text(vendorIDGroup, SWT.BORDER | SWT.RIGHT);
vendorID.setBounds(new org.eclipse.swt.graphics.Rectangle(7,23,76,19));
vendorID.setText("0x8235");
vendorID
.setBounds(new org.eclipse.swt.graphics.Rectangle(7, 23, 76, 19));
vendorID.setText("0x"
+ Integer.toHexString(TestImplementation.IdVendor & 0xffff));
TestImplementation.IdVendor = (short) parseInt(vendorID.getText());
vendorID.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
TestImplementation.IdVendor = (short) parseInt(vendorID.getText());
TestImplementation.IdVendor = (short) parseInt(vendorID
.getText());
}
});
}
/**
* This method initializes productIDGroup
*
* This method initializes productIDGroup
*
*/
private void createProductIDGroup() {
productIDGroup = new Group(deviceGroup2, SWT.NONE);
productIDGroup.setText("ProductID");
productID = new Text(productIDGroup, SWT.BORDER | SWT.RIGHT);
productID.setBounds(new org.eclipse.swt.graphics.Rectangle(4,24,76,19));
productID.setText("0x0100");
TestImplementation.IdProduct = (short) parseInt(productID.getText());
productID.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
TestImplementation.IdProduct = (short) parseInt(productID.getText());
}
});
productID.setBounds(new org.eclipse.swt.graphics.Rectangle(4, 24, 76,
19));
productID.setText("0x"
+ Integer.toHexString(TestImplementation.IdProduct & 0xffff));
TestImplementation.IdProduct = (short) parseInt(productID.getText());
productID
.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
TestImplementation.IdProduct = (short) parseInt(productID
.getText());
}
});
}
/**
* This method initializes group
*
* This method initializes group
*
*/
private void createGroup() {
configGroup = new Group(deviceGroup2, SWT.NONE);
configGroup.setText("Configuration");
configuration = new Text(configGroup, SWT.BORDER | SWT.RIGHT);
configuration.setBounds(new org.eclipse.swt.graphics.Rectangle(4,24,75,19));
configuration.setText("1");
configuration.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
TestImplementation.CONFIGURATION = parseInt(configuration.getText());
}
});
configuration.setBounds(new org.eclipse.swt.graphics.Rectangle(4, 24,
75, 19));
configuration.setText(Integer
.toString(TestImplementation.CONFIGURATION));
configuration
.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
TestImplementation.CONFIGURATION = parseInt(configuration
.getText());
}
});
}
/**
* This method initializes group
*
* This method initializes group
*
*/
private void createGroup2() {
interfaceGroup = new Group(deviceGroup2, SWT.NONE);
interfaceGroup.setText("Interface");
interface_ = new Text(interfaceGroup, SWT.BORDER | SWT.RIGHT);
interface_.setBounds(new org.eclipse.swt.graphics.Rectangle(4,24,57,19));
interface_.setText("0");
interface_.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
TestImplementation.INTERFACE = parseInt(interface_.getText());
}
});
interface_.setBounds(new org.eclipse.swt.graphics.Rectangle(4, 24, 57,
19));
interface_.setText(Integer.toString(TestImplementation.INTERFACE));
interface_
.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
TestImplementation.INTERFACE = parseInt(interface_
.getText());
}
});
}
/**
* This method initializes group
*
* This method initializes group
*
*/
private void createGroup3() {
altIntGroup = new Group(deviceGroup2, SWT.NONE);
altIntGroup.setText("Alternative Int");
altInt = new Text(altIntGroup, SWT.BORDER | SWT.RIGHT);
altInt.setBounds(new Rectangle(4, 24, 76, 19));
altInt.setText("0");
altInt.setText(Integer.toString(TestImplementation.ALTINTERFACE));
altInt.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
TestImplementation.ALTINTERFACE = parseInt(altInt.getText());
TestImplementation.ALTINTERFACE = parseInt(altInt.getText());
}
});
}
/**
* This method initializes deviceGroup
*
* This method initializes deviceGroup
*
*/
private void createDeviceGroup() {
RowLayout rowLayout1 = new RowLayout();
@@ -191,8 +205,8 @@ public class TestGUI {
}
/**
* This method initializes endpointGroup
*
* This method initializes endpointGroup
*
*/
private void createEndpointGroup() {
endpointGroup = new Group(devComp, SWT.NONE);
@@ -203,8 +217,8 @@ public class TestGUI {
}
/**
* This method initializes deviceGroup2
*
* This method initializes deviceGroup2
*
*/
private void createDeviceGroup2() {
deviceGroup2 = new Group(deviceGroup, SWT.NONE);
@@ -217,59 +231,62 @@ public class TestGUI {
}
/**
* This method initializes group
*
* This method initializes group
*
*/
private void createGroup4() {
outEPGroup = new Group(endpointGroup, SWT.NONE);
outEPGroup.setText("OUT EP");
outEP = new Text(outEPGroup, SWT.BORDER | SWT.RIGHT);
outEP.setBounds(new org.eclipse.swt.graphics.Rectangle(4,24,46,19));
outEP.setText("0x02");
outEP.setBounds(new org.eclipse.swt.graphics.Rectangle(4, 24, 46, 19));
outEP.setText("0x"
+ Integer.toHexString(TestImplementation.OUT_ENDPOINT));
outEP.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
TestImplementation.OUT_ENDPOINT = parseInt(outEP.getText());
TestImplementation.OUT_ENDPOINT = parseInt(outEP.getText());
}
});
}
/**
* This method initializes group
*
* This method initializes group
*
*/
private void createGroup5() {
inEPGroup = new Group(endpointGroup, SWT.NONE);
inEPGroup.setText("IN EP");
inEP = new Text(inEPGroup, SWT.BORDER | SWT.RIGHT);
inEP.setBounds(new org.eclipse.swt.graphics.Rectangle(4,24,46,19));
inEP.setText("0x86");
inEP.setBounds(new org.eclipse.swt.graphics.Rectangle(4, 24, 46, 19));
inEP
.setText("0x"
+ Integer.toHexString(TestImplementation.IN_ENDPOINT));
inEP.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
TestImplementation.IN_ENDPOINT = parseInt(inEP.getText());
TestImplementation.IN_ENDPOINT = parseInt(inEP.getText());
}
});
}
/**
* This method initializes group
*
* This method initializes group
*
*/
private void createGroup6() {
timeoutGroup = new Group(endpointGroup, SWT.NONE);
timeoutGroup.setText("Timeout");
timeout = new Text(timeoutGroup, SWT.BORDER | SWT.RIGHT);
timeout.setBounds(new Rectangle(4, 24, 46, 19));
timeout.setText("2000");
timeout.setText(Integer.toString(TestImplementation.TIMEOUT));
timeout.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
TestImplementation.TIMEOUT = parseInt(timeout.getText());
TestImplementation.TIMEOUT = parseInt(timeout.getText());
}
});
}
/**
* This method initializes dataGroup
*
* This method initializes dataGroup
*
*/
private void createDataGroup() {
RowLayout rowLayout5 = new RowLayout();
@@ -283,8 +300,8 @@ public class TestGUI {
}
/**
* This method initializes buttonComp
*
* This method initializes buttonComp
*
*/
private void createButtonComp() {
RowLayout rowLayout3 = new RowLayout();
@@ -294,25 +311,31 @@ public class TestGUI {
dataButtonComp = new Composite(dataGroup, SWT.NONE);
sendButton = new Button(dataButtonComp, SWT.NONE);
sendButton.setText("Send");
sendButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
byte[] b = parseByteArray(dataField.getText());
TestImplementation.write(b, b.length);
}
});
sendButton
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
@Override
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
byte[] b = parseByteArray(dataField.getText());
TestImplementation.write(b, b.length);
}
});
recButton = new Button(dataButtonComp, SWT.NONE);
dataButtonComp.setLayout(rowLayout3);
recButton.setText("Receive");
recButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
TestImplementation.read();
}
});
recButton
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
@Override
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
TestImplementation.read();
}
});
}
/**
* This method initializes devComp
*
* This method initializes devComp
*
*/
private void createDevComp() {
RowLayout rowLayout4 = new RowLayout();
@@ -325,8 +348,8 @@ public class TestGUI {
}
/**
* This method initializes devButtonComp
*
* This method initializes devButtonComp
*
*/
private void createDevButtonComp() {
RowLayout rowLayout2 = new RowLayout();
@@ -338,7 +361,9 @@ public class TestGUI {
devOpenButton.setText("Open Device");
devOpenButton
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
@Override
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
TestImplementation.openUsbDevice();
}
});
@@ -346,22 +371,27 @@ public class TestGUI {
devCloseButton.setText("Close Device");
resetButton = new Button(devButtonComp, SWT.NONE);
resetButton.setText("Reset");
resetButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
TestImplementation.resetUsbDevice();
}
});
resetButton
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
@Override
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
TestImplementation.resetUsbDevice();
}
});
devCloseButton
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
@Override
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
TestImplementation.closeUsbDevice();
}
});
}
/**
* This method initializes dataFieldGoup
*
* This method initializes dataFieldGoup
*
*/
private void createDataFieldGoup() {
RowData rowData = new org.eclipse.swt.layout.RowData();
@@ -374,20 +404,19 @@ public class TestGUI {
dataFieldGoup.setText("Data to send [hex]");
dataFieldGoup.setLayout(rowLayout6);
dataField = new Text(dataFieldGoup, SWT.BORDER);
// 33 5B 02 01 00 05 01 03 07 0F 7F 1F
dataField.setText("0x5B 0x02 0x01 0x00 0x05 0x01 0x03 0x07 0x0F 0x7F 0x1F");
dataField.setText(TestImplementation.sendData);
dataField.setLayoutData(rowData);
}
public static void main(String[] args) {
TestGUI app = new TestGUI();
app.createSShell();
app.rootShell.open();
Display display = app.rootShell.getDisplay();
while (!app.rootShell.isDisposed()) {
if(!display.readAndDispatch()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}

View File

@@ -6,32 +6,29 @@ import java.util.logging.Logger;
import ch.ntb.usb.Device;
import ch.ntb.usb.USB;
import ch.ntb.usb.USBException;
import ch.ntb.usb.Usb_Bus;
import ch.ntb.usb.logger.LogUtil;
public class TestImplementation {
private static Logger logger = LogUtil.ch_ntb_usb_test;
static Usb_Bus bus;
public static String sendData = "0x5b 0x02 0x01 0x00 0x03 0x03 0xf0 0xf0 0x1f";
static int usb_dev_handle = 0;
public static short IdVendor = (short) 0x8235;
static short IdVendor = 0x04B4;
public static short IdProduct = 0x0200;
static short IdProduct = (short) 0x1004;
public static int TIMEOUT = 2000;
static int TIMEOUT = 1000;
public static int CONFIGURATION = 1;
static int CONFIGURATION = 1;
public static int INTERFACE = 0;
static int INTERFACE = 0;
public static int ALTINTERFACE = 0;
static int ALTINTERFACE = 0;
public static int OUT_ENDPOINT = 0x01;
static int OUT_ENDPOINT = 0x02;
static int IN_ENDPOINT = 0x86;
public static int IN_ENDPOINT = 0x82;
private static Device dev = null;

View File

@@ -1,303 +0,0 @@
package ch.ntb.usb.test;
import java.io.IOException;
import ch.ntb.usb.*;
public class TestUsb_old {
static Usb_Bus bus;
static final short EZ_USB_DevKit_idVendor = 0x04B4;
static final short EZ_USB_DevKit_idProduct = (short) 0x1004; // 0x8613;
static final int TIMEOUT = 3000;
static final int CONFIGURATION = 1;
static final int INTERFACE = 0;
static final int ALTINTERFACE = 0; // 1;
static final int OUT_ENDPOINT = 0x02; // 0x04;
static final int IN_ENDPOINT = 0x86; // 0x88;
static final int MAX_BYTEARRAY_SIZE = 512;
static final int PACKET_HEADER_1 = 0x33; // first byte of header
static final int PACKET_HEADER_2 = 0x5B; // second byte of header
static final int PACKET_END = 0x1F; // last byte of packet
static final int PACKET_DATA_OFFSET = 6; // offset to the first byte of
// data
static final int PACKET_MIN_LENGTH = 7; // minimal Length of a packet (no
// payload)
// Main Types
static final int MTYPE_ERROR = 0x01; // Errors before dispatching data
static final int MTYPE_BDI = 0x02;
static final int MTYPE_UART_1 = 0x03;
// Sub Types
// ERRORS
static final int STYPE_ERROR_HEADER = 0x01; // Header of packet wrong
static final int STYPE_ERROR_PACKET_END = 0x02; // Packet end wrong
// BDI
static final int STYPE_BDI_35IN = 0x01; // 35 Bit Packet to BDI
static final int STYPE_BDI_35OUT = 0x02; // 35 Bit Packet from BDI
static final int STYPE_BDI_10IN = 0x03; // 10 Bit Packet to BDI
static final int STYPE_BDI_10OUT = 0x04; // 10 Bit Packet from BDI
static final int STYPE_BDI_FD_DATA = 0x05; // Fast Download Data
static final int STYPE_BDI_ERROR_FD_LENGTH = 0x06; // Error if length in FD
// packet too small
// UART 1
static final int STYPE_UART_1_IN = 0x11; // Data to UART 1
static final int STYPE_UART_1_OUT = 0x22; // Data from UART 1
private static void do_read(Usb_Bus bus, int dev_handle) {
byte[] data = new byte[MAX_BYTEARRAY_SIZE];
int res = read_bulkdata(dev_handle, CONFIGURATION, INTERFACE,
ALTINTERFACE, IN_ENDPOINT, data, MAX_BYTEARRAY_SIZE, TIMEOUT);
if (res <= 0) {
System.err.println("Error on read_bulkdata "
+ LibusbWin.usb_strerror());
return;
}
System.out.println("read_bulkdata length: " + res);
System.out.print("Data: ");
for (int i = 0; i < res; i++) {
System.out.print("0x" + String.format("%1$02X", data[i]) + " ");
}
System.out.println();
// System.out.println("Data: " + logBytesAsChars(data));
}
private static String logBytesAsChars(byte[] data) {
StringBuffer sb = new StringBuffer(MAX_BYTEARRAY_SIZE);
int i = 0;
while ((data[i] != 0) && (i < MAX_BYTEARRAY_SIZE)) {
sb.append((char) data[i]);
i++;
}
return sb.toString();
}
private static void findFirstDevice() {
// find a valid device
Usb_Device dev;
while (bus != null) {
dev = bus.devices;
while (dev != null) {
System.out.println("dev.devnum " + dev.devnum);
int dev_handle = LibusbWin.usb_open(dev);
System.out.println("dev_handle " + dev_handle);
if (dev_handle > 0) {
if (LibusbWin.usb_close(dev_handle) < 0) {
System.err
.println("error on usb.usb_close(dev_handle)");
}
return;
}
dev = dev.next;
}
bus = bus.next;
}
}
private static void openDevice(Usb_Bus bus) {
int handle = openUsb_Device(bus, EZ_USB_DevKit_idVendor,
EZ_USB_DevKit_idProduct);
if (handle > 0) {
System.out.println("Usb_device_handle: " + handle);
System.out.println("closed: " + LibusbWin.usb_close(handle));
}
}
private static int write_bulkdata(int dev_handle, int configuration,
int interface_, int altinterface, int endpoint, byte[] data,
int length, int timeout) {
int res = LibusbWin.usb_set_configuration(dev_handle, configuration);
if (res < 0) {
System.err.println("Error on usb_set_configuration: "
+ LibusbWin.usb_strerror());
return res;
}
res = LibusbWin.usb_claim_interface(dev_handle, interface_);
if (res < 0) {
System.err.println("Error on usb_claim_interface: "
+ LibusbWin.usb_strerror());
return res;
}
LibusbWin.usb_set_altinterface(dev_handle, altinterface);
res = LibusbWin.usb_bulk_write(dev_handle, endpoint, data, length,
timeout);
LibusbWin.usb_release_interface(dev_handle, interface_);
if (res <= 0) {
System.err.println("Error on usb_bulk_write: "
+ LibusbWin.usb_strerror());
}
return res;
}
private static int read_bulkdata(int dev_handle, int configuration,
int interface_, int altinterface, int endpoint, byte[] data,
int size, int timeout) {
int res = LibusbWin.usb_set_configuration(dev_handle, configuration);
if (res < 0) {
System.err.println("Error on usb_set_configuration: "
+ LibusbWin.usb_strerror());
return res;
}
res = LibusbWin.usb_claim_interface(dev_handle, interface_);
if (res < 0) {
System.err.println("Error on read_bulkdata: "
+ LibusbWin.usb_strerror());
return res;
}
LibusbWin.usb_set_altinterface(dev_handle, altinterface);
res = LibusbWin
.usb_bulk_read(dev_handle, endpoint, data, size, timeout);
LibusbWin.usb_release_interface(dev_handle, interface_);
if (res <= 0) {
System.err.println("Error on usb_bulk_read: "
+ LibusbWin.usb_strerror());
return res;
}
return res;
}
private static void do_write(Usb_Bus bus, int dev_handle) {
// byte[] data = new String("Data to send...").getBytes();
byte[] data = new byte[512];
data[0] = PACKET_HEADER_1; // header
data[1] = (byte) PACKET_HEADER_2; // header
data[2] = MTYPE_BDI; // header
data[3] = STYPE_BDI_35IN; // header
data[4] = 0x00; // length of payload
data[5] = 0x05;
data[6] = 0x01; // payload
data[7] = 0x03;
data[8] = 0x07;
data[9] = 0x0F;
data[10] = 0x7F;
data[11] = (byte) PACKET_END; // packet end
int length = 12;
int res = write_bulkdata(dev_handle, CONFIGURATION, INTERFACE,
ALTINTERFACE, OUT_ENDPOINT, data, length, TIMEOUT);
if (res <= 0) {
System.err.println("Error on write_bulkdata");
return;
}
System.out.print(res + " Bytes sent: ");
for (int i = 0; i < res; i++) {
System.out.print("0x" + String.format("%1$02X", data[i]) + " ");
}
System.out.println();
System.out.println("write_bulkdata done");
}
private static String logBytes(byte[] data) {
StringBuffer sb = new StringBuffer(MAX_BYTEARRAY_SIZE);
for (int i = 0; i < data.length; i++) {
sb.append(data[i]);
sb.append(" ");
}
return sb.toString();
}
private static void do_write_read(Usb_Bus bus) {
int dev_handle = openUsb_Device(bus, EZ_USB_DevKit_idVendor,
EZ_USB_DevKit_idProduct);
if (dev_handle <= 0) {
System.err.println("Error on openUsb_Device: " + dev_handle);
return;
}
boolean run = true;
char c = 'a';
while (run) {
try {
c = (char) System.in.read();
} catch (IOException e) {
e.printStackTrace();
run = false;
}
switch (c) {
case 'w':
do_write(bus, dev_handle);
break;
case 'r':
do_read(bus, dev_handle);
break;
case 'x':
run = false;
break;
default:
break;
}
}
LibusbWin.usb_close(dev_handle);
}
public static int openUsb_Device(Usb_Bus bus, short idVendor,
short idProduct) {
int handle = -1;
while (bus != null) {
Usb_Device dev = bus.devices;
while (dev != null) {
// Usb_Device_Descriptor
Usb_Device_Descriptor defDesc = dev.descriptor;
if ((defDesc.idVendor == idVendor)
&& (defDesc.idProduct == idProduct)) {
System.out.println("Open device: " + dev.filename);
return LibusbWin.usb_open(dev);
}
dev = dev.next;
}
bus = bus.next;
}
return handle;
}
public static void main(String[] args) {
LibusbWin.usb_init();
LibusbWin.usb_find_busses();
LibusbWin.usb_find_devices();
bus = LibusbWin.usb_get_busses();
if (bus == null) {
System.err.println("Error on usb.usb_get_busses(): "
+ LibusbWin.usb_strerror());
return;
}
// Utils.logUsb(bus);
// openDevice(bus);
do_write_read(bus);
System.out.println("LibusbWin done");
}
}