- old files removed
git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@75 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
@@ -1,346 +0,0 @@
|
|||||||
package ch.ntb.usb;
|
|
||||||
|
|
||||||
import ch.ntb.usb.LibusbWin;
|
|
||||||
import ch.ntb.usb.Usb_Bus;
|
|
||||||
import ch.ntb.usb.Usb_Device;
|
|
||||||
import ch.ntb.usb.Usb_Device_Descriptor;
|
|
||||||
|
|
||||||
public class USB_old {
|
|
||||||
|
|
||||||
public static final int MAX_DATA_SIZE = 512;
|
|
||||||
|
|
||||||
private static final int TIMEOUT_ERROR_CODE = -116;
|
|
||||||
|
|
||||||
private static final boolean DEBUG_ON = false;
|
|
||||||
|
|
||||||
private static Usb_Bus bus;
|
|
||||||
|
|
||||||
private static int usb_dev_handle = 0;
|
|
||||||
|
|
||||||
private static short IdVendor = -1;
|
|
||||||
|
|
||||||
private static short IdProduct = -1;
|
|
||||||
|
|
||||||
private static int Configuration = -1;
|
|
||||||
|
|
||||||
private static int Interface = -1;
|
|
||||||
|
|
||||||
private static int Altinterface = -1;
|
|
||||||
|
|
||||||
private static int OUT_Endpoint_1 = -1;
|
|
||||||
|
|
||||||
private static int IN_Endpoint_1 = -1;
|
|
||||||
|
|
||||||
private static int OUT_Endpoint_2 = -1;
|
|
||||||
|
|
||||||
private static int IN_Endpoint_2 = -1;
|
|
||||||
|
|
||||||
public static void openUsbDevice() throws USBException {
|
|
||||||
|
|
||||||
int res;
|
|
||||||
|
|
||||||
// open bus
|
|
||||||
LibusbWin.usb_init();
|
|
||||||
LibusbWin.usb_find_busses();
|
|
||||||
LibusbWin.usb_find_devices();
|
|
||||||
|
|
||||||
bus = LibusbWin.usb_get_busses();
|
|
||||||
if (bus == null) {
|
|
||||||
throw new USBException("LibusbWin.usb_get_busses(): "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
if (DEBUG_ON) {
|
|
||||||
System.out.println("Open device: " + dev.filename);
|
|
||||||
}
|
|
||||||
res = LibusbWin.usb_open(dev);
|
|
||||||
if (res <= 0) {
|
|
||||||
throw new USBException("LibusbWin.usb_open: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
} else {
|
|
||||||
usb_dev_handle = res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dev = dev.next;
|
|
||||||
}
|
|
||||||
bus = bus.next;
|
|
||||||
}
|
|
||||||
if (usb_dev_handle <= 0) {
|
|
||||||
throw new USBException("UsbDevice with idVendor 0x"
|
|
||||||
+ Integer.toHexString(IdVendor & 0xFFFF)
|
|
||||||
+ " and idProduct 0x"
|
|
||||||
+ Integer.toHexString(IdProduct & 0xFFFF) + " not found");
|
|
||||||
}
|
|
||||||
claim_interface(usb_dev_handle, Configuration, Interface, Altinterface);
|
|
||||||
|
|
||||||
if (DEBUG_ON) {
|
|
||||||
System.out.println("device opened, interface claimed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void closeUsbDevice() throws USBException {
|
|
||||||
if (usb_dev_handle <= 0) {
|
|
||||||
throw new USBException("Device not open");
|
|
||||||
}
|
|
||||||
System.out.println(usb_dev_handle);
|
|
||||||
release_interface(usb_dev_handle, Interface);
|
|
||||||
if (LibusbWin.usb_close(usb_dev_handle) < 0) {
|
|
||||||
throw new USBException("LibusbWin.usb_close: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEBUG_ON) {
|
|
||||||
System.out.println("device closed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void resetUsbDevice() throws USBException {
|
|
||||||
if (usb_dev_handle <= 0) {
|
|
||||||
throw new USBException("Device not open");
|
|
||||||
}
|
|
||||||
if (LibusbWin.usb_reset(usb_dev_handle) < 0) {
|
|
||||||
throw new USBException("LibusbWin.usb_reset: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
usb_dev_handle = 0;
|
|
||||||
|
|
||||||
if (DEBUG_ON) {
|
|
||||||
System.out.println("resetUsbDevie done");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write_EP1(byte[] data, int length, int timeout)
|
|
||||||
throws USBException {
|
|
||||||
if (usb_dev_handle <= 0) {
|
|
||||||
throw new USBException("Device not open");
|
|
||||||
}
|
|
||||||
if (data == null) {
|
|
||||||
throw new USBException("data must not be null");
|
|
||||||
}
|
|
||||||
if (length <= 0) {
|
|
||||||
throw new USBException("size must be > 0");
|
|
||||||
}
|
|
||||||
int lenWritten = LibusbWin.usb_bulk_write(usb_dev_handle,
|
|
||||||
OUT_Endpoint_1, data, length, timeout);
|
|
||||||
if (lenWritten < 0) {
|
|
||||||
if (lenWritten == TIMEOUT_ERROR_CODE) {
|
|
||||||
throw new USBTimeoutException("LibusbWin.usb_bulk_write EP1: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
throw new USBException("LibusbWin.usb_bulk_write EP1: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEBUG_ON) {
|
|
||||||
System.out.print("write_bulkdata EP1: " + lenWritten
|
|
||||||
+ " Bytes sent: ");
|
|
||||||
for (int i = 0; i < lenWritten; i++) {
|
|
||||||
System.out.print("0x" + String.format("%1$02X", data[i]) + " ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int read_EP1(byte[] data, int size, int timeout)
|
|
||||||
throws USBException {
|
|
||||||
if (usb_dev_handle <= 0) {
|
|
||||||
throw new USBException("Device not open");
|
|
||||||
}
|
|
||||||
if (data == null) {
|
|
||||||
throw new USBException("data must not be null");
|
|
||||||
}
|
|
||||||
if (size <= 0) {
|
|
||||||
throw new USBException("size must be > 0");
|
|
||||||
}
|
|
||||||
int lenRead = LibusbWin.usb_bulk_read(usb_dev_handle, IN_Endpoint_1,
|
|
||||||
data, size, timeout);
|
|
||||||
if (lenRead < 0) {
|
|
||||||
if (lenRead == TIMEOUT_ERROR_CODE) {
|
|
||||||
throw new USBTimeoutException("LibusbWin.usb_bulk_read EP1: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
throw new USBException("LibusbWin.usb_bulk_read EP1: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEBUG_ON) {
|
|
||||||
System.out.print("read_bulkdata EP1: " + lenRead
|
|
||||||
+ " Bytes received: ");
|
|
||||||
System.out.print("Data: ");
|
|
||||||
for (int i = 0; i < lenRead; i++) {
|
|
||||||
System.out.print("0x" + String.format("%1$02X", data[i]) + " ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
return lenRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write_EP2(byte[] data, int length, int timeout)
|
|
||||||
throws USBException {
|
|
||||||
if (usb_dev_handle <= 0) {
|
|
||||||
throw new USBException("Device not open");
|
|
||||||
}
|
|
||||||
if (data == null) {
|
|
||||||
throw new USBException("data must not be null");
|
|
||||||
}
|
|
||||||
if (length <= 0) {
|
|
||||||
throw new USBException("size must be > 0");
|
|
||||||
}
|
|
||||||
int lenWritten = LibusbWin.usb_bulk_write(usb_dev_handle,
|
|
||||||
OUT_Endpoint_2, data, length, timeout);
|
|
||||||
if (lenWritten < 0) {
|
|
||||||
if (lenWritten == TIMEOUT_ERROR_CODE) {
|
|
||||||
throw new USBTimeoutException("LibusbWin.usb_bulk_write EP2: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
throw new USBException("LibusbWin.usb_bulk_write EP2: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEBUG_ON) {
|
|
||||||
System.out.print("write_bulkdata EP2: " + lenWritten
|
|
||||||
+ " Bytes sent: ");
|
|
||||||
for (int i = 0; i < lenWritten; i++) {
|
|
||||||
System.out.print("0x" + String.format("%1$02X", data[i]) + " ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int read_EP2(byte[] data, int size, int timeout)
|
|
||||||
throws USBException {
|
|
||||||
if (usb_dev_handle <= 0) {
|
|
||||||
throw new USBException("Device not open");
|
|
||||||
}
|
|
||||||
if (data == null) {
|
|
||||||
throw new USBException("data must not be null");
|
|
||||||
}
|
|
||||||
if (size <= 0) {
|
|
||||||
throw new USBException("size must be > 0");
|
|
||||||
}
|
|
||||||
int lenRead = LibusbWin.usb_bulk_read(usb_dev_handle, IN_Endpoint_2,
|
|
||||||
data, size, timeout);
|
|
||||||
if (lenRead < 0) {
|
|
||||||
if (lenRead == TIMEOUT_ERROR_CODE) {
|
|
||||||
throw new USBTimeoutException("LibusbWin.usb_bulk_read EP2: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
throw new USBException("LibusbWin.usb_bulk_read EP2: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEBUG_ON) {
|
|
||||||
System.out.print("read_bulkdata EP2: " + lenRead
|
|
||||||
+ " Bytes received: ");
|
|
||||||
System.out.print("Data: ");
|
|
||||||
for (int i = 0; i < lenRead; i++) {
|
|
||||||
System.out.print("0x" + String.format("%1$02X", data[i]) + " ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
return lenRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void claim_interface(int dev_handle, int configuration,
|
|
||||||
int interface_, int altinterface) throws USBException {
|
|
||||||
if (LibusbWin.usb_set_configuration(usb_dev_handle, configuration) < 0) {
|
|
||||||
throw new USBException("LibusbWin.usb_set_configuration: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
if (LibusbWin.usb_claim_interface(dev_handle, interface_) < 0) {
|
|
||||||
throw new USBException("LibusbWin.usb_claim_interface: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
if (LibusbWin.usb_set_altinterface(dev_handle, altinterface) < 0) {
|
|
||||||
throw new USBException("LibusbWin.usb_set_altinterface: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void release_interface(int dev_handle, int interface_)
|
|
||||||
throws USBException {
|
|
||||||
if (LibusbWin.usb_release_interface(dev_handle, interface_) < 0) {
|
|
||||||
throw new USBException("LibusbWin.usb_release_interface: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static short getIdProduct() {
|
|
||||||
return IdProduct;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setIdProduct(short idProduct) {
|
|
||||||
IdProduct = idProduct;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static short getIdVendor() {
|
|
||||||
return IdVendor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setIdVendor(short idVendor) {
|
|
||||||
IdVendor = idVendor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getConfiguration() {
|
|
||||||
return Configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setConfiguration(int configuration) {
|
|
||||||
Configuration = configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getInterface() {
|
|
||||||
return Interface;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setInterface(int interface_) {
|
|
||||||
Interface = interface_;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getIN_Endpoint_1() {
|
|
||||||
return IN_Endpoint_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setIN_Endpoint_1(int in_endpoint_1) {
|
|
||||||
IN_Endpoint_1 = in_endpoint_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getOUT_Endpoint_1() {
|
|
||||||
return OUT_Endpoint_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setOUT_Endpoint_1(int out_endpoint_1) {
|
|
||||||
OUT_Endpoint_1 = out_endpoint_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getIN_Endpoint_2() {
|
|
||||||
return IN_Endpoint_2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setIN_Endpoint_2(int in_endpoint_2) {
|
|
||||||
IN_Endpoint_2 = in_endpoint_2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getOUT_Endpoint_2() {
|
|
||||||
return OUT_Endpoint_2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setOUT_Endpoint_2(int out_endpoint_2) {
|
|
||||||
OUT_Endpoint_2 = out_endpoint_2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getAltinterface() {
|
|
||||||
return Altinterface;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setAltinterface(int altinterface) {
|
|
||||||
Altinterface = altinterface;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
package ch.ntb.usb.test;
|
|
||||||
|
|
||||||
import ch.ntb.usb.LibusbWin;
|
|
||||||
import ch.ntb.usb.USBException;
|
|
||||||
import ch.ntb.usb.USB_old;
|
|
||||||
import ch.ntb.usb.Usb_Bus;
|
|
||||||
|
|
||||||
public class TestAppUsb_old {
|
|
||||||
|
|
||||||
static Usb_Bus bus;
|
|
||||||
|
|
||||||
static int usb_dev_handle = 0;
|
|
||||||
|
|
||||||
static short IdVendor = 0x04B4;
|
|
||||||
|
|
||||||
static short IdProduct = (short) 0x1004;
|
|
||||||
|
|
||||||
static int TIMEOUT = 1000;
|
|
||||||
|
|
||||||
static int CONFIGURATION = 1;
|
|
||||||
|
|
||||||
static int INTERFACE = 0;
|
|
||||||
|
|
||||||
static int ALTINTERFACE = 0;
|
|
||||||
|
|
||||||
static int OUT_ENDPOINT = 0x02;
|
|
||||||
|
|
||||||
static int IN_ENDPOINT = 0x86;
|
|
||||||
|
|
||||||
static final int MAX_BYTEARRAY_SIZE = 512;
|
|
||||||
|
|
||||||
static boolean dev_opened = false;
|
|
||||||
|
|
||||||
static void openUsbDevice() {
|
|
||||||
try {
|
|
||||||
USB_old.openUsbDevice();
|
|
||||||
} catch (USBException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.println("device opened, interface claimed");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void closeUsbDevice() {
|
|
||||||
try {
|
|
||||||
USB_old.closeUsbDevice();
|
|
||||||
} catch (USBException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.println("device closed");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void write(byte[] data, int length) {
|
|
||||||
try {
|
|
||||||
USB_old.write_EP1(data, length, TIMEOUT);
|
|
||||||
} catch (USBException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
int res = 0;
|
|
||||||
System.out.print("write_bulkdata: " + res + " Bytes sent: ");
|
|
||||||
for (int i = 0; i < res; i++) {
|
|
||||||
System.out.print("0x" + String.format("%1$02X", data[i]) + " ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void read() {
|
|
||||||
if (!dev_opened) {
|
|
||||||
System.out.println("Open Device first");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
byte[] data = new byte[MAX_BYTEARRAY_SIZE];
|
|
||||||
int res = LibusbWin.usb_bulk_read(usb_dev_handle, IN_ENDPOINT, data,
|
|
||||||
MAX_BYTEARRAY_SIZE, TIMEOUT);
|
|
||||||
if (res < 0) {
|
|
||||||
System.err.println("Error on LibusbWin.usb_bulk_read: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
System.out.print("read_bulkdata: " + res + " Bytes received: ");
|
|
||||||
System.out.print("Data: ");
|
|
||||||
for (int i = 0; i < res; i++) {
|
|
||||||
System.out.print("0x" + String.format("%1$02X", data[i]) + " ");
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean claim_interface(int dev_handle, int configuration,
|
|
||||||
int interface_, int altinterface) {
|
|
||||||
int res = LibusbWin
|
|
||||||
.usb_set_configuration(usb_dev_handle, configuration);
|
|
||||||
if (res < 0) {
|
|
||||||
System.err.println("Error on LibusbWin.usb_set_configuration: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
return res >= 0;
|
|
||||||
}
|
|
||||||
res = LibusbWin.usb_claim_interface(dev_handle, interface_);
|
|
||||||
if (res < 0) {
|
|
||||||
System.err.println("Error on LibusbWin.usb_claim_interface: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
return res >= 0;
|
|
||||||
}
|
|
||||||
res = LibusbWin.usb_set_altinterface(dev_handle, altinterface);
|
|
||||||
if (res < 0) {
|
|
||||||
System.err.println("Error on LibusbWin.usb_set_altinterface: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
return res >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean release_interface(int dev_handle, int interface_) {
|
|
||||||
int res = LibusbWin.usb_release_interface(dev_handle, interface_);
|
|
||||||
if (res < 0) {
|
|
||||||
System.err.println("Error on LibusbWin.usb_release_interface: "
|
|
||||||
+ LibusbWin.usb_strerror());
|
|
||||||
}
|
|
||||||
return res >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// private static int write_bulkdata(int dev_handle, int endpoint,
|
|
||||||
// byte[] data, int length, int timeout) {
|
|
||||||
// int res = LibusbWin.usb_bulk_write(dev_handle, endpoint, data, length,
|
|
||||||
// timeout);
|
|
||||||
// if (res < 0) {
|
|
||||||
// System.err.println("Error on LibusbWin.usb_bulk_write: "
|
|
||||||
// + LibusbWin.usb_strerror());
|
|
||||||
// }
|
|
||||||
// return res;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private static int read_bulkdata(int dev_handle, int interface_,
|
|
||||||
// int altinterface, int endpoint, byte[] data, int size, int timeout) {
|
|
||||||
// int res = LibusbWin.usb_bulk_read(dev_handle, endpoint, data, size,
|
|
||||||
// timeout);
|
|
||||||
// if (res < 0) {
|
|
||||||
// System.err.println("Error on LibusbWin.usb_bulk_read: "
|
|
||||||
// + LibusbWin.usb_strerror());
|
|
||||||
// }
|
|
||||||
// return res;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -1,395 +0,0 @@
|
|||||||
package ch.ntb.usb.test;
|
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
|
||||||
import org.eclipse.swt.graphics.Rectangle;
|
|
||||||
import org.eclipse.swt.layout.RowData;
|
|
||||||
import org.eclipse.swt.layout.RowLayout;
|
|
||||||
import org.eclipse.swt.widgets.Button;
|
|
||||||
import org.eclipse.swt.widgets.Composite;
|
|
||||||
import org.eclipse.swt.widgets.Display;
|
|
||||||
import org.eclipse.swt.widgets.Group;
|
|
||||||
import org.eclipse.swt.widgets.Shell;
|
|
||||||
import org.eclipse.swt.widgets.Text;
|
|
||||||
|
|
||||||
public class TestApp_old {
|
|
||||||
|
|
||||||
private static final int HEX_WIDTH = 5;
|
|
||||||
private Shell rootShell = null; // @jve:decl-index=0:visual-constraint="10,10"
|
|
||||||
private Group vendorIDGroup = null;
|
|
||||||
private Text vendorID = null;
|
|
||||||
private Group productIDGroup = null;
|
|
||||||
private Text productID = null;
|
|
||||||
private Group configGroup = null;
|
|
||||||
private Text configuration = null;
|
|
||||||
private Group interfaceGroup = null;
|
|
||||||
private Text interface_ = null;
|
|
||||||
private Group altIntGroup = null;
|
|
||||||
private Text altInt = null;
|
|
||||||
private Group deviceGroup = null;
|
|
||||||
private Group endpointGroup = null;
|
|
||||||
private Group deviceGroup2 = null;
|
|
||||||
private Group outEPGroup = null;
|
|
||||||
private Text outEP = null;
|
|
||||||
private Group inEPGroup = null;
|
|
||||||
private Text inEP = null;
|
|
||||||
private Group timeoutGroup = null;
|
|
||||||
private Text timeout = null;
|
|
||||||
private Group dataGroup = null;
|
|
||||||
private Composite dataButtonComp = null;
|
|
||||||
private Button sendButton = null;
|
|
||||||
private Button recButton = null;
|
|
||||||
private Composite devComp = null;
|
|
||||||
private Composite devButtonComp = null;
|
|
||||||
private Button devOpenButton = null;
|
|
||||||
private Button devCloseButton = null;
|
|
||||||
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;
|
|
||||||
if (s.indexOf('x') > 0) {
|
|
||||||
// is hex number
|
|
||||||
if (s.length() <= 2){ // exception for "0x"
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
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){
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
int stringIndex = 0, spaceIndex = 0;
|
|
||||||
String ss;
|
|
||||||
while (stringIndex + 3 < s.length()){
|
|
||||||
ss = s.substring(spaceIndex, spaceIndex + 4);
|
|
||||||
spaceIndex = s.indexOf(' ', stringIndex) + 1;
|
|
||||||
sb.append((char) parseInt(ss));
|
|
||||||
stringIndex += HEX_WIDTH;
|
|
||||||
}
|
|
||||||
return sb.toString().getBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createSShell() {
|
|
||||||
RowLayout rowLayout = new RowLayout();
|
|
||||||
rowLayout.type = org.eclipse.swt.SWT.VERTICAL;
|
|
||||||
rowLayout.justify = true;
|
|
||||||
rowLayout.fill = true;
|
|
||||||
rootShell = new Shell();
|
|
||||||
rootShell.setText("Usb TestApplication");
|
|
||||||
rootShell.setLayout(rowLayout);
|
|
||||||
createDeviceGroup();
|
|
||||||
createDataGroup();
|
|
||||||
rootShell.setSize(new org.eclipse.swt.graphics.Point(466,315));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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");
|
|
||||||
TestAppUsb_old.IdVendor = (short) parseInt(vendorID.getText());
|
|
||||||
vendorID.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
|
|
||||||
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
|
|
||||||
TestAppUsb_old.IdVendor = (short) parseInt(vendorID.getText());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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");
|
|
||||||
TestAppUsb_old.IdProduct = (short) parseInt(productID.getText());
|
|
||||||
productID.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
|
|
||||||
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
|
|
||||||
TestAppUsb_old.IdProduct = (short) parseInt(productID.getText());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
TestAppUsb_old.CONFIGURATION = parseInt(configuration.getText());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
TestAppUsb_old.INTERFACE = parseInt(interface_.getText());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
|
|
||||||
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
|
|
||||||
TestAppUsb_old.ALTINTERFACE = parseInt(altInt.getText());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes deviceGroup
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void createDeviceGroup() {
|
|
||||||
RowLayout rowLayout1 = new RowLayout();
|
|
||||||
rowLayout1.type = org.eclipse.swt.SWT.VERTICAL;
|
|
||||||
rowLayout1.fill = true;
|
|
||||||
deviceGroup = new Group(rootShell, SWT.NONE);
|
|
||||||
deviceGroup.setText("Device Settings");
|
|
||||||
createDeviceGroup2();
|
|
||||||
deviceGroup.setLayout(rowLayout1);
|
|
||||||
createDevComp();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes endpointGroup
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void createEndpointGroup() {
|
|
||||||
endpointGroup = new Group(devComp, SWT.NONE);
|
|
||||||
endpointGroup.setLayout(new RowLayout());
|
|
||||||
createGroup4();
|
|
||||||
createGroup5();
|
|
||||||
createGroup6();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes deviceGroup2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void createDeviceGroup2() {
|
|
||||||
deviceGroup2 = new Group(deviceGroup, SWT.NONE);
|
|
||||||
deviceGroup2.setLayout(new RowLayout());
|
|
||||||
createVendorIDGroup();
|
|
||||||
createProductIDGroup();
|
|
||||||
createGroup();
|
|
||||||
createGroup2();
|
|
||||||
createGroup3();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
|
|
||||||
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
|
|
||||||
TestAppUsb_old.OUT_ENDPOINT = parseInt(outEP.getText());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
|
|
||||||
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
|
|
||||||
TestAppUsb_old.IN_ENDPOINT = parseInt(inEP.getText());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
|
|
||||||
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
|
|
||||||
TestAppUsb_old.TIMEOUT = parseInt(timeout.getText());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes dataGroup
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void createDataGroup() {
|
|
||||||
RowLayout rowLayout5 = new RowLayout();
|
|
||||||
rowLayout5.type = org.eclipse.swt.SWT.HORIZONTAL;
|
|
||||||
rowLayout5.spacing = 10;
|
|
||||||
dataGroup = new Group(rootShell, SWT.NONE);
|
|
||||||
dataGroup.setText("Send and Receive Data");
|
|
||||||
dataGroup.setLayout(rowLayout5);
|
|
||||||
createDataFieldGoup();
|
|
||||||
createButtonComp();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes buttonComp
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void createButtonComp() {
|
|
||||||
RowLayout rowLayout3 = new RowLayout();
|
|
||||||
rowLayout3.type = org.eclipse.swt.SWT.VERTICAL;
|
|
||||||
rowLayout3.justify = true;
|
|
||||||
rowLayout3.fill = true;
|
|
||||||
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());
|
|
||||||
TestAppUsb_old.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) {
|
|
||||||
TestAppUsb_old.read();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes devComp
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void createDevComp() {
|
|
||||||
RowLayout rowLayout4 = new RowLayout();
|
|
||||||
rowLayout4.fill = true;
|
|
||||||
rowLayout4.spacing = 50;
|
|
||||||
devComp = new Composite(deviceGroup, SWT.NONE);
|
|
||||||
createEndpointGroup();
|
|
||||||
devComp.setLayout(rowLayout4);
|
|
||||||
createDevButtonComp();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes devButtonComp
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void createDevButtonComp() {
|
|
||||||
RowLayout rowLayout2 = new RowLayout();
|
|
||||||
rowLayout2.marginHeight = 25;
|
|
||||||
rowLayout2.spacing = 5;
|
|
||||||
devButtonComp = new Composite(devComp, SWT.NONE);
|
|
||||||
devButtonComp.setLayout(rowLayout2);
|
|
||||||
devOpenButton = new Button(devButtonComp, SWT.NONE);
|
|
||||||
devOpenButton.setText("Open Device");
|
|
||||||
devOpenButton
|
|
||||||
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
|
|
||||||
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
|
|
||||||
TestAppUsb_old.openUsbDevice();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
devCloseButton = new Button(devButtonComp, SWT.NONE);
|
|
||||||
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) {
|
|
||||||
System.out.println("not implemented");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
devCloseButton
|
|
||||||
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
|
|
||||||
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
|
|
||||||
TestAppUsb_old.closeUsbDevice();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes dataFieldGoup
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void createDataFieldGoup() {
|
|
||||||
RowData rowData = new org.eclipse.swt.layout.RowData();
|
|
||||||
rowData.width = 340;
|
|
||||||
RowLayout rowLayout6 = new RowLayout();
|
|
||||||
rowLayout6.fill = true;
|
|
||||||
rowLayout6.marginHeight = 5;
|
|
||||||
rowLayout6.justify = true;
|
|
||||||
dataFieldGoup = new Group(dataGroup, SWT.NONE);
|
|
||||||
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.setLayoutData(rowData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
TestApp_old app = new TestApp_old();
|
|
||||||
app.createSShell();
|
|
||||||
app.rootShell.open();
|
|
||||||
|
|
||||||
Display display = app.rootShell.getDisplay();
|
|
||||||
|
|
||||||
while (!app.rootShell.isDisposed()) {
|
|
||||||
if(!display.readAndDispatch()) {
|
|
||||||
display.sleep();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user