Просмотр исходного кода

Дополнил класс usbDevice, удалил пакет javaapp1, в getUsbDevicesId.java добавил номер порта

Илья Егоров лет назад: 8
Родитель
Сommit
d529513061

+ 10 - 4
nbproject/project.properties

@@ -28,16 +28,22 @@ dist.jar=${dist.dir}/SwingExample.jar
 dist.javadoc.dir=${dist.dir}/javadoc
 dist.javadoc.dir=${dist.dir}/javadoc
 excludes=
 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.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.commons-lang3-3.2.1.jar-1=C:\\Users\\User\\Desktop\\libusb\\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.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.libusb4java-1.2.0-windows-x86.jar-1=C:\\Users\\User\\Desktop\\libusb\\libusb4java-1.2.0-windows-x86.jar
+file.reference.libusb4java-1.2.0-windows-x86_64.jar-1=C:\\Users\\User\\Desktop\\libusb\\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
 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
+file.reference.usb4java-1.2.0.jar-1=C:\\Users\\User\\Desktop\\libusb\\usb4java-1.2.0.jar
 includes=**
 includes=**
 jar.compress=false
 jar.compress=false
 javac.classpath=\
 javac.classpath=\
     ${file.reference.commons-lang3-3.2.1.jar}:\
     ${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.jar}:\
-    ${file.reference.libusb4java-1.2.0-windows-x86_64.jar}:\
-    ${file.reference.usb4java-1.2.0.jar}
+    ${file.reference.usb4java-1.2.0.jar}:\
+    ${file.reference.commons-lang3-3.2.1.jar-1}:\
+    ${file.reference.libusb4java-1.2.0-windows-x86.jar-1}:\
+    ${file.reference.libusb4java-1.2.0-windows-x86_64.jar-1}:\
+    ${file.reference.usb4java-1.2.0.jar-1}
 # Space-separated list of extra javac options
 # Space-separated list of extra javac options
 javac.compilerargs=
 javac.compilerargs=
 javac.deprecation=false
 javac.deprecation=false
@@ -61,7 +67,7 @@ javadoc.splitindex=true
 javadoc.use=true
 javadoc.use=true
 javadoc.version=false
 javadoc.version=false
 javadoc.windowtitle=
 javadoc.windowtitle=
-main.class=javaapp1.Frame1
+main.class=project82usb.main
 manifest.file=manifest.mf
 manifest.file=manifest.mf
 meta.inf.dir=${src.dir}/META-INF
 meta.inf.dir=${src.dir}/META-INF
 mkdist.disabled=false
 mkdist.disabled=false

+ 0 - 139
src/javaapp1/Frame1.java

@@ -1,139 +0,0 @@
-/*
- * 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 javaapp1;
-
-/**
- *
- * @author Анастасия
- */
-public class Frame1 extends javax.swing.JFrame {
-
-    boolean btext = true; // добавим логическую переменную
-    
-    /**
-     * Creates new form Frame1
-     */
-    public Frame1() {
-        initComponents();
-    }
-
-    /**
-     * This method is called from within the constructor to initialize the form.
-     * WARNING: Do NOT modify this code. The content of this method is always
-     * regenerated by the Form Editor.
-     */
-    @SuppressWarnings("unchecked")
-    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
-    private void initComponents() {
-
-        jButton1 = new javax.swing.JButton();
-        jButton2 = new javax.swing.JButton();
-        jLabel1 = new javax.swing.JLabel();
-
-        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
-
-        jButton1.setText("Вывод текста");
-        jButton1.addActionListener(new java.awt.event.ActionListener() {
-            public void actionPerformed(java.awt.event.ActionEvent evt) {
-                jButton1ActionPerformed(evt);
-            }
-        });
-
-        jButton2.setText("Открытие окна");
-        jButton2.addActionListener(new java.awt.event.ActionListener() {
-            public void actionPerformed(java.awt.event.ActionEvent evt) {
-                jButton2ActionPerformed(evt);
-            }
-        });
-
-        jLabel1.setText("   ");
-
-        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
-        getContentPane().setLayout(layout);
-        layout.setHorizontalGroup(
-            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addGroup(layout.createSequentialGroup()
-                .addGap(64, 64, 64)
-                .addComponent(jButton2)
-                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-                    .addGroup(layout.createSequentialGroup()
-                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 102, Short.MAX_VALUE)
-                        .addComponent(jLabel1)
-                        .addGap(114, 114, 114))
-                    .addGroup(layout.createSequentialGroup()
-                        .addGap(54, 54, 54)
-                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
-                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
-        );
-        layout.setVerticalGroup(
-            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addGroup(layout.createSequentialGroup()
-                .addGap(93, 93, 93)
-                .addComponent(jLabel1)
-                .addGap(59, 59, 59)
-                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-                    .addComponent(jButton2)
-                    .addComponent(jButton1))
-                .addContainerGap(111, Short.MAX_VALUE))
-        );
-
-        pack();
-    }// </editor-fold>//GEN-END:initComponents
-
-    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
-     jLabel1.setText("Here was Ilya Lysko!");
-     if(btext) {jLabel1.setText("Hello"); btext=false;} // если btext=true, записываем в наш JLabel запись, меняем btext на false      
-     else{jLabel1.setText(""); btext=true;}  // в ином случае, записываем пустой текст в JLabel, меняем btext на true
-
-    }//GEN-LAST:event_jButton1ActionPerformed
-
-    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
-      this.dispose();  // закрываем 1 окно
-      Frame2 fr = new Frame2(); // экземпляр класса 2 окна
-      fr.setVisible(true);   // делаем его видимым
-    }//GEN-LAST:event_jButton2ActionPerformed
-
-    /**
-     * @param args the command line arguments
-     */
-    public static void main(String args[]) {
-        /* Set the Nimbus look and feel */
-        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
-        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
-         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
-         */
-        try {
-            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
-                if ("Nimbus".equals(info.getName())) {
-                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
-                    break;
-                }
-            }
-        } catch (ClassNotFoundException ex) {
-            java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-        } catch (InstantiationException ex) {
-            java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-        } catch (IllegalAccessException ex) {
-            java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
-            java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-        }
-        //</editor-fold>
-
-        /* Create and display the form */
-        java.awt.EventQueue.invokeLater(new Runnable() {
-            public void run() {
-                new Frame1().setVisible(true);
-            }
-        });
-    }
-
-    // Variables declaration - do not modify//GEN-BEGIN:variables
-    private javax.swing.JButton jButton1;
-    private javax.swing.JButton jButton2;
-    private javax.swing.JLabel jLabel1;
-    // End of variables declaration//GEN-END:variables
-}

+ 0 - 62
src/javaapp1/Frame2.java

@@ -1,62 +0,0 @@
-/*
- * 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 javaapp1;
-
-/**
- *
- * @author Анастасия
- */
-public class Frame2 extends javax.swing.JFrame {
-
-    /**
-     * Creates new form Frame2
-     */
-    public Frame2() {
-        initComponents();
-    }
-
-    /**
-     * This method is called from within the constructor to initialize the form.
-     * WARNING: Do NOT modify this code. The content of this method is always
-     * regenerated by the Form Editor.
-     */
-    @SuppressWarnings("unchecked")
-    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
-    private void initComponents() {
-
-        jLabel1 = new javax.swing.JLabel();
-
-        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
-
-        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
-        jLabel1.setText("Новое окно");
-
-        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
-        getContentPane().setLayout(layout);
-        layout.setHorizontalGroup(
-            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addGroup(layout.createSequentialGroup()
-                .addGap(140, 140, 140)
-                .addComponent(jLabel1)
-                .addContainerGap(165, Short.MAX_VALUE))
-        );
-        layout.setVerticalGroup(
-            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addGroup(layout.createSequentialGroup()
-                .addGap(119, 119, 119)
-                .addComponent(jLabel1)
-                .addContainerGap(159, Short.MAX_VALUE))
-        );
-
-        pack();
-    }// </editor-fold>//GEN-END:initComponents
-
-   
-
-    // Variables declaration - do not modify//GEN-BEGIN:variables
-    private javax.swing.JLabel jLabel1;
-    // End of variables declaration//GEN-END:variables
-}

+ 1 - 1
src/project82usb/getUSBDevicesId.java

@@ -35,7 +35,7 @@ public class getUSBDevicesId {
                 result = LibUsb.getDeviceDescriptor(device, descriptor);
                 result = LibUsb.getDeviceDescriptor(device, descriptor);
                 if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to read device descriptor", result);
                 if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to read device descriptor", result);
                 
                 
-                System.out.println(descriptor.idVendor()+" "+descriptor.idProduct());
+                System.out.println(descriptor.idVendor()+" "+descriptor.idProduct()+" on port #"+LibUsb.getPortNumber(device));
             }
             }
         } finally {
         } finally {
             // Ensure the allocated device list is freed
             // Ensure the allocated device list is freed

+ 1 - 1
src/project82usb/main.java

@@ -14,6 +14,6 @@ import static project82usb.getUSBDevicesId.tryusb4java;
 
 
 public class main {
 public class main {
     public static void main(String[] args){
     public static void main(String[] args){
-        tryusb4java();
+        String[] tryusb4java = tryusb4java();
     }
     }
 }
 }

+ 8 - 3
src/project82usb/usbDevice.java

@@ -12,14 +12,19 @@ package project82usb;
 public class usbDevice {
 public class usbDevice {
     private short idVendor;
     private short idVendor;
     private short idProduct;
     private short idProduct;
-    public usbDevice(short idVendor, short idProduct){
+    private byte port;
+    public usbDevice(short idVendor, short idProduct, byte port){
         this.idVendor=idVendor;
         this.idVendor=idVendor;
         this.idProduct=idProduct;
         this.idProduct=idProduct;
+        this.port=port;
     }
     }
-    public int getIdVendor(){
+    public short getIdVendor(){
         return this.idVendor;
         return this.idVendor;
     }
     }
-    public int getIdProduct(){
+    public short getIdProduct(){
         return this.idProduct;
         return this.idProduct;
     }
     }
+    public byte port(){
+        return this.port;
+    }
 }
 }