- LibusbWin renamed to LibusbJava
git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@208 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
@@ -48,18 +48,18 @@ public class Device {
|
||||
}
|
||||
|
||||
private void initUSB() {
|
||||
LibusbWin.usb_init();
|
||||
LibusbJava.usb_init();
|
||||
initUSBDone = true;
|
||||
}
|
||||
|
||||
private Usb_Bus initBus() throws USBException {
|
||||
LibusbWin.usb_find_busses();
|
||||
LibusbWin.usb_find_devices();
|
||||
LibusbJava.usb_find_busses();
|
||||
LibusbJava.usb_find_devices();
|
||||
|
||||
Usb_Bus bus = LibusbWin.usb_get_busses();
|
||||
Usb_Bus bus = LibusbJava.usb_get_busses();
|
||||
if (bus == null) {
|
||||
throw new USBException("LibusbWin.usb_get_busses(): "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
|
||||
return bus;
|
||||
@@ -183,10 +183,10 @@ public class Device {
|
||||
dev = initDevice();
|
||||
|
||||
if (dev != null) {
|
||||
int res = LibusbWin.usb_open(dev);
|
||||
int res = LibusbJava.usb_open(dev);
|
||||
if (res <= 0) {
|
||||
throw new USBException("LibusbWin.usb_open: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
usbDevHandle = res;
|
||||
}
|
||||
@@ -221,10 +221,10 @@ public class Device {
|
||||
throw new USBException("invalid device handle");
|
||||
}
|
||||
release_interface(usbDevHandle, dev_interface);
|
||||
if (LibusbWin.usb_close(usbDevHandle) < 0) {
|
||||
if (LibusbJava.usb_close(usbDevHandle) < 0) {
|
||||
usbDevHandle = 0;
|
||||
throw new USBException("LibusbWin.usb_close: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
usbDevHandle = 0;
|
||||
maxPacketSize = -1;
|
||||
@@ -242,10 +242,10 @@ public class Device {
|
||||
if (usbDevHandle <= 0) {
|
||||
throw new USBException("invalid device handle");
|
||||
}
|
||||
if (LibusbWin.usb_reset(usbDevHandle) < 0) {
|
||||
if (LibusbJava.usb_reset(usbDevHandle) < 0) {
|
||||
usbDevHandle = 0;
|
||||
throw new USBException("LibusbWin.usb_reset: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
usbDevHandle = 0;
|
||||
logger.info("device reset");
|
||||
@@ -280,7 +280,7 @@ public class Device {
|
||||
if (length <= 0) {
|
||||
throw new USBException("size must be > 0");
|
||||
}
|
||||
int lenWritten = LibusbWin.usb_bulk_write(usbDevHandle, out_ep_address,
|
||||
int lenWritten = LibusbJava.usb_bulk_write(usbDevHandle, out_ep_address,
|
||||
data, length, timeout);
|
||||
if (lenWritten < 0) {
|
||||
if (lenWritten == TIMEOUT_ERROR_CODE) {
|
||||
@@ -293,10 +293,10 @@ public class Device {
|
||||
false);
|
||||
}
|
||||
throw new USBTimeoutException("LibusbWin.usb_bulk_write: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
throw new USBException("LibusbWin.usb_bulk_write: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
|
||||
logger.info("length written: " + lenWritten);
|
||||
@@ -341,7 +341,7 @@ public class Device {
|
||||
if (size <= 0) {
|
||||
throw new USBException("size must be > 0");
|
||||
}
|
||||
int lenRead = LibusbWin.usb_bulk_read(usbDevHandle, in_ep_address,
|
||||
int lenRead = LibusbJava.usb_bulk_read(usbDevHandle, in_ep_address,
|
||||
data, size, timeout);
|
||||
if (lenRead < 0) {
|
||||
if (lenRead == TIMEOUT_ERROR_CODE) {
|
||||
@@ -353,10 +353,10 @@ public class Device {
|
||||
return readBulk(in_ep_address, data, size, timeout, false);
|
||||
}
|
||||
throw new USBTimeoutException("LibusbWin.usb_bulk_read: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
throw new USBException("LibusbWin.usb_bulk_read: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
|
||||
logger.info("length read: " + lenRead);
|
||||
@@ -401,7 +401,7 @@ public class Device {
|
||||
if (length <= 0) {
|
||||
throw new USBException("size must be > 0");
|
||||
}
|
||||
int lenWritten = LibusbWin.usb_interrupt_write(usbDevHandle,
|
||||
int lenWritten = LibusbJava.usb_interrupt_write(usbDevHandle,
|
||||
out_ep_address, data, length, timeout);
|
||||
if (lenWritten < 0) {
|
||||
if (lenWritten == TIMEOUT_ERROR_CODE) {
|
||||
@@ -414,10 +414,10 @@ public class Device {
|
||||
timeout, false);
|
||||
}
|
||||
throw new USBTimeoutException("LibusbWin.usb_bulk_write: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
throw new USBException("LibusbWin.usb_bulk_write: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
|
||||
logger.info("length written: " + lenWritten);
|
||||
@@ -462,7 +462,7 @@ public class Device {
|
||||
if (size <= 0) {
|
||||
throw new USBException("size must be > 0");
|
||||
}
|
||||
int lenRead = LibusbWin.usb_interrupt_read(usbDevHandle, in_ep_address,
|
||||
int lenRead = LibusbJava.usb_interrupt_read(usbDevHandle, in_ep_address,
|
||||
data, size, timeout);
|
||||
if (lenRead < 0) {
|
||||
if (lenRead == TIMEOUT_ERROR_CODE) {
|
||||
@@ -475,10 +475,10 @@ public class Device {
|
||||
false);
|
||||
}
|
||||
throw new USBTimeoutException("LibusbWin.usb_bulk_read: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
throw new USBException("LibusbWin.usb_bulk_read: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
|
||||
logger.info("length read: " + lenRead);
|
||||
@@ -511,18 +511,18 @@ public class Device {
|
||||
*/
|
||||
private void claim_interface(int usb_dev_handle, int configuration,
|
||||
int interface_, int altinterface) throws USBException {
|
||||
if (LibusbWin.usb_set_configuration(usb_dev_handle, configuration) < 0) {
|
||||
if (LibusbJava.usb_set_configuration(usb_dev_handle, configuration) < 0) {
|
||||
throw new USBException("LibusbWin.usb_set_configuration: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
if (LibusbWin.usb_claim_interface(usb_dev_handle, interface_) < 0) {
|
||||
if (LibusbJava.usb_claim_interface(usb_dev_handle, interface_) < 0) {
|
||||
throw new USBException("LibusbWin.usb_claim_interface: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
if (altinterface >= 0) {
|
||||
if (LibusbWin.usb_set_altinterface(usb_dev_handle, altinterface) < 0) {
|
||||
if (LibusbJava.usb_set_altinterface(usb_dev_handle, altinterface) < 0) {
|
||||
throw new USBException("LibusbWin.usb_set_altinterface: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
}
|
||||
logger.info("interface claimed");
|
||||
@@ -540,10 +540,10 @@ public class Device {
|
||||
*/
|
||||
private void release_interface(int dev_handle, int interface_)
|
||||
throws USBException {
|
||||
if (LibusbWin.usb_release_interface(dev_handle, interface_) < 0) {
|
||||
if (LibusbJava.usb_release_interface(dev_handle, interface_) < 0) {
|
||||
usbDevHandle = 0;
|
||||
throw new USBException("LibusbWin.usb_release_interface: "
|
||||
+ LibusbWin.usb_strerror());
|
||||
+ LibusbJava.usb_strerror());
|
||||
}
|
||||
logger.info("interface released");
|
||||
}
|
||||
|
||||
@@ -23,10 +23,9 @@ package ch.ntb.usb;
|
||||
* and adapted where neccessary.<br>
|
||||
*
|
||||
* @author schlaepfer
|
||||
* @version DLL: 00.02.00
|
||||
*
|
||||
*/
|
||||
public class LibusbWin {
|
||||
public class LibusbJava {
|
||||
|
||||
/**
|
||||
* Sets the debugging level of libusb.<br>
|
||||
@@ -327,6 +326,11 @@ public class LibusbWin {
|
||||
/** **************************************************************** */
|
||||
|
||||
static {
|
||||
System.load(System.getenv("SystemRoot") + "/system32/LibusbWin.dll");
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.contains("Windows")) {
|
||||
System.loadLibrary("LibusbJava");
|
||||
} else {
|
||||
System.loadLibrary("usbJava");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class Usb_Config_Descriptor extends Usb_Descriptor {
|
||||
public byte bNumInterfaces;
|
||||
|
||||
/**
|
||||
* Value to use as an argument to select this configuration ({@link LibusbWin#usb_set_configuration(int, int)}).
|
||||
* Value to use as an argument to select this configuration ({@link LibusbJava#usb_set_configuration(int, int)}).
|
||||
*/
|
||||
public byte bConfigurationValue;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Usb_Interface_Descriptor extends Usb_Descriptor {
|
||||
public byte bInterfaceNumber;
|
||||
|
||||
/**
|
||||
* Value used to select alternate setting ({@link LibusbWin#usb_set_altinterface(int, int)}).
|
||||
* Value used to select alternate setting ({@link LibusbJava#usb_set_altinterface(int, int)}).
|
||||
*/
|
||||
public byte bAlternateSetting;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ package ch.ntb.usb;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static void logUsb(Usb_Bus bus) {
|
||||
public static void logBus(Usb_Bus bus) {
|
||||
Usb_Bus usb_Bus = bus;
|
||||
while (usb_Bus != null) {
|
||||
System.out.println(usb_Bus.toString());
|
||||
@@ -17,24 +17,24 @@ public class Utils {
|
||||
System.out.println("\t" + dev.toString());
|
||||
// Usb_Device_Descriptor
|
||||
Usb_Device_Descriptor defDesc = dev.descriptor;
|
||||
System.out.println("\t" + defDesc.toString());
|
||||
System.out.println("\t\t" + defDesc.toString());
|
||||
// Usb_Config_Descriptor
|
||||
Usb_Config_Descriptor[] confDesc = dev.config;
|
||||
for (int i = 0; i < confDesc.length; i++) {
|
||||
System.out.println("\t" + confDesc[i].toString());
|
||||
System.out.println("\t\t" + confDesc[i].toString());
|
||||
Usb_Interface[] int_ = confDesc[i].interface_;
|
||||
if (int_ != null) {
|
||||
for (int j = 0; j < int_.length; j++) {
|
||||
System.out.println("\t" + int_[j].toString());
|
||||
System.out.println("\t\t\t" + int_[j].toString());
|
||||
Usb_Interface_Descriptor[] intDesc = int_[j].altsetting;
|
||||
if (intDesc != null) {
|
||||
for (int k = 0; k < intDesc.length; k++) {
|
||||
System.out.println("\t"
|
||||
System.out.println("\t\t\t\t"
|
||||
+ intDesc[k].toString());
|
||||
Usb_Endpoint_Descriptor[] epDesc = intDesc[k].endpoint;
|
||||
if (epDesc != null) {
|
||||
for (int e = 0; e < epDesc.length; e++) {
|
||||
System.out.println("\t"
|
||||
System.out.println("\t\t\t\t\t"
|
||||
+ epDesc[e].toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.TreeModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
import ch.ntb.usb.LibusbWin;
|
||||
import ch.ntb.usb.LibusbJava;
|
||||
import ch.ntb.usb.Usb_Bus;
|
||||
import ch.ntb.usb.Usb_Config_Descriptor;
|
||||
import ch.ntb.usb.Usb_Device;
|
||||
@@ -226,14 +226,14 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
||||
&& ((dev.descriptor.iManufacturer > 0)
|
||||
|| (dev.descriptor.iProduct > 0) || (dev.descriptor.iSerialNumber > 0))) {
|
||||
if (tmpDevDesc.equals(devDesc)) {
|
||||
int handle = LibusbWin.usb_open(dev);
|
||||
int handle = LibusbJava.usb_open(dev);
|
||||
sb.append("\nString descriptors\n");
|
||||
if (handle <= 0) {
|
||||
sb.append("\terror opening the device\n");
|
||||
break;
|
||||
}
|
||||
if (dev.descriptor.iManufacturer > 0) {
|
||||
String manufacturer = LibusbWin
|
||||
String manufacturer = LibusbJava
|
||||
.usb_get_string_simple(handle,
|
||||
devDesc.iManufacturer);
|
||||
if (manufacturer == null)
|
||||
@@ -242,7 +242,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
||||
+ "\n");
|
||||
}
|
||||
if (dev.descriptor.iProduct > 0) {
|
||||
String product = LibusbWin
|
||||
String product = LibusbJava
|
||||
.usb_get_string_simple(handle,
|
||||
devDesc.iProduct);
|
||||
if (product == null)
|
||||
@@ -250,7 +250,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
||||
sb.append("\tiProduct: " + product + "\n");
|
||||
}
|
||||
if (dev.descriptor.iSerialNumber > 0) {
|
||||
String serialNumber = LibusbWin
|
||||
String serialNumber = LibusbJava
|
||||
.usb_get_string_simple(handle,
|
||||
devDesc.iSerialNumber);
|
||||
if (serialNumber == null)
|
||||
@@ -258,7 +258,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
||||
sb.append("\tiSerialNumber: " + serialNumber
|
||||
+ "\n");
|
||||
}
|
||||
LibusbWin.usb_close(handle);
|
||||
LibusbJava.usb_close(handle);
|
||||
}
|
||||
}
|
||||
dev = dev.next;
|
||||
@@ -296,13 +296,13 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
||||
for (int i = 0; i < tmpConfDesc.length; i++) {
|
||||
if ((tmpConfDesc.equals(confDesc))
|
||||
&& (confDesc.iConfiguration > 0)) {
|
||||
int handle = LibusbWin.usb_open(dev);
|
||||
int handle = LibusbJava.usb_open(dev);
|
||||
sb.append("\nString descriptors\n");
|
||||
if (handle <= 0) {
|
||||
sb.append("\terror opening the device\n");
|
||||
break;
|
||||
}
|
||||
String configuration = LibusbWin
|
||||
String configuration = LibusbJava
|
||||
.usb_get_string_simple(handle,
|
||||
confDesc.iConfiguration);
|
||||
if (configuration == null)
|
||||
@@ -310,7 +310,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
||||
sb.append("\tiConfiguration: " + configuration
|
||||
+ "\n");
|
||||
|
||||
LibusbWin.usb_close(handle);
|
||||
LibusbJava.usb_close(handle);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -366,21 +366,21 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
|
||||
for (int k = 0; k < ints.length; k++) {
|
||||
if (tmpIntDescs[i].equals(intDesc)
|
||||
&& (intDesc.iInterface > 0)) {
|
||||
int handle = LibusbWin.usb_open(dev);
|
||||
int handle = LibusbJava.usb_open(dev);
|
||||
sb.append("\nString descriptors\n");
|
||||
if (handle <= 0) {
|
||||
sb
|
||||
.append("\terror opening the device\n");
|
||||
break;
|
||||
}
|
||||
String interface_ = LibusbWin
|
||||
String interface_ = LibusbJava
|
||||
.usb_get_string_simple(handle,
|
||||
intDesc.iInterface);
|
||||
if (interface_ == null)
|
||||
interface_ = "unable to fetch interface string";
|
||||
sb.append("\tiInterface: " + interface_
|
||||
+ "\n");
|
||||
LibusbWin.usb_close(handle);
|
||||
LibusbJava.usb_close(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import javax.swing.JTextArea;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import ch.ntb.usb.LibusbWin;
|
||||
import ch.ntb.usb.LibusbJava;
|
||||
import ch.ntb.usb.Usb_Bus;
|
||||
|
||||
public class UsbView extends JFrame {
|
||||
@@ -144,11 +144,11 @@ public class UsbView extends JFrame {
|
||||
.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent e) {
|
||||
// open bus
|
||||
LibusbWin.usb_init();
|
||||
LibusbWin.usb_find_busses();
|
||||
LibusbWin.usb_find_devices();
|
||||
LibusbJava.usb_init();
|
||||
LibusbJava.usb_find_busses();
|
||||
LibusbJava.usb_find_devices();
|
||||
|
||||
Usb_Bus bus = LibusbWin.usb_get_busses();
|
||||
Usb_Bus bus = LibusbJava.usb_get_busses();
|
||||
if (bus != null) {
|
||||
treeModel.fireTreeStructureChanged(bus);
|
||||
}
|
||||
@@ -166,11 +166,11 @@ public class UsbView extends JFrame {
|
||||
private JTree getUsbTree() {
|
||||
if (usbTree == null) {
|
||||
// open bus
|
||||
LibusbWin.usb_init();
|
||||
LibusbWin.usb_find_busses();
|
||||
LibusbWin.usb_find_devices();
|
||||
LibusbJava.usb_init();
|
||||
LibusbJava.usb_find_busses();
|
||||
LibusbJava.usb_find_devices();
|
||||
|
||||
Usb_Bus bus = LibusbWin.usb_get_busses();
|
||||
Usb_Bus bus = LibusbJava.usb_get_busses();
|
||||
|
||||
treeModel = new UsbTreeModel(bus, jPropertiesArea);
|
||||
usbTree = new JTree(treeModel);
|
||||
|
||||
Reference in New Issue
Block a user