/*
|
/*
|
* Java libusb wrapper
|
* Java libusb wrapper
|
* Copyright (c) 2005-2006 Andreas Schläpfer <spandi at users.sourceforge.net>
|
* Copyright (c) 2005-2006 Andreas Schläpfer <spandi at users.sourceforge.net>
|
*
|
*
|
* http://libusbjava.sourceforge.net
|
* http://libusbjava.sourceforge.net
|
* This library is covered by the LGPL, read LGPL.txt for details.
|
* This library is covered by the LGPL, read LGPL.txt for details.
|
*/
|
*/
|
package ch.ntb.usb;
|
package ch.ntb.usb;
|
|
|
import java.util.logging.Level;
|
import java.util.logging.Level;
|
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
|
|
import ch.ntb.usb.logger.LogUtil;
|
import ch.ntb.usb.logger.LogUtil;
|
|
|
/**
|
/**
|
* This class represents an USB device.<br>
|
* This class represents an USB device.<br>
|
* To get an instance of an USB device use <code>USB.getDevice(...)</code>.
|
* To get an instance of an USB device use <code>USB.getDevice(...)</code>.
|
*
|
*
|
*/
|
*/
|
public class Device {
|
public class Device {
|
|
|
private static final Logger logger = LogUtil.getLogger("ch.ntb.usb");
|
private static final Logger logger = LogUtil.getLogger("ch.ntb.usb");
|
|
|
private int maxPacketSize;
|
private int maxPacketSize;
|
|
|
/**
|
/**
|
* Mandatory identification values for the device.
|
* Mandatory identification values for the device.
|
*/
|
*/
|
private int idVendor, idProduct;
|
private int idVendor, idProduct;
|
|
|
/**
|
/**
|
* Optional identification value for the device (e.g. if there are multiple
|
* Optional identification value for the device (e.g. if there are multiple
|
* devices with the same vendor and product id).
|
* devices with the same vendor and product id).
|
*/
|
*/
|
private String filename;
|
private String filename;
|
|
|
private int dev_configuration, dev_interface, dev_altinterface;
|
private int dev_configuration, dev_interface, dev_altinterface;
|
|
|
private int usbDevHandle;
|
private long usbDevHandle;
|
|
|
private boolean resetOnFirstOpen, resetDone;
|
private boolean resetOnFirstOpen, resetDone;
|
|
|
private int resetTimeout = 2000;
|
private int resetTimeout = 2000;
|
|
|
private Usb_Device dev;
|
private Usb_Device dev;
|
|
|
protected Device(short idVendor, short idProduct) {
|
protected Device(short idVendor, short idProduct) {
|
resetOnFirstOpen = false;
|
resetOnFirstOpen = false;
|
resetDone = false;
|
resetDone = false;
|
maxPacketSize = -1;
|
maxPacketSize = -1;
|
this.idVendor = idVendor;
|
this.idVendor = idVendor;
|
this.idProduct = idProduct;
|
this.idProduct = idProduct;
|
this.filename = null;
|
this.filename = null;
|
}
|
}
|
|
|
protected Device(short idVendor, short idProduct, String filename) {
|
protected Device(short idVendor, short idProduct, String filename) {
|
resetOnFirstOpen = false;
|
resetOnFirstOpen = false;
|
resetDone = false;
|
resetDone = false;
|
maxPacketSize = -1;
|
maxPacketSize = -1;
|
this.idVendor = idVendor;
|
this.idVendor = idVendor;
|
this.idProduct = idProduct;
|
this.idProduct = idProduct;
|
this.filename = filename;
|
this.filename = filename;
|
}
|
}
|
|
|
private void updateMaxPacketSize(Usb_Device device) throws USBException {
|
private void updateMaxPacketSize(Usb_Device device) throws USBException {
|
maxPacketSize = -1;
|
maxPacketSize = -1;
|
Usb_Config_Descriptor[] confDesc = device.getConfig();
|
Usb_Config_Descriptor[] confDesc = device.getConfig();
|
for (int i = 0; i < confDesc.length; i++) {
|
for (int i = 0; i < confDesc.length; i++) {
|
Usb_Interface[] int_ = confDesc[i].getInterface();
|
Usb_Interface[] int_ = confDesc[i].getInterface();
|
for (int j = 0; j < int_.length; j++) {
|
for (int j = 0; j < int_.length; j++) {
|
Usb_Interface_Descriptor[] intDesc = int_[j].getAltsetting();
|
Usb_Interface_Descriptor[] intDesc = int_[j].getAltsetting();
|
for (int k = 0; k < intDesc.length; k++) {
|
for (int k = 0; k < intDesc.length; k++) {
|
Usb_Endpoint_Descriptor[] epDesc = intDesc[k].getEndpoint();
|
Usb_Endpoint_Descriptor[] epDesc = intDesc[k].getEndpoint();
|
for (int l = 0; l < epDesc.length; l++) {
|
for (int l = 0; l < epDesc.length; l++) {
|
maxPacketSize = Math.max(epDesc[l].getWMaxPacketSize(),
|
maxPacketSize = Math.max(epDesc[l].getWMaxPacketSize(),
|
maxPacketSize);
|
maxPacketSize);
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
if (maxPacketSize <= 0) {
|
if (maxPacketSize <= 0) {
|
throw new USBException(
|
throw new USBException(
|
"No USB endpoints found. Check the device configuration");
|
"No USB endpoints found. Check the device configuration");
|
}
|
}
|
}
|
}
|
|
|
/**
|
/**
|
* Initializes the device. The parameters <code>idVendor</code> and
|
* Initializes the device. The parameters <code>idVendor</code> and
|
* <code>idProduct</code> are mandatory. The parameter
|
* <code>idProduct</code> are mandatory. The parameter
|
* <code>filename</code> is optional.
|
* <code>filename</code> is optional.
|
*/
|
*/
|
private Usb_Device initDevice(int idVendorParam, int idProductParam,
|
private Usb_Device initDevice(int idVendorParam, int idProductParam,
|
String filename) throws USBException {
|
String filename) throws USBException {
|
Usb_Bus bus = USB.getBus();
|
Usb_Bus bus = USB.getBus();
|
|
|
Usb_Device device = null;
|
Usb_Device device = null;
|
// search for device
|
// search for device
|
while (bus != null) {
|
while (bus != null) {
|
device = bus.getDevices();
|
device = bus.getDevices();
|
while (device != null) {
|
while (device != null) {
|
Usb_Device_Descriptor devDesc = device.getDescriptor();
|
Usb_Device_Descriptor devDesc = device.getDescriptor();
|
if (filename != null
|
if (filename != null
|
&& filename.compareTo(device.getFilename()) == 0
|
&& filename.compareTo(device.getFilename()) == 0
|
&& devDesc.getIdVendor() == idVendorParam
|
&& devDesc.getIdVendor() == idVendorParam
|
&& devDesc.getIdProduct() == idProductParam) {
|
&& devDesc.getIdProduct() == idProductParam) {
|
// idVendor, idProduct and filename
|
// idVendor, idProduct and filename
|
logger.info("Device found: " + device.getFilename());
|
logger.info("Device found: " + device.getFilename());
|
updateMaxPacketSize(device);
|
updateMaxPacketSize(device);
|
return device;
|
return device;
|
} else if (devDesc.getIdVendor() == idVendorParam
|
} else if (devDesc.getIdVendor() == idVendorParam
|
&& devDesc.getIdProduct() == idProductParam) {
|
&& devDesc.getIdProduct() == idProductParam) {
|
// only idVendor and idProduct
|
// only idVendor and idProduct
|
logger.info("Device found: " + device.getFilename());
|
logger.info("Device found: " + device.getFilename());
|
updateMaxPacketSize(device);
|
updateMaxPacketSize(device);
|
return device;
|
return device;
|
}
|
}
|
device = device.getNext();
|
device = device.getNext();
|
}
|
}
|
bus = bus.getNext();
|
bus = bus.getNext();
|
}
|
}
|
return null;
|
return null;
|
}
|
}
|
|
|
/**
|
/**
|
* Updates the device and descriptor information from the bus.<br>
|
* Updates the device and descriptor information from the bus.<br>
|
* The descriptors can be read with {@link #getDeviceDescriptor()} and
|
* The descriptors can be read with {@link #getDeviceDescriptor()} and
|
* {@link #getConfigDescriptors()}.
|
* {@link #getConfigDescriptors()}.
|
*
|
*
|
* @throws USBException
|
* @throws USBException
|
*/
|
*/
|
public void updateDescriptors() throws USBException {
|
public void updateDescriptors() throws USBException {
|
dev = initDevice(idVendor, idProduct, filename);
|
dev = initDevice(idVendor, idProduct, filename);
|
}
|
}
|
|
|
/**
|
/**
|
* Returns the device descriptor associated with this device.<br>
|
* Returns the device descriptor associated with this device.<br>
|
* The descriptor is updated by calling {@link #updateDescriptors()} or
|
* The descriptor is updated by calling {@link #updateDescriptors()} or
|
* {@link #open(int, int, int)}.
|
* {@link #open(int, int, int)}.
|
*
|
*
|
* @return the device descriptor associated with this device or
|
* @return the device descriptor associated with this device or
|
* <code>null</code>
|
* <code>null</code>
|
*/
|
*/
|
public Usb_Device_Descriptor getDeviceDescriptor() {
|
public Usb_Device_Descriptor getDeviceDescriptor() {
|
if (dev == null) {
|
if (dev == null) {
|
return null;
|
return null;
|
}
|
}
|
return dev.getDescriptor();
|
return dev.getDescriptor();
|
}
|
}
|
|
|
/**
|
/**
|
* Returns the configuration descriptors associated with this device.<br>
|
* Returns the configuration descriptors associated with this device.<br>
|
* The descriptors are updated by calling {@link #updateDescriptors()} or
|
* The descriptors are updated by calling {@link #updateDescriptors()} or
|
* {@link #open(int, int, int)}.
|
* {@link #open(int, int, int)}.
|
*
|
*
|
* @return the configuration descriptors associated with this device or
|
* @return the configuration descriptors associated with this device or
|
* <code>null</code>
|
* <code>null</code>
|
*/
|
*/
|
public Usb_Config_Descriptor[] getConfigDescriptors() {
|
public Usb_Config_Descriptor[] getConfigDescriptors() {
|
if (dev == null) {
|
if (dev == null) {
|
return null;
|
return null;
|
}
|
}
|
return dev.getConfig();
|
return dev.getConfig();
|
}
|
}
|
|
|
/**
|
/**
|
* Opens the device and claims the specified configuration, interface and
|
* Opens the device and claims the specified configuration, interface and
|
* altinterface.<br>
|
* altinterface.<br>
|
* First the bus is enumerated. If the device is found its descriptors are
|
* First the bus is enumerated. If the device is found its descriptors are
|
* read and the <code>maxPacketSize</code> value is updated. If no
|
* read and the <code>maxPacketSize</code> value is updated. If no
|
* endpoints are found in the descriptors an exception is thrown.
|
* endpoints are found in the descriptors an exception is thrown.
|
*
|
*
|
* @param configuration
|
* @param configuration
|
* the configuration, see
|
* the configuration, see
|
* {@link Usb_Config_Descriptor#getBConfigurationValue()}
|
* {@link Usb_Config_Descriptor#getBConfigurationValue()}
|
* @param interface_
|
* @param interface_
|
* the interface, see
|
* the interface, see
|
* {@link Usb_Interface_Descriptor#getBInterfaceNumber()}
|
* {@link Usb_Interface_Descriptor#getBInterfaceNumber()}
|
* @param altinterface
|
* @param altinterface
|
* the alternate interface, see
|
* the alternate interface, see
|
* {@link Usb_Interface_Descriptor#getBAlternateSetting()}. If
|
* {@link Usb_Interface_Descriptor#getBAlternateSetting()}. If
|
* no alternate interface must be set <i>-1</i> can be used.
|
* no alternate interface must be set <i>-1</i> can be used.
|
* @throws USBException
|
* @throws USBException
|
*/
|
*/
|
public void open(int configuration, int interface_, int altinterface)
|
public void open(int configuration, int interface_, int altinterface)
|
throws USBException {
|
throws USBException {
|
this.dev_configuration = configuration;
|
this.dev_configuration = configuration;
|
this.dev_interface = interface_;
|
this.dev_interface = interface_;
|
this.dev_altinterface = altinterface;
|
this.dev_altinterface = altinterface;
|
|
|
if (usbDevHandle != 0) {
|
if (usbDevHandle != 0) {
|
throw new USBException("device opened, close or reset first");
|
throw new USBException("device opened, close or reset first");
|
}
|
}
|
|
|
dev = initDevice(idVendor, idProduct, filename);
|
dev = initDevice(idVendor, idProduct, filename);
|
|
|
if (dev != null) {
|
if (dev != null) {
|
int res = LibusbJava.usb_open(dev);
|
long res = LibusbJava.usb_open(dev);
|
if (res == 0) {
|
if (res == 0) {
|
throw new USBException("LibusbJava.usb_open: "
|
throw new USBException("LibusbJava.usb_open: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
usbDevHandle = res;
|
usbDevHandle = res;
|
}
|
}
|
|
|
if (dev == null || usbDevHandle == 0) {
|
if (dev == null || usbDevHandle == 0) {
|
throw new USBException("USB device with idVendor 0x"
|
throw new USBException("USB device with idVendor 0x"
|
+ Integer.toHexString(idVendor & 0xFFFF)
|
+ Integer.toHexString(idVendor & 0xFFFF)
|
+ " and idProduct 0x"
|
+ " and idProduct 0x"
|
+ Integer.toHexString(idProduct & 0xFFFF) + " not found");
|
+ Integer.toHexString(idProduct & 0xFFFF) + " not found");
|
}
|
}
|
claim_interface(usbDevHandle, configuration, interface_, altinterface);
|
claim_interface(usbDevHandle, configuration, interface_, altinterface);
|
if (resetOnFirstOpen & !resetDone) {
|
if (resetOnFirstOpen & !resetDone) {
|
logger.info("reset on first open");
|
logger.info("reset on first open");
|
resetDone = true;
|
resetDone = true;
|
reset();
|
reset();
|
try {
|
try {
|
Thread.sleep(resetTimeout);
|
Thread.sleep(resetTimeout);
|
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
//
|
//
|
}
|
}
|
open(configuration, interface_, altinterface);
|
open(configuration, interface_, altinterface);
|
}
|
}
|
}
|
}
|
|
|
/**
|
/**
|
* Release the claimed interface and close the opened device.<br>
|
* Release the claimed interface and close the opened device.<br>
|
*
|
*
|
* @throws USBException
|
* @throws USBException
|
*/
|
*/
|
public void close() throws USBException {
|
public void close() throws USBException {
|
if (usbDevHandle == 0) {
|
if (usbDevHandle == 0) {
|
throw new USBException("invalid device handle");
|
throw new USBException("invalid device handle");
|
}
|
}
|
release_interface(usbDevHandle, dev_interface);
|
release_interface(usbDevHandle, dev_interface);
|
if (LibusbJava.usb_close(usbDevHandle) < 0) {
|
if (LibusbJava.usb_close(usbDevHandle) < 0) {
|
usbDevHandle = 0;
|
usbDevHandle = 0;
|
throw new USBException("LibusbJava.usb_close: "
|
throw new USBException("LibusbJava.usb_close: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
usbDevHandle = 0;
|
usbDevHandle = 0;
|
maxPacketSize = -1;
|
maxPacketSize = -1;
|
logger.info("device closed");
|
logger.info("device closed");
|
}
|
}
|
|
|
/**
|
/**
|
* Sends an USB reset to the device. The device handle will no longer be
|
* Sends an USB reset to the device. The device handle will no longer be
|
* valid. To use the device again, {@link #open(int, int, int)} must be
|
* valid. To use the device again, {@link #open(int, int, int)} must be
|
* called.
|
* called.
|
*
|
*
|
* @throws USBException
|
* @throws USBException
|
*/
|
*/
|
public void reset() throws USBException {
|
public void reset() throws USBException {
|
if (usbDevHandle == 0) {
|
if (usbDevHandle == 0) {
|
throw new USBException("invalid device handle");
|
throw new USBException("invalid device handle");
|
}
|
}
|
release_interface(usbDevHandle, dev_interface);
|
release_interface(usbDevHandle, dev_interface);
|
if (LibusbJava.usb_reset(usbDevHandle) < 0) {
|
if (LibusbJava.usb_reset(usbDevHandle) < 0) {
|
usbDevHandle = 0;
|
usbDevHandle = 0;
|
throw new USBException("LibusbJava.usb_reset: "
|
throw new USBException("LibusbJava.usb_reset: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
usbDevHandle = 0;
|
usbDevHandle = 0;
|
logger.info("device reset");
|
logger.info("device reset");
|
}
|
}
|
|
|
/**
|
/**
|
* Write data to the device using a bulk transfer.<br>
|
* Write data to the device using a bulk transfer.<br>
|
*
|
*
|
* @param out_ep_address
|
* @param out_ep_address
|
* endpoint address to write to
|
* endpoint address to write to
|
* @param data
|
* @param data
|
* data to write to this endpoint
|
* data to write to this endpoint
|
* @param size
|
* @param size
|
* size of the data
|
* size of the data
|
* @param timeout
|
* @param timeout
|
* amount of time in ms the device will try to send the data
|
* amount of time in ms the device will try to send the data
|
* until a timeout exception is thrown
|
* until a timeout exception is thrown
|
* @param reopenOnTimeout
|
* @param reopenOnTimeout
|
* if set to true, the device will try to open the connection and
|
* if set to true, the device will try to open the connection and
|
* send the data again before a timeout exception is thrown
|
* send the data again before a timeout exception is thrown
|
* @return the actual number of bytes written
|
* @return the actual number of bytes written
|
* @throws USBException
|
* @throws USBException
|
*/
|
*/
|
public int writeBulk(int out_ep_address, byte[] data, int size,
|
public int writeBulk(int out_ep_address, byte[] data, int size,
|
int timeout, boolean reopenOnTimeout) throws USBException {
|
int timeout, boolean reopenOnTimeout) throws USBException {
|
if (usbDevHandle == 0) {
|
if (usbDevHandle == 0) {
|
throw new USBException("invalid device handle");
|
throw new USBException("invalid device handle");
|
}
|
}
|
if (data == null) {
|
if (data == null) {
|
throw new USBException("data must not be null");
|
throw new USBException("data must not be null");
|
}
|
}
|
if (size <= 0 || size > data.length) {
|
if (size <= 0 || size > data.length) {
|
throw new ArrayIndexOutOfBoundsException("invalid size: " + size);
|
throw new ArrayIndexOutOfBoundsException("invalid size: " + size);
|
}
|
}
|
int lenWritten = LibusbJava.usb_bulk_write(usbDevHandle,
|
int lenWritten = LibusbJava.usb_bulk_write(usbDevHandle,
|
out_ep_address, data, size, timeout);
|
out_ep_address, data, size, timeout);
|
if (lenWritten < 0) {
|
if (lenWritten < 0) {
|
if (lenWritten == LibusbJava.ERROR_TIMEDOUT) {
|
if (lenWritten == LibusbJava.ERROR_TIMEDOUT) {
|
// try to reopen the device and send the data again
|
// try to reopen the device and send the data again
|
if (reopenOnTimeout) {
|
if (reopenOnTimeout) {
|
logger.info("try to reopen");
|
logger.info("try to reopen");
|
reset();
|
reset();
|
open(dev_configuration, dev_interface, dev_altinterface);
|
open(dev_configuration, dev_interface, dev_altinterface);
|
return writeBulk(out_ep_address, data, size, timeout, false);
|
return writeBulk(out_ep_address, data, size, timeout, false);
|
}
|
}
|
throw new USBTimeoutException("LibusbJava.usb_bulk_write: "
|
throw new USBTimeoutException("LibusbJava.usb_bulk_write: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
throw new USBException("LibusbJava.usb_bulk_write: "
|
throw new USBException("LibusbJava.usb_bulk_write: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
|
|
logger.info("length written: " + lenWritten);
|
logger.info("length written: " + lenWritten);
|
if (logger.isLoggable(Level.FINEST)) {
|
if (logger.isLoggable(Level.FINEST)) {
|
StringBuffer sb = new StringBuffer("bulkwrite, ep 0x"
|
StringBuffer sb = new StringBuffer("bulkwrite, ep 0x"
|
+ Integer.toHexString(out_ep_address) + ": " + lenWritten
|
+ Integer.toHexString(out_ep_address) + ": " + lenWritten
|
+ " Bytes sent: ");
|
+ " Bytes sent: ");
|
for (int i = 0; i < lenWritten; i++) {
|
for (int i = 0; i < lenWritten; i++) {
|
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
|
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
|
}
|
}
|
logger.info(sb.toString());
|
logger.info(sb.toString());
|
}
|
}
|
return lenWritten;
|
return lenWritten;
|
}
|
}
|
|
|
/**
|
/**
|
* Read data from the device using a bulk transfer.<br>
|
* Read data from the device using a bulk transfer.<br>
|
*
|
*
|
* @param in_ep_address
|
* @param in_ep_address
|
* endpoint address to read from
|
* endpoint address to read from
|
* @param data
|
* @param data
|
* data buffer for the data to be read
|
* data buffer for the data to be read
|
* @param size
|
* @param size
|
* the maximum requested data size
|
* the maximum requested data size
|
* @param timeout
|
* @param timeout
|
* amount of time in ms the device will try to receive data until
|
* amount of time in ms the device will try to receive data until
|
* a timeout exception is thrown
|
* a timeout exception is thrown
|
* @param reopenOnTimeout
|
* @param reopenOnTimeout
|
* if set to true, the device will try to open the connection and
|
* if set to true, the device will try to open the connection and
|
* receive the data again before a timeout exception is thrown
|
* receive the data again before a timeout exception is thrown
|
* @return the actual number of bytes read
|
* @return the actual number of bytes read
|
* @throws USBException
|
* @throws USBException
|
*/
|
*/
|
public int readBulk(int in_ep_address, byte[] data, int size, int timeout,
|
public int readBulk(int in_ep_address, byte[] data, int size, int timeout,
|
boolean reopenOnTimeout) throws USBException {
|
boolean reopenOnTimeout) throws USBException {
|
if (usbDevHandle == 0) {
|
if (usbDevHandle == 0) {
|
throw new USBException("invalid device handle");
|
throw new USBException("invalid device handle");
|
}
|
}
|
if (data == null) {
|
if (data == null) {
|
throw new USBException("data must not be null");
|
throw new USBException("data must not be null");
|
}
|
}
|
if (size <= 0 || size > data.length) {
|
if (size <= 0 || size > data.length) {
|
throw new ArrayIndexOutOfBoundsException("invalid size: " + size);
|
throw new ArrayIndexOutOfBoundsException("invalid size: " + size);
|
}
|
}
|
int lenRead = LibusbJava.usb_bulk_read(usbDevHandle, in_ep_address,
|
int lenRead = LibusbJava.usb_bulk_read(usbDevHandle, in_ep_address,
|
data, size, timeout);
|
data, size, timeout);
|
if (lenRead < 0) {
|
if (lenRead < 0) {
|
if (lenRead == LibusbJava.ERROR_TIMEDOUT) {
|
if (lenRead == LibusbJava.ERROR_TIMEDOUT) {
|
// try to reopen the device and send the data again
|
// try to reopen the device and send the data again
|
if (reopenOnTimeout) {
|
if (reopenOnTimeout) {
|
logger.info("try to reopen");
|
logger.info("try to reopen");
|
reset();
|
reset();
|
open(dev_configuration, dev_interface, dev_altinterface);
|
open(dev_configuration, dev_interface, dev_altinterface);
|
return readBulk(in_ep_address, data, size, timeout, false);
|
return readBulk(in_ep_address, data, size, timeout, false);
|
}
|
}
|
throw new USBTimeoutException("LibusbJava.usb_bulk_read: "
|
throw new USBTimeoutException("LibusbJava.usb_bulk_read: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
throw new USBException("LibusbJava.usb_bulk_read: "
|
throw new USBException("LibusbJava.usb_bulk_read: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
|
|
logger.info("length read: " + lenRead);
|
logger.info("length read: " + lenRead);
|
if (logger.isLoggable(Level.FINEST)) {
|
if (logger.isLoggable(Level.FINEST)) {
|
StringBuffer sb = new StringBuffer("bulkread, ep 0x"
|
StringBuffer sb = new StringBuffer("bulkread, ep 0x"
|
+ Integer.toHexString(in_ep_address) + ": " + lenRead
|
+ Integer.toHexString(in_ep_address) + ": " + lenRead
|
+ " Bytes received: ");
|
+ " Bytes received: ");
|
for (int i = 0; i < lenRead; i++) {
|
for (int i = 0; i < lenRead; i++) {
|
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
|
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
|
}
|
}
|
logger.info(sb.toString());
|
logger.info(sb.toString());
|
}
|
}
|
return lenRead;
|
return lenRead;
|
}
|
}
|
|
|
/**
|
/**
|
* Write data to the device using a interrupt transfer.<br>
|
* Write data to the device using a interrupt transfer.<br>
|
*
|
*
|
* @param out_ep_address
|
* @param out_ep_address
|
* endpoint address to write to
|
* endpoint address to write to
|
* @param data
|
* @param data
|
* data to write to this endpoint
|
* data to write to this endpoint
|
* @param size
|
* @param size
|
* size of the data
|
* size of the data
|
* @param timeout
|
* @param timeout
|
* amount of time in ms the device will try to send the data
|
* amount of time in ms the device will try to send the data
|
* until a timeout exception is thrown
|
* until a timeout exception is thrown
|
* @param reopenOnTimeout
|
* @param reopenOnTimeout
|
* if set to true, the device will try to open the connection and
|
* if set to true, the device will try to open the connection and
|
* send the data again before a timeout exception is thrown
|
* send the data again before a timeout exception is thrown
|
* @return the actual number of bytes written
|
* @return the actual number of bytes written
|
* @throws USBException
|
* @throws USBException
|
*/
|
*/
|
public int writeInterrupt(int out_ep_address, byte[] data, int size,
|
public int writeInterrupt(int out_ep_address, byte[] data, int size,
|
int timeout, boolean reopenOnTimeout) throws USBException {
|
int timeout, boolean reopenOnTimeout) throws USBException {
|
if (usbDevHandle == 0) {
|
if (usbDevHandle == 0) {
|
throw new USBException("invalid device handle");
|
throw new USBException("invalid device handle");
|
}
|
}
|
if (data == null) {
|
if (data == null) {
|
throw new USBException("data must not be null");
|
throw new USBException("data must not be null");
|
}
|
}
|
if (size <= 0 || size > data.length) {
|
if (size <= 0 || size > data.length) {
|
throw new ArrayIndexOutOfBoundsException("invalid size: " + size);
|
throw new ArrayIndexOutOfBoundsException("invalid size: " + size);
|
}
|
}
|
int lenWritten = LibusbJava.usb_interrupt_write(usbDevHandle,
|
int lenWritten = LibusbJava.usb_interrupt_write(usbDevHandle,
|
out_ep_address, data, size, timeout);
|
out_ep_address, data, size, timeout);
|
if (lenWritten < 0) {
|
if (lenWritten < 0) {
|
if (lenWritten == LibusbJava.ERROR_TIMEDOUT) {
|
if (lenWritten == LibusbJava.ERROR_TIMEDOUT) {
|
// try to reopen the device and send the data again
|
// try to reopen the device and send the data again
|
if (reopenOnTimeout) {
|
if (reopenOnTimeout) {
|
logger.info("try to reopen");
|
logger.info("try to reopen");
|
reset();
|
reset();
|
open(dev_configuration, dev_interface, dev_altinterface);
|
open(dev_configuration, dev_interface, dev_altinterface);
|
return writeInterrupt(out_ep_address, data, size, timeout,
|
return writeInterrupt(out_ep_address, data, size, timeout,
|
false);
|
false);
|
}
|
}
|
throw new USBTimeoutException(
|
throw new USBTimeoutException(
|
"LibusbJava.usb_interrupt_write: "
|
"LibusbJava.usb_interrupt_write: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
throw new USBException("LibusbJava.usb_interrupt_write: "
|
throw new USBException("LibusbJava.usb_interrupt_write: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
|
|
logger.info("length written: " + lenWritten);
|
logger.info("length written: " + lenWritten);
|
if (logger.isLoggable(Level.FINEST)) {
|
if (logger.isLoggable(Level.FINEST)) {
|
StringBuffer sb = new StringBuffer("interruptwrite, ep 0x"
|
StringBuffer sb = new StringBuffer("interruptwrite, ep 0x"
|
+ Integer.toHexString(out_ep_address) + ": " + lenWritten
|
+ Integer.toHexString(out_ep_address) + ": " + lenWritten
|
+ " Bytes sent: ");
|
+ " Bytes sent: ");
|
for (int i = 0; i < lenWritten; i++) {
|
for (int i = 0; i < lenWritten; i++) {
|
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
|
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
|
}
|
}
|
logger.info(sb.toString());
|
logger.info(sb.toString());
|
}
|
}
|
return lenWritten;
|
return lenWritten;
|
}
|
}
|
|
|
/**
|
/**
|
* Read data from the device using a interrupt transfer.<br>
|
* Read data from the device using a interrupt transfer.<br>
|
*
|
*
|
* @param in_ep_address
|
* @param in_ep_address
|
* endpoint address to read from
|
* endpoint address to read from
|
* @param data
|
* @param data
|
* data buffer for the data to be read
|
* data buffer for the data to be read
|
* @param size
|
* @param size
|
* the maximum requested data size
|
* the maximum requested data size
|
* @param timeout
|
* @param timeout
|
* amount of time in ms the device will try to receive data until
|
* amount of time in ms the device will try to receive data until
|
* a timeout exception is thrown
|
* a timeout exception is thrown
|
* @param reopenOnTimeout
|
* @param reopenOnTimeout
|
* if set to true, the device will try to open the connection and
|
* if set to true, the device will try to open the connection and
|
* receive the data again before a timeout exception is thrown
|
* receive the data again before a timeout exception is thrown
|
* @return the actual number of bytes read
|
* @return the actual number of bytes read
|
* @throws USBException
|
* @throws USBException
|
*/
|
*/
|
public int readInterrupt(int in_ep_address, byte[] data, int size,
|
public int readInterrupt(int in_ep_address, byte[] data, int size,
|
int timeout, boolean reopenOnTimeout) throws USBException {
|
int timeout, boolean reopenOnTimeout) throws USBException {
|
if (usbDevHandle == 0) {
|
if (usbDevHandle == 0) {
|
throw new USBException("invalid device handle");
|
throw new USBException("invalid device handle");
|
}
|
}
|
if (data == null) {
|
if (data == null) {
|
throw new USBException("data must not be null");
|
throw new USBException("data must not be null");
|
}
|
}
|
if (size <= 0 || size > data.length) {
|
if (size <= 0 || size > data.length) {
|
throw new ArrayIndexOutOfBoundsException("invalid size: " + size);
|
throw new ArrayIndexOutOfBoundsException("invalid size: " + size);
|
}
|
}
|
int lenRead = LibusbJava.usb_interrupt_read(usbDevHandle,
|
int lenRead = LibusbJava.usb_interrupt_read(usbDevHandle,
|
in_ep_address, data, size, timeout);
|
in_ep_address, data, size, timeout);
|
if (lenRead < 0) {
|
if (lenRead < 0) {
|
if (lenRead == LibusbJava.ERROR_TIMEDOUT) {
|
if (lenRead == LibusbJava.ERROR_TIMEDOUT) {
|
// try to reopen the device and send the data again
|
// try to reopen the device and send the data again
|
if (reopenOnTimeout) {
|
if (reopenOnTimeout) {
|
logger.info("try to reopen");
|
logger.info("try to reopen");
|
reset();
|
reset();
|
open(dev_configuration, dev_interface, dev_altinterface);
|
open(dev_configuration, dev_interface, dev_altinterface);
|
return readInterrupt(in_ep_address, data, size, timeout,
|
return readInterrupt(in_ep_address, data, size, timeout,
|
false);
|
false);
|
}
|
}
|
throw new USBTimeoutException("LibusbJava.usb_interrupt_read: "
|
throw new USBTimeoutException("LibusbJava.usb_interrupt_read: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
throw new USBException("LibusbJava.usb_interrupt_read: "
|
throw new USBException("LibusbJava.usb_interrupt_read: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
|
|
logger.info("length read: " + lenRead);
|
logger.info("length read: " + lenRead);
|
if (logger.isLoggable(Level.FINEST)) {
|
if (logger.isLoggable(Level.FINEST)) {
|
StringBuffer sb = new StringBuffer("interrupt, ep 0x"
|
StringBuffer sb = new StringBuffer("interrupt, ep 0x"
|
+ Integer.toHexString(in_ep_address) + ": " + lenRead
|
+ Integer.toHexString(in_ep_address) + ": " + lenRead
|
+ " Bytes received: ");
|
+ " Bytes received: ");
|
for (int i = 0; i < lenRead; i++) {
|
for (int i = 0; i < lenRead; i++) {
|
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
|
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
|
}
|
}
|
logger.info(sb.toString());
|
logger.info(sb.toString());
|
}
|
}
|
return lenRead;
|
return lenRead;
|
}
|
}
|
|
|
/**
|
/**
|
* Performs a control request to the default control pipe on a device.<br>
|
* Performs a control request to the default control pipe on a device.<br>
|
* The parameters mirror the types of the same name in the USB
|
* The parameters mirror the types of the same name in the USB
|
* specification.
|
* specification.
|
*
|
*
|
* @param requestType
|
* @param requestType
|
* USB device request type (USB specification 9.3,
|
* USB device request type (USB specification 9.3,
|
* bmRequestType). Use constants from {@link ch.ntb.usb.USB}
|
* bmRequestType). Use constants from {@link ch.ntb.usb.USB}
|
* (REQ_TYPE_xxx).
|
* (REQ_TYPE_xxx).
|
* @param request
|
* @param request
|
* specific request (USB specification 9.4, bRequest). Use
|
* specific request (USB specification 9.4, bRequest). Use
|
* constants from {@link ch.ntb.usb.USB} (REQ_xxx).
|
* constants from {@link ch.ntb.usb.USB} (REQ_xxx).
|
* @param value
|
* @param value
|
* field that varies according to request (USB specification 9.4,
|
* field that varies according to request (USB specification 9.4,
|
* wValue)
|
* wValue)
|
* @param index
|
* @param index
|
* field that varies according to request (USB specification 9.4,
|
* field that varies according to request (USB specification 9.4,
|
* wIndex)
|
* wIndex)
|
* @param data
|
* @param data
|
* the send/receive buffer
|
* the send/receive buffer
|
* @param size
|
* @param size
|
* the buffer size. 0 is a valid value, but there must still be a
|
* the buffer size. 0 is a valid value, but there must still be a
|
* dummy data buffer provided.
|
* dummy data buffer provided.
|
* @param timeout
|
* @param timeout
|
* amount of time in ms the device will try to send/receive data
|
* amount of time in ms the device will try to send/receive data
|
* until a timeout exception is thrown
|
* until a timeout exception is thrown
|
* @param reopenOnTimeout
|
* @param reopenOnTimeout
|
* if set to true, the device will try to open the connection and
|
* if set to true, the device will try to open the connection and
|
* send/receive the data again before a timeout exception is
|
* send/receive the data again before a timeout exception is
|
* thrown
|
* thrown
|
* @return the number of bytes written/read
|
* @return the number of bytes written/read
|
* @throws USBException
|
* @throws USBException
|
*/
|
*/
|
public int controlMsg(int requestType, int request, int value, int index,
|
public int controlMsg(int requestType, int request, int value, int index,
|
byte[] data, int size, int timeout, boolean reopenOnTimeout)
|
byte[] data, int size, int timeout, boolean reopenOnTimeout)
|
throws USBException {
|
throws USBException {
|
if (usbDevHandle == 0) {
|
if (usbDevHandle == 0) {
|
throw new USBException("invalid device handle");
|
throw new USBException("invalid device handle");
|
}
|
}
|
if (data == null) {
|
if (data == null) {
|
throw new USBException("data must not be null");
|
throw new USBException("data must not be null");
|
}
|
}
|
if (size < 0 || size > data.length) {
|
if (size < 0 || size > data.length) {
|
throw new ArrayIndexOutOfBoundsException("invalid size: " + size);
|
throw new ArrayIndexOutOfBoundsException("invalid size: " + size);
|
}
|
}
|
int len = LibusbJava.usb_control_msg(usbDevHandle, requestType,
|
int len = LibusbJava.usb_control_msg(usbDevHandle, requestType,
|
request, value, index, data, size, timeout);
|
request, value, index, data, size, timeout);
|
if (len < 0) {
|
if (len < 0) {
|
if (len == LibusbJava.ERROR_TIMEDOUT) {
|
if (len == LibusbJava.ERROR_TIMEDOUT) {
|
// try to reopen the device and send the data again
|
// try to reopen the device and send the data again
|
if (reopenOnTimeout) {
|
if (reopenOnTimeout) {
|
logger.info("try to reopen");
|
logger.info("try to reopen");
|
reset();
|
reset();
|
open(dev_configuration, dev_interface, dev_altinterface);
|
open(dev_configuration, dev_interface, dev_altinterface);
|
return controlMsg(requestType, request, value, index, data,
|
return controlMsg(requestType, request, value, index, data,
|
size, timeout, false);
|
size, timeout, false);
|
}
|
}
|
throw new USBTimeoutException("LibusbJava.controlMsg: "
|
throw new USBTimeoutException("LibusbJava.controlMsg: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
throw new USBException("LibusbJava.controlMsg: "
|
throw new USBException("LibusbJava.controlMsg: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
|
|
logger.info("length read/written: " + len);
|
logger.info("length read/written: " + len);
|
if (logger.isLoggable(Level.FINEST)) {
|
if (logger.isLoggable(Level.FINEST)) {
|
StringBuffer sb = new StringBuffer("controlMsg: " + len
|
StringBuffer sb = new StringBuffer("controlMsg: " + len
|
+ " Bytes received(written: ");
|
+ " Bytes received(written: ");
|
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
|
sb.append("0x" + String.format("%1$02X", data[i]) + " ");
|
}
|
}
|
logger.info(sb.toString());
|
logger.info(sb.toString());
|
}
|
}
|
return len;
|
return len;
|
}
|
}
|
|
|
/**
|
/**
|
* Claim an interface to send and receive USB data.<br>
|
* Claim an interface to send and receive USB data.<br>
|
*
|
*
|
* @param usb_dev_handle
|
* @param usb_dev_handle
|
* the handle of the device <b>(MUST BE VALID)</b>
|
* the handle of the device <b>(MUST BE VALID)</b>
|
* @param configuration
|
* @param configuration
|
* the configuration to use
|
* the configuration to use
|
* @param interface_
|
* @param interface_
|
* the interface to claim
|
* the interface to claim
|
* @param altinterface
|
* @param altinterface
|
* the alternate interface to use. If no alternate interface must
|
* the alternate interface to use. If no alternate interface must
|
* be set <i>-1</i> can be used.
|
* be set <i>-1</i> can be used.
|
* @throws USBException
|
* @throws USBException
|
* throws an USBException if the action fails
|
* throws an USBException if the action fails
|
*/
|
*/
|
private void claim_interface(int usb_dev_handle, int configuration,
|
private void claim_interface(long usb_dev_handle, int configuration,
|
int interface_, int altinterface) throws USBException {
|
int interface_, int altinterface) throws USBException {
|
if (LibusbJava.usb_set_configuration(usb_dev_handle, configuration) < 0) {
|
if (LibusbJava.usb_set_configuration(usb_dev_handle, configuration) < 0) {
|
usbDevHandle = 0;
|
usbDevHandle = 0;
|
throw new USBException("LibusbJava.usb_set_configuration: "
|
throw new USBException("LibusbJava.usb_set_configuration: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
if (LibusbJava.usb_claim_interface(usb_dev_handle, interface_) < 0) {
|
if (LibusbJava.usb_claim_interface(usb_dev_handle, interface_) < 0) {
|
usbDevHandle = 0;
|
usbDevHandle = 0;
|
throw new USBException("LibusbJava.usb_claim_interface: "
|
throw new USBException("LibusbJava.usb_claim_interface: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
if (altinterface >= 0) {
|
if (altinterface >= 0) {
|
if (LibusbJava.usb_set_altinterface(usb_dev_handle, altinterface) < 0) {
|
if (LibusbJava.usb_set_altinterface(usb_dev_handle, altinterface) < 0) {
|
try {
|
try {
|
release_interface(usb_dev_handle, interface_);
|
release_interface(usb_dev_handle, interface_);
|
} catch (USBException e) {
|
} catch (USBException e) {
|
// ignore
|
// ignore
|
}
|
}
|
usbDevHandle = 0;
|
usbDevHandle = 0;
|
throw new USBException("LibusbJava.usb_set_altinterface: "
|
throw new USBException("LibusbJava.usb_set_altinterface: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
}
|
}
|
logger.info("interface claimed");
|
logger.info("interface claimed");
|
}
|
}
|
|
|
/**
|
/**
|
* Release a previously claimed interface.<br>
|
* Release a previously claimed interface.<br>
|
*
|
*
|
* @param dev_handle
|
* @param dev_handle
|
* the handle of the device <b>(MUST BE VALID)</b>
|
* the handle of the device <b>(MUST BE VALID)</b>
|
* @param interface_
|
* @param interface_
|
* the interface to claim
|
* the interface to claim
|
* @throws USBException
|
* @throws USBException
|
* throws an USBException if the action fails
|
* throws an USBException if the action fails
|
*/
|
*/
|
private void release_interface(int dev_handle, int interface_)
|
private void release_interface(long dev_handle, int interface_)
|
throws USBException {
|
throws USBException {
|
if (LibusbJava.usb_release_interface(dev_handle, interface_) < 0) {
|
if (LibusbJava.usb_release_interface(dev_handle, interface_) < 0) {
|
usbDevHandle = 0;
|
usbDevHandle = 0;
|
throw new USBException("LibusbJava.usb_release_interface: "
|
throw new USBException("LibusbJava.usb_release_interface: "
|
+ LibusbJava.usb_strerror());
|
+ LibusbJava.usb_strerror());
|
}
|
}
|
logger.info("interface released");
|
logger.info("interface released");
|
}
|
}
|
|
|
/**
|
/**
|
* Returns the product ID of the device.<br>
|
* Returns the product ID of the device.<br>
|
*
|
*
|
* @return the product ID of the device.
|
* @return the product ID of the device.
|
*/
|
*/
|
public int getIdProduct() {
|
public int getIdProduct() {
|
return idProduct;
|
return idProduct;
|
}
|
}
|
|
|
/**
|
/**
|
* Returns the vendor ID of the device.<br>
|
* Returns the vendor ID of the device.<br>
|
*
|
*
|
* @return the vendor ID of the device.
|
* @return the vendor ID of the device.
|
*/
|
*/
|
public int getIdVendor() {
|
public int getIdVendor() {
|
return idVendor;
|
return idVendor;
|
}
|
}
|
|
|
/**
|
/**
|
* Returns the alternative interface.<br>
|
* Returns the alternative interface.<br>
|
* This value is only valid after opening the device.
|
* This value is only valid after opening the device.
|
*
|
*
|
* @return the alternative interface. This value is only valid after opening
|
* @return the alternative interface. This value is only valid after opening
|
* the device.
|
* the device.
|
*/
|
*/
|
public int getAltinterface() {
|
public int getAltinterface() {
|
return dev_altinterface;
|
return dev_altinterface;
|
}
|
}
|
|
|
/**
|
/**
|
* Returns the current configuration used.<br>
|
* Returns the current configuration used.<br>
|
* This value is only valid after opening the device.
|
* This value is only valid after opening the device.
|
*
|
*
|
* @return the current configuration used. This value is only valid after
|
* @return the current configuration used. This value is only valid after
|
* opening the device.
|
* opening the device.
|
*/
|
*/
|
public int getConfiguration() {
|
public int getConfiguration() {
|
return dev_configuration;
|
return dev_configuration;
|
}
|
}
|
|
|
/**
|
/**
|
* Returns the current interface.<br>
|
* Returns the current interface.<br>
|
* This value is only valid after opening the device.
|
* This value is only valid after opening the device.
|
*
|
*
|
* @return the current interface. This value is only valid after opening the
|
* @return the current interface. This value is only valid after opening the
|
* device.
|
* device.
|
*/
|
*/
|
public int getInterface() {
|
public int getInterface() {
|
return dev_interface;
|
return dev_interface;
|
}
|
}
|
|
|
/**
|
/**
|
* Returns the maximum packet size in bytes which is allowed to be
|
* Returns the maximum packet size in bytes which is allowed to be
|
* transmitted at once.<br>
|
* transmitted at once.<br>
|
* The value is determined by reading the endpoint descriptor(s) when
|
* The value is determined by reading the endpoint descriptor(s) when
|
* opening the device. It is invalid before the device is opened! Note that
|
* opening the device. It is invalid before the device is opened! Note that
|
* if some endpoints use different packet sizes the maximum packet size is
|
* if some endpoints use different packet sizes the maximum packet size is
|
* return. This value may be used to determine if a device is opened in
|
* return. This value may be used to determine if a device is opened in
|
* fullspeed or highspeed mode.
|
* fullspeed or highspeed mode.
|
*
|
*
|
* @return the maximum packet size
|
* @return the maximum packet size
|
*/
|
*/
|
public int getMaxPacketSize() {
|
public int getMaxPacketSize() {
|
return maxPacketSize;
|
return maxPacketSize;
|
}
|
}
|
|
|
/**
|
/**
|
* Check if the device is open.<br>
|
* Check if the device is open.<br>
|
* This checks only for a valid device handle. It doesn't check if the
|
* This checks only for a valid device handle. It doesn't check if the
|
* device is still attached or working.
|
* device is still attached or working.
|
*
|
*
|
* @return true if the device is open
|
* @return true if the device is open
|
*/
|
*/
|
public boolean isOpen() {
|
public boolean isOpen() {
|
return usbDevHandle != 0;
|
return usbDevHandle != 0;
|
}
|
}
|
|
|
/**
|
/**
|
* If enabled, the device is reset when first opened. <br>
|
* If enabled, the device is reset when first opened. <br>
|
* This will only happen once. When the application is started, the device
|
* This will only happen once. When the application is started, the device
|
* state is unknown. If the device is not reset, read or write may result in
|
* state is unknown. If the device is not reset, read or write may result in
|
* a {@link USBTimeoutException}.<br>
|
* a {@link USBTimeoutException}.<br>
|
* <br>
|
* <br>
|
* This feature is disabled by default.
|
* This feature is disabled by default.
|
*
|
*
|
* @param enable
|
* @param enable
|
* true if the device should be reset when first opened
|
* true if the device should be reset when first opened
|
* @param timeout
|
* @param timeout
|
* the timeout between the reset and the reopening
|
* the timeout between the reset and the reopening
|
*/
|
*/
|
public void setResetOnFirstOpen(boolean enable, int timeout) {
|
public void setResetOnFirstOpen(boolean enable, int timeout) {
|
resetOnFirstOpen = enable;
|
resetOnFirstOpen = enable;
|
resetTimeout = timeout;
|
resetTimeout = timeout;
|
}
|
}
|
|
|
/**
|
/**
|
* Returns the optional filename which is set when there are multiple
|
* Returns the optional filename which is set when there are multiple
|
* devices with the same vendor and product id. See
|
* devices with the same vendor and product id. See
|
* {@link USB#getDevice(short, short, String)}. Use
|
* {@link USB#getDevice(short, short, String)}. Use
|
* {@link Usb_Device#getFilename()} to read the filename of a device.
|
* {@link Usb_Device#getFilename()} to read the filename of a device.
|
*
|
*
|
* @return the filename if set or null
|
* @return the filename if set or null
|
*/
|
*/
|
protected String getFilename() {
|
protected String getFilename() {
|
return filename;
|
return filename;
|
}
|
}
|
|
|
/**
|
/**
|
* Returns the Usb_Device instance associated with this device. This value
|
* Returns the Usb_Device instance associated with this device. This value
|
* is only valid after opening the device.
|
* is only valid after opening the device.
|
*
|
*
|
* @return the Usb_Device instance associated with this device.
|
* @return the Usb_Device instance associated with this device.
|
*/
|
*/
|
public Usb_Device getDevice() {
|
public Usb_Device getDevice() {
|
return dev;
|
return dev;
|
}
|
}
|
}
|
}
|
|
|