⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deviceimpl.java

📁 JAVA 访问USB JAVA 访问USB JAVA 访问USB JAVA 访问USB JAVA 访问USB JAVA 访问USB
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    // children and notify the bus                    if(Windows.debugEnum) System.out.println(" >> BEFORE <<  a different EXTERNAL HUB was connected to this (root)hub. Former Hub ID:" + oldDev.getUniqueDeviceID());                       if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> TO DO << remove all former chlidren of the hub and the hub itself too. Add the new hub.");                    removeAllChildren(oldDev.getChildren());                    bus.removeDevice(oldDev);                    // add the new hub                    // depending on the friendlyDeviceName we create either a JSUB instance or a NonJUSB instance                    if(friendlyDeviceName != null && friendlyDeviceName.startsWith(Windows.A_JUSB_DRIVER))                        dev = new JUSB(usb,this,devPath,devAddress,driverKeyName,friendlyDeviceName,uniqueID,portIndex);                    else                        dev = new NonJUSB(usb,this,devPath,devAddress,driverKeyName,friendlyDeviceName,uniqueID,portIndex);                    hub.children[portIndex-1] = dev;                    bus.addDevice(dev,devAddress);                    }                   else{                     // the device is still the same one                     // check if the children are identical                     // add it again as a child of this hub.                     hub.children[portIndex-1] = oldDev;                      if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> BEFORE <<  the same one : Check now if its children changed.");                                            checkChildren(oldDev);                                        }                }                else{                    // there was no hub attached before                    // add this new hub now to the bus                    if(Windows.debugEnum) System.out.println(" >> BEFORE <<   no connection");                    if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> TO DO << Add the new hub. This includes also all children, which are attached to this new hub.");                    if(friendlyDeviceName != null && friendlyDeviceName.startsWith(Windows.A_JUSB_DRIVER))                        dev = new JUSB(usb,this,devPath,devAddress,driverKeyName,friendlyDeviceName,uniqueID,portIndex);                    else                        dev = new NonJUSB(usb,this,devPath,devAddress,driverKeyName,friendlyDeviceName,uniqueID,portIndex);                                        hub.children[portIndex-1] = dev;                    bus.addDevice(dev,devAddress);                 }                                         }else if(devType == NO_DEVICE_CONNECTED){                // there is no device connected to this port                                //check if there was before a device connected to this port                if(Windows.debugEnum) System.out.print("DeviceImpl.enumerateHubPorts() >>> NOW on Port["+portIndex+"]<< No device connected" );                               if(oldChildren != null){                 oldDev = oldChildren[portIndex-1];                   }                else oldDev = null;                              if(oldDev != null ){                    // we had a device connected to the bus                    // but not anymore. remove it                    //check whether the device was a hub or just a simple device                    if(oldDev.getChildren() == null){                        if(Windows.debugEnum) System.out.println(" >> BEFORE <<  a DEVICE was connected to this (root)hub.Former Device ID:" + oldDev.getUniqueDeviceID());                        //just one device                        bus.removeDevice(oldDev);                    }                    else{                      if(Windows.debugEnum) System.out.println(" >> BEFORE <<  an EXTERNAL HUB was connected to this (root)hub. Former Hub ID:" + oldDev.getUniqueDeviceID());                       // it's a hub. remove the hub and all its children                       if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> TO DO << cremove all former chlidren of the hub and the hub itself too." );                       removeAllChildren(oldDev.getChildren());                       bus.removeDevice(oldDev);                    }                 }                 else  if(Windows.debugEnum) System.out.println(" >> BEFORE << also no connection");                                 // add null to the bus                hub.children[portIndex-1] = null;                if(Windows.debugDeviceImpl)                    System.out.println("DeviceImpl.enumerateHubPorts() >>> EnumPort:" + portIndex + "  Address:" + this.getAddress() + "  Device: null");                            }else{                if(Windows.debugDeviceImpl)                    System.out.println("DeviceImpl.enumerateHubPorts() >>> EnumPort:" + portIndex + "  Address:" + this.getAddress() + "  Device: null");                              throw new USBException("Unknown Device Type! Device Error Reason: " + devType,devType);            }        }// end for          // at this point we did enuerate all Devices but only if the hub.getAddress is 0        // this is used for synchronization while scanning the bus        if(hub.getAddress() == 0) bus.setFinishEnumerating();     }        /** Returns the device path of that device     * @return The device path or null     */        public String getDevicePath(){        return this.usbDevicePath;    }        /** Returns the friendly device name     * @return The friendly device name or null     */        public String getDeviceFriendlyName(){     return this.friendlyDeviceName;       }        /** Returns the unique ID     * @return The unique ID String or null     */        public String getUniqueDeviceID(){     return this.uniqueDevID;       }        private DeviceImpl [] getChildren(){      return children;    }        /** Removes all the children from the bus     * @param children All the children of this hub     */        synchronized void removeAllChildren(DeviceImpl children[]){     DeviceImpl dev;       if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> remove all children of this hub! numOfChildren= " + children.length);     for(int i=0; i < children.length; i++){                dev = children[i];       if(dev != null){          if(dev.getChildren() != null){              if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> there was a HUB on Port[ "+ dev.getHubPortNum()+ "]. remove it from the list! Device: " + dev.getUniqueDeviceID() + " Addr[" + dev.getAddress() + "]");              removeAllChildren(dev.getChildren());          }          else{              if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> there was a DEVICE on Port[ "+ dev.getHubPortNum()+ "]. remove it from the list! Device: " + dev.getUniqueDeviceID() + " Addr[" + dev.getAddress() + "]");              usb.removeDevice(dev);          }       }       else{         if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> The " + i + ".th DEVICE was null");       }     }    }        /**     * The hub is identical, we therefore have to check if the children     * are still the same and when not doing the necessary changes.     * We get a current handle to the hub and let enumerate the hub      * recursivly.     *     */    void checkChildren(DeviceImpl hub) throws IOException{       int hubHandle = hub.openHandle(hub.getDevicePath());      if(hubHandle == USBException.ERROR_INVALID_HANDLE)                throw new USBException("INVALID_HANDLE_VALUE for external hub ",hubHandle);                  if(Windows.debugDeviceImpl) System.out.println("DeviceImpl.checkChildren() >>> External Hub (hubHandle:" + hubHandle + "numPorts:" + this.numPorts+")");      this.enumerateHubPorts(usb, hubHandle,hub,hub.getNumPorts());      // close the hub handle      this.closeHandle(hubHandle);    }        /** For debugging purposes */        synchronized void showAllChildren(DeviceImpl children[]){     DeviceImpl dev;       if(Windows.debugEnum) System.out.println("DeviceImpl.checkChildren() >>> show all children of this hub! numOfChildren= " + children.length);     for(int i=0; i < children.length; i++){                dev = children[i];       if(dev != null){          if(dev.getChildren() != null){              if(Windows.debugEnum) System.out.println("DeviceImpl.checkChildren() >>> there is a HUB on Port[ "+ dev.getHubPortNum()+ "].  Device: " + dev.getUniqueDeviceID() + " Addr[" + dev.getAddress() + "]");              showAllChildren(dev.getChildren());          }          else{              if(Windows.debugEnum) System.out.println("DeviceImpl.checkChildren() >>> there is a DEVICE on Port[ "+ dev.getHubPortNum()+ "]. Device: " + dev.getUniqueDeviceID() + " Addr[" + dev.getAddress() + "]");          }       }       else{         if(Windows.debugEnum) System.out.println("DeviceImpl.checkChildren() >>> The " + i + ".th DEVICE was null");       }     }    }       private void printDevices(DeviceImpl [] dev) {        try{        if(dev != null){                int length;            if(dev.length < 7) length = dev.length;            else length = 8;            for(int i = 0; i < length; i++){               if(dev[i] != null){                   if(dev[i].getAddress() == 0)        System.out.println(" [ROOT]          numOfPort:" + dev[i].getNumPorts()+"  Address:" + dev[i].getAddress());                   else if(dev[i].getNumPorts() > 0)   System.out.println(" [EXTERNAL HUB]  numOfPort:" + dev[i].getNumPorts()+"  Address:" + dev[i].getAddress() + "  UniqueID[" + dev[i].getUniqueDeviceID() + "]");                   else System.out.println(" [USB DEVICE]                 Address:" + dev[i].getAddress() + "  UniqueID[" + dev[i].getUniqueDeviceID() + "]");                }               else System.out.println(" [NULL] ");            }          }        }catch(Exception e){	    e.printStackTrace ();        }    }       /**     * print a Byte Array to String     * main purpose is for debugging matters     * name: The name of the array, just for clarifying the output     * radix: 0: decimal 2: binary (default 2)     * numOfByteLine: the number of Byte printed at one line     */    public void printByteArray(byte buf[], String title,int radix, int numOfBytesLine){              if(buf != null){        String temp = null;       if(radix != 0 && radix != 2 && radix!=16) radix = 2;              if(title != null) System.out.println(title);       for(int i=0; i<buf.length; i++){                      if(radix == 2){                temp = Integer.toBinaryString((int)buf[i]);                if(temp.length() > 8){                    temp = temp.substring(temp.length() - 8, temp.length());                }                else if(temp.length() < 8){                    for(int k=temp.length(); k < 8; k++)                       temp = "0" + temp;                 }           }                      if(radix == 16){                temp = Integer.toHexString((int)buf[i]);                if(temp.length() > 2){                    temp = temp.substring(temp.length() - 2, temp.length());                }                if(temp.length() < 2){                    for(int k=temp.length(); k < 2; k++)                       temp = "0" + temp;                 }           }                                 if(radix == 0) System.out.print(buf[i] + "   ");           else System.out.print(temp + "   ");                      if(i > 0 && (i % numOfBytesLine) == 0) System.out.println();       }              System.out.println();        }       else System.out.println("Buffer is Empty: buf == null!!!");     }            /** Not implemented yet!<br>     * Returns always null!     */    public String getSpeed() {        return null;    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -