Parcourir la source

Добавлен исходный код для работы с Id usb девайсов

ilysk il y a 8 ans
Parent
commit
ca2216cc2b

+ 2 - 1
.gitignore

@@ -1 +1,2 @@
-/nbproject/private/
+/nbproject/private/
+/build/

+ 9 - 1
nbproject/project.properties

@@ -27,9 +27,17 @@ dist.dir=dist
 dist.jar=${dist.dir}/SwingExample.jar
 dist.javadoc.dir=${dist.dir}/javadoc
 excludes=
+file.reference.commons-lang3-3.2.1.jar=C:\\Users\\ilysk\\Desktop\\Work&Learn\\Coding\\Java\\Libraries\\usb4java-1.2.0\\lib\\commons-lang3-3.2.1.jar
+file.reference.libusb4java-1.2.0-windows-x86.jar=C:\\Users\\ilysk\\Desktop\\Work&Learn\\Coding\\Java\\Libraries\\usb4java-1.2.0\\lib\\libusb4java-1.2.0-windows-x86.jar
+file.reference.libusb4java-1.2.0-windows-x86_64.jar=C:\\Users\\ilysk\\Desktop\\Work&Learn\\Coding\\Java\\Libraries\\usb4java-1.2.0\\lib\\libusb4java-1.2.0-windows-x86_64.jar
+file.reference.usb4java-1.2.0.jar=C:\\Users\\ilysk\\Desktop\\Work&Learn\\Coding\\Java\\Libraries\\usb4java-1.2.0\\lib\\usb4java-1.2.0.jar
 includes=**
 jar.compress=false
-javac.classpath=
+javac.classpath=\
+    ${file.reference.commons-lang3-3.2.1.jar}:\
+    ${file.reference.libusb4java-1.2.0-windows-x86.jar}:\
+    ${file.reference.libusb4java-1.2.0-windows-x86_64.jar}:\
+    ${file.reference.usb4java-1.2.0.jar}
 # Space-separated list of extra javac options
 javac.compilerargs=
 javac.deprecation=false

+ 42 - 0
src/project82usb/getUSBDevicesId.java

@@ -0,0 +1,42 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package project82usb;
+
+import org.usb4java.Context;
+import org.usb4java.Device;
+import org.usb4java.DeviceDescriptor;
+import org.usb4java.DeviceList;
+import org.usb4java.LibUsb;
+import org.usb4java.LibUsbException;
+
+/**
+ *
+ * @author ilysk
+ */
+public class getUSBDevicesId {
+    public static void tryusb4java() {
+        Context context = new Context();
+        int result = LibUsb.init(context);
+        if (result != LibUsb.SUCCESS) {
+            throw new LibUsbException("Unable to initialize libusb.", result);
+        }
+        DeviceList list = new DeviceList();
+        result = LibUsb.getDeviceList(null, list);
+        if (result < 0) throw new LibUsbException("Unable to get device list", result);
+        try {
+            // Iterate over all devices and scan for the right one
+            for (Device device: list) {
+                DeviceDescriptor descriptor = new DeviceDescriptor();
+                result = LibUsb.getDeviceDescriptor(device, descriptor);
+                if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to read device descriptor", result);
+                System.out.println(descriptor.idVendor()+" "+descriptor.idProduct());
+            }
+        } finally {
+            // Ensure the allocated device list is freed
+            LibUsb.freeDeviceList(list, true);
+        }
+    }
+}

+ 19 - 0
src/project82usb/main.java

@@ -0,0 +1,19 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package project82usb;
+
+import static project82usb.getUSBDevicesId.tryusb4java;
+
+/**
+ *
+ * @author ilysk
+ */
+
+public class main {
+    public static void main(String[] args){
+        tryusb4java();
+    }
+}