- Timeout as parameter
git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@64 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
@@ -23,7 +23,9 @@ public class USBDevice {
|
||||
|
||||
private static final int IN_Endpoint_UART = 0x88;
|
||||
|
||||
private static final int Timeout = 2000;
|
||||
private static final int BDI_Timeout = 1000;
|
||||
|
||||
private static final int UART_Timeout = 50;
|
||||
|
||||
static {
|
||||
// set data for our device
|
||||
@@ -36,7 +38,6 @@ public class USBDevice {
|
||||
USB.setIN_Endpoint_1(IN_Endpoint_BDI);
|
||||
USB.setOUT_Endpoint_2(OUT_Endpoint_UART);
|
||||
USB.setIN_Endpoint_2(IN_Endpoint_UART);
|
||||
USB.setTimeout(Timeout);
|
||||
// reset USB
|
||||
USB.reset();
|
||||
}
|
||||
@@ -54,20 +55,20 @@ public class USBDevice {
|
||||
}
|
||||
|
||||
public static void write_BDI(byte[] data, int length) throws USBException {
|
||||
USB.write_EP1(data, length);
|
||||
USB.write_EP1(data, length, BDI_Timeout);
|
||||
}
|
||||
|
||||
public static synchronized int read_BDI(byte[] data, int size)
|
||||
throws USBException {
|
||||
return USB.read_EP1(data, size);
|
||||
return USB.read_EP1(data, size, BDI_Timeout);
|
||||
}
|
||||
|
||||
public static void write_UART(byte[] data, int length) throws USBException {
|
||||
USB.write_EP2(data, length);
|
||||
USB.write_EP2(data, length, UART_Timeout);
|
||||
}
|
||||
|
||||
public static synchronized int read_UART(byte[] data, int size)
|
||||
throws USBException {
|
||||
return USB.read_EP2(data, size);
|
||||
return USB.read_EP2(data, size, UART_Timeout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@ public class USB {
|
||||
|
||||
private static short IdProduct = -1;
|
||||
|
||||
private static int Timeout = 3000;
|
||||
|
||||
private static int Configuration = -1;
|
||||
|
||||
private static int Interface = -1;
|
||||
@@ -126,7 +124,8 @@ public class USB {
|
||||
}
|
||||
}
|
||||
|
||||
public static void write_EP1(byte[] data, int length) throws USBException {
|
||||
public static void write_EP1(byte[] data, int length, int timeout)
|
||||
throws USBException {
|
||||
if (data == null) {
|
||||
throw new USBException("data must not be null");
|
||||
}
|
||||
@@ -134,7 +133,7 @@ public class USB {
|
||||
throw new USBException("size must be > 0");
|
||||
}
|
||||
int lenWritten = LibusbWin.usb_bulk_write(usb_dev_handle,
|
||||
OUT_Endpoint_1, data, length, Timeout);
|
||||
OUT_Endpoint_1, data, length, timeout);
|
||||
if (lenWritten < 0) {
|
||||
if (lenWritten == TIMEOUT_ERROR_CODE) {
|
||||
throw new USBTimeoutException("LibusbWin.usb_bulk_write EP1: "
|
||||
@@ -154,7 +153,8 @@ public class USB {
|
||||
}
|
||||
}
|
||||
|
||||
public static int read_EP1(byte[] data, int size) throws USBException {
|
||||
public static int read_EP1(byte[] data, int size, int timeout)
|
||||
throws USBException {
|
||||
if (data == null) {
|
||||
throw new USBException("data must not be null");
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class USB {
|
||||
throw new USBException("size must be > 0");
|
||||
}
|
||||
int lenRead = LibusbWin.usb_bulk_read(usb_dev_handle, IN_Endpoint_1,
|
||||
data, size, Timeout);
|
||||
data, size, timeout);
|
||||
if (lenRead < 0) {
|
||||
if (lenRead == TIMEOUT_ERROR_CODE) {
|
||||
throw new USBTimeoutException("LibusbWin.usb_bulk_read EP1: "
|
||||
@@ -184,7 +184,8 @@ public class USB {
|
||||
return lenRead;
|
||||
}
|
||||
|
||||
public static void write_EP2(byte[] data, int length) throws USBException {
|
||||
public static void write_EP2(byte[] data, int length, int timeout)
|
||||
throws USBException {
|
||||
if (data == null) {
|
||||
throw new USBException("data must not be null");
|
||||
}
|
||||
@@ -192,7 +193,7 @@ public class USB {
|
||||
throw new USBException("size must be > 0");
|
||||
}
|
||||
int lenWritten = LibusbWin.usb_bulk_write(usb_dev_handle,
|
||||
OUT_Endpoint_2, data, length, Timeout);
|
||||
OUT_Endpoint_2, data, length, timeout);
|
||||
if (lenWritten < 0) {
|
||||
if (lenWritten == TIMEOUT_ERROR_CODE) {
|
||||
throw new USBTimeoutException("LibusbWin.usb_bulk_write EP2: "
|
||||
@@ -212,7 +213,8 @@ public class USB {
|
||||
}
|
||||
}
|
||||
|
||||
public static int read_EP2(byte[] data, int size) throws USBException {
|
||||
public static int read_EP2(byte[] data, int size, int timeout)
|
||||
throws USBException {
|
||||
if (data == null) {
|
||||
throw new USBException("data must not be null");
|
||||
}
|
||||
@@ -220,7 +222,7 @@ public class USB {
|
||||
throw new USBException("size must be > 0");
|
||||
}
|
||||
int lenRead = LibusbWin.usb_bulk_read(usb_dev_handle, IN_Endpoint_2,
|
||||
data, size, Timeout);
|
||||
data, size, timeout);
|
||||
if (lenRead < 0) {
|
||||
if (lenRead == TIMEOUT_ERROR_CODE) {
|
||||
throw new USBTimeoutException("LibusbWin.usb_bulk_read EP2: "
|
||||
@@ -330,14 +332,6 @@ public class USB {
|
||||
OUT_Endpoint_2 = out_endpoint_2;
|
||||
}
|
||||
|
||||
public static int getTimeout() {
|
||||
return Timeout;
|
||||
}
|
||||
|
||||
public static void setTimeout(int timeout) {
|
||||
Timeout = timeout;
|
||||
}
|
||||
|
||||
public static int getAltinterface() {
|
||||
return Altinterface;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user