Files
jlibusb/java/src/ch/ntb/usb/test/TestImplementation.java
schlaepfer 059df21ceb - 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
2006-08-09 13:49:28 +00:00

100 lines
2.3 KiB
Java

package ch.ntb.usb.test;
import java.util.logging.Level;
import java.util.logging.Logger;
import ch.ntb.usb.Device;
import ch.ntb.usb.USB;
import ch.ntb.usb.USBException;
import ch.ntb.usb.logger.LogUtil;
public class TestImplementation {
private static Logger logger = LogUtil.ch_ntb_usb_test;
public static String sendData = "0x5b 0x02 0x01 0x00 0x03 0x03 0xf0 0xf0 0x1f";
public static short IdVendor = (short) 0x8235;
public static short IdProduct = 0x0200;
public static int TIMEOUT = 2000;
public static int CONFIGURATION = 1;
public static int INTERFACE = 0;
public static int ALTINTERFACE = 0;
public static int OUT_ENDPOINT = 0x01;
public static int IN_ENDPOINT = 0x82;
private static Device dev = null;
static {
logger.setLevel(Level.ALL);
}
static void openUsbDevice() {
dev = USB.getDevice(IdVendor, IdProduct);
try {
dev.open(CONFIGURATION, INTERFACE, ALTINTERFACE);
logger.info("device opened, interface claimed");
} catch (USBException e) {
e.printStackTrace();
}
}
static void closeUsbDevice() {
try {
dev.close();
logger.info("device closed");
} catch (USBException e) {
e.printStackTrace();
}
}
static void resetUsbDevice() {
try {
dev.reset();
logger.info("device reset");
} catch (USBException e) {
e.printStackTrace();
}
}
static void write(byte[] data, int length) {
int lenWritten = 0;
try {
lenWritten = dev.bulkwrite(OUT_ENDPOINT, data, length, TIMEOUT,
false);
StringBuffer sb = new StringBuffer("write_bulkdata: " + lenWritten
+ " Bytes sent: ");
for (int i = 0; i < lenWritten; i++) {
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
}
logger.info(sb.toString());
} catch (USBException e) {
e.printStackTrace();
}
}
static void read() {
byte[] data = new byte[dev.getMaxPacketSize()];
int lenRead = 0;
try {
lenRead = dev.bulkread(IN_ENDPOINT, data, dev.getMaxPacketSize(),
TIMEOUT, false);
StringBuffer sb = new StringBuffer("read_bulkdata: " + lenRead
+ " Bytes received: Data: ");
for (int i = 0; i < lenRead; i++) {
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
}
logger.info(sb.toString());
} catch (USBException e) {
e.printStackTrace();
}
}
}