Parcourir la source

Инициализация устройств, вывод в таблицу

Илья Егоров il y a 8 ans
Parent
commit
de8a33e07a

+ 5 - 4
nbproject/project.properties

@@ -1,9 +1,10 @@
 annotation.processing.enabled=true
 annotation.processing.enabled.in.editor=false
-annotation.processing.processor.options=
 annotation.processing.processors.list=
 annotation.processing.run.all.processors=true
 annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+application.title=SwingExample
+application.vendor=User
 build.classes.dir=${build.dir}/classes
 build.classes.excludes=**/*.java,**/*.form
 # This directory is removed when the project is cleaned:
@@ -26,11 +27,11 @@ dist.archive.excludes=
 dist.dir=dist
 dist.jar=${dist.dir}/SwingExample.jar
 dist.javadoc.dir=${dist.dir}/javadoc
+endorsed.classpath=
 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-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-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.usb-api-1.0.2.jar=C:\\Users\\User\\Desktop\\libusb\\usb-api-1.0.2.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
@@ -43,7 +44,6 @@ javac.classpath=\
     ${file.reference.libusb4java-1.2.0-windows-x86.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}:\
     ${file.reference.usb-api-1.0.2.jar}:\
@@ -51,6 +51,7 @@ javac.classpath=\
 # Space-separated list of extra javac options
 javac.compilerargs=
 javac.deprecation=false
+javac.external.vm=false
 javac.processorpath=\
     ${javac.classpath}
 javac.source=1.8
@@ -71,7 +72,7 @@ javadoc.splitindex=true
 javadoc.use=true
 javadoc.version=false
 javadoc.windowtitle=
-main.class=project82usb.devMatrix
+main.class=initDevices.initFrame
 manifest.file=manifest.mf
 meta.inf.dir=${src.dir}/META-INF
 mkdist.disabled=false

+ 13 - 0
src/project82usb/devMatrix.form

@@ -3,6 +3,7 @@
 <Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
   <Properties>
     <Property name="defaultCloseOperation" type="int" value="3"/>
+    <Property name="resizable" type="boolean" value="false"/>
   </Properties>
   <SyntheticProperties>
     <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
@@ -65,12 +66,24 @@
       <SubComponents>
         <Component class="javax.swing.JTable" name="devTable">
           <Properties>
+            <Property name="autoCreateRowSorter" type="boolean" value="true"/>
+            <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
+              <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
+                <EmptyBorder/>
+              </Border>
+            </Property>
+            <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
+              <Font name="Verdana" size="14" style="1"/>
+            </Property>
             <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
               <Table columnCount="0" rowCount="0"/>
             </Property>
             <Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
               <TableColumnModel selectionModel="0"/>
             </Property>
+            <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
+              <Color id="Default Cursor"/>
+            </Property>
             <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
               <TableHeader reorderingAllowed="true" resizingAllowed="true"/>
             </Property>

+ 25 - 6
src/project82usb/devMatrix.java

@@ -3,25 +3,39 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package project82usb;
+package devTable;
 
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.RowSorter;
+import javax.swing.SortOrder;
 import javax.swing.table.TableModel;
+import javax.swing.table.TableRowSorter;
+import project82usb.devList;
 
 /**
  *
  * @author egorov
  */
 public class devMatrix extends javax.swing.JFrame {
-    private final devList list;
+    private static devList list;
+    private static devList filter;
     devTableModel myModel;
     /**
      * Creates new form devicesmatrix
+     * @param filter
      */
-    public devMatrix() {
-        list = new devList();
+    public devMatrix(devList filter) {
+        this.filter = filter;
+        list = new devList(this.filter.getDevList(),devList.FILTER);
         myModel = new devTableModel(list);
+        TableRowSorter<TableModel> sorter = new TableRowSorter<>(myModel); 
         initComponents();
         devTable.setModel(myModel);
+        devTable.setRowSorter(sorter);
+        List<RowSorter.SortKey> sortKeys = new ArrayList<>();
+        sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
+        sorter.setSortKeys(sortKeys);
     }
 
     /**
@@ -41,7 +55,11 @@ public class devMatrix extends javax.swing.JFrame {
         btnRefresh = new javax.swing.JButton();
 
         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+        setResizable(false);
 
+        devTable.setAutoCreateRowSorter(true);
+        devTable.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
+        devTable.setFont(new java.awt.Font("Verdana", 1, 14)); // NOI18N
         devTable.setModel(new javax.swing.table.DefaultTableModel(
             new Object [][] {
 
@@ -50,6 +68,7 @@ public class devMatrix extends javax.swing.JFrame {
 
             }
         ));
+        devTable.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
         jScrollPane1.setViewportView(devTable);
 
         tvOut.setEditable(false);
@@ -108,7 +127,7 @@ public class devMatrix extends javax.swing.JFrame {
     }//GEN-LAST:event_btnClearActionPerformed
 
     private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
-        this.list.update();
+        this.list.update(this.filter.getDevList());
         this.addTextTvOut(list.toString());
         myModel.fireTableDataChanged();
     }//GEN-LAST:event_btnRefreshActionPerformed
@@ -144,7 +163,7 @@ public class devMatrix extends javax.swing.JFrame {
         /* Create and display the form */
         java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
-                new devMatrix().setVisible(true);
+                new devMatrix(list).setVisible(true);
             }
         });
     }

+ 9 - 3
src/project82usb/devTableModel.java

@@ -3,10 +3,11 @@
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */
-package project82usb;
+package devTable;
 
 import javax.swing.table.AbstractTableModel;
 import java.util.*;
+import project82usb.devList;
 
 /**
  *
@@ -28,13 +29,18 @@ public class devTableModel extends AbstractTableModel{
         return 4;
     }
     
+    @Override
     public int getRowCount(){
-        return this.list.getListSize();
+        if(this.list.getDevList()==null){
+            return 0;
+        } else{
+            return this.list.getListSize();
+        }
     }
     
     public Object getValueAt(int row, int col){
         switch(col){
-            case 0: return list.getDevice(row).getUsbHub().toString().substring(9);
+            case 0: return list.getDevice(row).getUsbHub().toString().substring(8);
             case 1: return list.getDevice(row).getPort();
             case 2: return list.getDevice(row).getStringIdProduct();
             case 3: return list.getDevice(row).getStringIdVendor();

+ 31 - 0
src/initDevices/initCalc.java

@@ -0,0 +1,31 @@
+/*
+ * 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 initDevices;
+
+import java.util.ArrayList;
+import project82usb.devList;
+import project82usb.usbDevice;
+
+/**
+ *
+ * @author User
+ */
+public class initCalc {
+    public static devList mix(devList before, devList after){
+        ArrayList<usbDevice> ll = new ArrayList<>();
+        for(usbDevice bDev: before.getDevList()){
+            boolean inList=false;
+            for(usbDevice aDev: after.getDevList()){
+                if(bDev.equalsPidVid(aDev)){
+                    inList=true;
+                    break;
+                } 
+            }
+            if(!inList) ll.add(bDev);
+        }
+        return new devList(ll,devList.BASE_LIST);
+    }
+}

+ 71 - 0
src/initDevices/initFrame.form

@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
+  <Properties>
+    <Property name="defaultCloseOperation" type="int" value="3"/>
+    <Property name="title" type="java.lang.String" value="&#x418;&#x43d;&#x438;&#x446;&#x438;&#x430;&#x43b;&#x438;&#x437;&#x430;&#x446;&#x438;&#x44f;"/>
+  </Properties>
+  <SyntheticProperties>
+    <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+    <SyntheticProperty name="generateCenter" type="boolean" value="false"/>
+  </SyntheticProperties>
+  <AuxValues>
+    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
+    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
+    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+  </AuxValues>
+
+  <Layout>
+    <DimensionLayout dim="0">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <Group type="102" alignment="1" attributes="0">
+              <EmptySpace pref="357" max="32767" attributes="0"/>
+              <Component id="btnStep1" min="-2" max="-2" attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
+          </Group>
+          <Component id="jScrollPane2" alignment="0" max="32767" attributes="0"/>
+      </Group>
+    </DimensionLayout>
+    <DimensionLayout dim="1">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <Group type="102" alignment="1" attributes="0">
+              <Component id="jScrollPane2" pref="166" max="32767" attributes="0"/>
+              <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
+              <Component id="btnStep1" min="-2" max="-2" attributes="0"/>
+              <EmptySpace min="-2" max="-2" attributes="0"/>
+          </Group>
+      </Group>
+    </DimensionLayout>
+  </Layout>
+  <SubComponents>
+    <Component class="javax.swing.JButton" name="btnStep1">
+      <Properties>
+        <Property name="text" type="java.lang.String" value="&#x414;&#x430;&#x43b;&#x435;&#x435;"/>
+      </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnStep1ActionPerformed"/>
+      </Events>
+    </Component>
+    <Container class="javax.swing.JScrollPane" name="jScrollPane2">
+      <AuxValues>
+        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
+      </AuxValues>
+
+      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+      <SubComponents>
+        <Component class="javax.swing.JTextArea" name="tvOut">
+          <Properties>
+            <Property name="columns" type="int" value="20"/>
+            <Property name="rows" type="int" value="5"/>
+          </Properties>
+        </Component>
+      </SubComponents>
+    </Container>
+  </SubComponents>
+</Form>

+ 141 - 0
src/initDevices/initFrame.java

@@ -0,0 +1,141 @@
+/*
+ * 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 initDevices;
+import devTable.devMatrix;
+import static initDevices.initCalc.mix;
+import java.util.ArrayList;
+import project82usb.*;
+/**
+ *
+ * @author User
+ */
+public class initFrame extends javax.swing.JFrame{
+    private boolean firstList = false;
+    private devList before;
+    private devList after;
+    private devList filterList;
+
+    /**
+     * Creates new form initFrame
+     */
+    public initFrame() {
+        this.before=null;
+        this.after=null;
+        this.filterList=null;
+        initComponents();
+        tvOut.setText("**Подключите устройства ко всем портам хаба**\n\n");
+    }
+
+    /**
+     * 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() {
+
+        btnStep1 = new javax.swing.JButton();
+        jScrollPane2 = new javax.swing.JScrollPane();
+        tvOut = new javax.swing.JTextArea();
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+        setTitle("Инициализация");
+
+        btnStep1.setText("Далее");
+        btnStep1.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                btnStep1ActionPerformed(evt);
+            }
+        });
+
+        tvOut.setColumns(20);
+        tvOut.setRows(5);
+        jScrollPane2.setViewportView(tvOut);
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
+        getContentPane().setLayout(layout);
+        layout.setHorizontalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addContainerGap(357, Short.MAX_VALUE)
+                .addComponent(btnStep1)
+                .addContainerGap())
+            .addComponent(jScrollPane2)
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(btnStep1)
+                .addContainerGap())
+        );
+
+        pack();
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void btnStep1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStep1ActionPerformed
+        if(!this.firstList){
+            this.before = new devList();
+            this.firstList=true;
+            tvOut.setText("**Отключите все устройства от хаба**\n\n"
+                + "Учтите, что список портов может быть некорректен.\n"+
+                "Если будут одинаковые порты, перезапустите программу.\nЭто некорректная работа либо моего хаба, либо API\n");
+        } else {
+            this.after = new devList();
+            System.out.println("AFTER LIST:::"+this.after.toString());
+            this.filterList = mix(before,after);
+            this.filterList.toNull();
+            System.out.println("FILTER LIST:::"+this.filterList.toString());
+            new devMatrix(this.filterList).setVisible(true);
+            this.setVisible(false);
+        }
+    }//GEN-LAST:event_btnStep1ActionPerformed
+
+    /**
+     * @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(initFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (InstantiationException ex) {
+            java.util.logging.Logger.getLogger(initFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (IllegalAccessException ex) {
+            java.util.logging.Logger.getLogger(initFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+            java.util.logging.Logger.getLogger(initFrame.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 initFrame().setVisible(true);
+            }
+        });
+    }
+    
+    
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JButton btnStep1;
+    private javax.swing.JScrollPane jScrollPane2;
+    private javax.swing.JTextArea tvOut;
+    // End of variables declaration//GEN-END:variables
+}

+ 65 - 9
src/project82usb/devList.java

@@ -5,23 +5,54 @@
  */
 package project82usb;
 import java.util.*;
+import javax.usb.UsbHub;
 /**
  *
  * @author User
  */
 public class devList {
+    public static final String FILTER ="filter";
+    public static final String BASE_LIST = "base_list";
     private ArrayList<usbDevice> list;
     private final devListLow low;
     private final devListHigh high;
+    
+    public devList(ArrayList<usbDevice> filter, String key){
+        switch(key){
+            case devList.FILTER: {
+                this.low = new devListLow();
+                this.high = new devListHigh();
+                this.list=mix(this.low,this.high);
+                this.filter(filter);
+                break;
+            }
+            case devList.BASE_LIST: {
+                this.low=null;
+                this.high=null;
+                this.list=filter;
+                break;
+            }
+            default: {
+                this.low=null;
+                this.high=null;
+                this.list=null;
+            }
+        }    
+    }
     public devList(){
         this.low = new devListLow();
         this.high = new devListHigh();
         this.list = mix(this.low,this.high);
     }
+    public devList(UsbHub root){
+        this.low = new devListLow();
+        this.high = new devListHigh(root);
+        this.list = mix(this.low,this.high);
+    }
     private ArrayList<usbDevice> mix(devListLow low,devListHigh high){
         ArrayList<usbDevice> finalList = new ArrayList<>();
         for(usbDevice hDev: high.getDevListHigh()){
-            if(hDev.getIdProduct()==0&&hDev.getIdVendor()==0){
+            if(hDev.getIdProduct()==0||hDev.getIdVendor()==0){
                 finalList.add(hDev);
             } else {
                 for(usbDevice lDev: low.getDevListLow()){
@@ -35,15 +66,12 @@ public class devList {
         }
         return finalList;
     }
-    public void toTable(devMatrix out){
-        
-    }
+    @Override
     public String toString(){
         String result="";
         result+="Printing device list:\n";
         for(usbDevice device:this.list){
             result+=device.toString();
-            //result+=device.getUsbHub().toString().substring(9)+"; device "+device.getStringIdProduct()+":"+device.getStringIdVendor()+" on port #"+device.getPort()+"\n";
         }
         return result;
     }
@@ -53,9 +81,37 @@ public class devList {
     public usbDevice getDevice(int i){
         return this.list.get(i);
     }
-    public void update(){
-        this.low.update();
-        this.high.update();
-        this.list = mix(this.low,this.high);
+    public void update(ArrayList<usbDevice> filter){
+        if(this.low!=null&&this.high!=null){
+            this.low.update();
+            this.high.update();
+            this.list = mix(this.low,this.high);
+        }
+        if(filter!=null) this.filter(filter);
+    }
+    public ArrayList<usbDevice> getDevList(){
+        return this.list;
+    }
+    public void toNull(){
+        ArrayList<usbDevice> newList = new ArrayList<>();
+        for(usbDevice device: this.list){
+            newList.add(new usbDevice((short)0,(short)0,device.getPort(),device.getUsbHub()));
+        }
+        this.list=newList;
+    }
+    private void filter(ArrayList<usbDevice> filt) {
+        ArrayList<usbDevice> newDev = new ArrayList<>();
+        for(usbDevice fDev: filt){
+            boolean isAdded=false;
+            for(usbDevice tDev: this.list){
+                if(tDev.getUsbHub()==fDev.getUsbHub()&&tDev.getPort()==fDev.getPort()){
+                    newDev.add(tDev);
+                    isAdded=true;
+                    break;
+                }
+            }
+            if(!isAdded) newDev.add(fDev);
+        }
+        this.list=newDev;
     }
 }

+ 16 - 3
src/project82usb/devListHigh.java

@@ -10,8 +10,7 @@ import java.util.*;
  *
  * @author egorov
  */
-public class devListHigh {
-    private static final String PREFIX = "        ";         
+public class devListHigh {     
     private final UsbHub rootHub;
     private final ArrayList<usbDevice> devList;
     
@@ -20,6 +19,11 @@ public class devListHigh {
         this.devList = new ArrayList<>();
         this.makeDevListHigh(rootHub);
     }
+    public devListHigh(UsbHub root){
+        this.rootHub = VirtualRootUsbHub();
+        this.devList = new ArrayList<>();
+        this.makeDevListHigh(root);
+    }
     private UsbHub VirtualRootUsbHub(){
         UsbServices services = null;
         UsbHub VirtualRootUsbHub = null;
@@ -57,7 +61,7 @@ public class devListHigh {
            UsbPort port = (UsbPort) usbPorts.get(i);
            //Проверяем, подключены ли к порту устройства
            if(!port.isUsbDeviceAttached()){
-                usbDevice tDev = new usbDevice((short)0,(short)0,device.getParentUsbPort().getPortNumber(),device.getParentUsbPort().getUsbHub());
+                usbDevice tDev = new usbDevice((short)0,(short)0,port.getPortNumber(),device.getParentUsbPort().getUsbHub());
                 this.devList.add(tDev);
                 return;
            } else{
@@ -72,4 +76,13 @@ public class devListHigh {
         this.devList.clear();
         this.makeDevListHigh(rootHub);
     }
+    @Override
+    public String toString(){
+        String result="";
+        result+="Printing device list:\n";
+        for(usbDevice device:this.devList){
+            result+=device.toString();
+        }
+        return result;
+    }
 }

+ 10 - 0
src/project82usb/devListLow.java

@@ -21,6 +21,7 @@ import javax.usb.*;
 public class devListLow {
     private final UsbHub defaultHub = null;
     private final ArrayList<usbDevice> devList;
+    
     public devListLow(){
         this.devList = new ArrayList<>();
         this.makeDevListLow();
@@ -55,4 +56,13 @@ public class devListLow {
     public void update(){
         this.makeDevListLow();
     }
+    @Override
+    public String toString(){
+        String result="";
+        result+="Printing device list:\n";
+        for(usbDevice device:this.devList){
+            result+=device.toString();
+        }
+        return result;
+    }
 }

+ 1 - 1
src/project82usb/usbDevice.java

@@ -54,7 +54,7 @@ public class usbDevice {
     }
     @Override
     public String toString(){
-        return PREFIX+"-Hub:   "+this.hub.toString().substring(9)
+        return PREFIX+"-Hub:   "+this.hub.toString().substring(8)
                 +"\n"+PREFIX+PREFIX+"-Port:   "+this.port
                 +"\n"+PREFIX+PREFIX+PREFIX+"-Device:   "+this.getStringIdProduct()+":"+this.getStringIdVendor()+"\n";
     }