?? deviceimpl.java
字號(hào):
/* * DeviceImpl.java * * Created on 15. Juli 2003, 16:35 *//* * Java USB Library * Copyright (C) 2000 by David Brownell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package usb.windows;import java.io.IOException;import java.util.Hashtable;import java.util.Locale;import usb.core.*;import usb.util.LangCode;/** * Provides access to all USB devices on a bus in limited fashion.<br> * The device descriptor and configuration descriptor provides more information * to the devices which are attached to the bus. <br> * The devices itself are instances of the subclass NonJUSB when not using the * jUSB driver and of the subclass JUSB when using the jUSB driver. * * @author Mike Stahl * @version $id: DeviceImpl.java, v1.0 Created on 15. Juli 2003, 16:37 */public class DeviceImpl extends Device { /** * Corresponds to a hub port and indicates that no device is connected to that * port. */ public static final int NO_DEVICE_CONNECTED = 1; /** Corresponds to a hub port and indicates that an external hub is connected to that * port. */ public static final int EXTERNAL_HUB = 2; /** Corresponds to a hub port and indicates that a device is connected to that * port. */ /** * The number of ports on this hub, or zero if it's a device */ private int numPorts; /** * The hub port number to which this device or hub is connected */ private int hubPortNumber; /** * The bus to which this device or hub is connected */ private final USB usb; /** * The devices that were on the USB before the scan */ private static DeviceImpl oldDevices [] = new DeviceImpl [127]; /** * usbDevicePath corresponds to the Windows DevicePath for this device */ private String usbDevicePath; /** * This id is unique to every usb device. It is used to find out if something * changed on the bus. */ private String uniqueDevID; /** * The Windows driverKeyName for that device */ private String driverKeyName; /** * Friendly Name of the Driverkey */ private String friendlyDeviceName; private DeviceImpl hub; private DeviceImpl children[]; /** The device descriptor */ public DeviceDescriptor descriptor; /** The configuration descriptor */ public Configuration configuration; /** used to create an instance of the root hub * @param bus The bus this device belongs to * @param devicePath The Windows OS specific device path for that device * @param address The device address (should be always 0, because this constructor is only called * to create the root hub) * @param devices Contains the current structure of the bus. Is used to compare if device have * been removed or attached during the last scan. * @throws IOException An exception is raised when we could not get a handle to the root hub */ DeviceImpl(USB bus, String devicePath, int address,DeviceImpl devices[]) throws IOException { super (null, bus, address); this.usb = bus; this.usbDevicePath = devicePath; this.hubPortNumber = 0; this.driverKeyName = null; this.friendlyDeviceName = "Root Hub"; this.oldDevices = devices; this.hub = null; if(Windows.debugDeviceImpl){ System.out.println("DeviceImpl.Constructor() ROOT >>> Bus[ " +usb.getBusNum() + "] --- Device[" + this + "] --- Adr["+ address+ "] " + address + " --- Port[" +hubPortNumber + "]" ); } //----------- R O O T H U B ------------------------ // check if it is the root hub if(devicePath != null && address == 0){ //we are accessing the root hub //get the root hub handle and how many //ports it contains int rootHubHandle = this.openHandle(devicePath); if(rootHubHandle == USBException.ERROR_INVALID_HANDLE) throw new USBException("INVALID_HANDLE_VALUE for roothub ",rootHubHandle); this.numPorts = getNumPorts(rootHubHandle); if(Windows.debugDeviceImpl) System.out.println("DeviceImpl.Constructor() ROOT >>> Root Hub (rootHubHandle:" + rootHubHandle + "numPorts:" + this.numPorts+")"); this.enumerateHubPorts(usb, rootHubHandle,this,this.numPorts); // close the root hub handle this.closeHandle(rootHubHandle); } else throw new USBException("This constructor is used only for a root hub",-1); } /** used to create an instance of either an external hub or an usb device * @param bus The bus object this device belongs to * @param hub The device(hub) this device is a child of * @param devicePath The Windows OS specific device path for that device * @param address The device address * @param driverKeyName The driver key name of that device<br>This look similiar to such a string * {<device interface class>} * @param friendlyDevName The friendly device name of that device * @param uniqueID The unique ID * @param portIndex The port number this device is connected to * @throws IOException An exception is raised when we could not get a handle a hub or a JUSB device */ DeviceImpl(USB bus,DeviceImpl hub, String devicePath, int address,String driverKeyName,String friendlyDevName, String uniqueID,int portIndex) throws IOException { super (null, bus, address); this.usb = bus; this.usbDevicePath = devicePath; this.driverKeyName = driverKeyName; this.friendlyDeviceName = friendlyDevName; this.hubPortNumber = portIndex; this.uniqueDevID = uniqueID; if(Windows.debugDeviceImpl){ System.out.println("DeviceImpl.Constructor() DEV or HUB >>> Bus[ " +usb.getBusNum() + "] --- Device[" + this.uniqueDevID + "] --- Adr["+ address + "] " + address + " --- Port[" +portIndex + "] "); } this.hub = hub; //---------- E X T E R N A L H U B ----------------- // if(devicePath != null && address > 0){ int hubHandle = this.openHandle(devicePath); if(hubHandle == USBException.ERROR_INVALID_HANDLE) throw new USBException("INVALID_HANDLE_VALUE for external hub ",hubHandle); // to do: // at this stage it would be useful to build the hub descriptor // and all information that wanted to be know over an external hub // ... this.numPorts = getNumPorts(hubHandle); if(Windows.debugDeviceImpl) System.out.println("DeviceImpl.Constructor() DEV or HUB >>> External Hub (hubHandle:" + hubHandle + "numPorts:" + this.numPorts+")"); this.enumerateHubPorts(usb, hubHandle,this,this.numPorts); // close the root hub handle this.closeHandle(hubHandle); }else //---------- U S B D E V I C E ----------------- // if(devicePath == null){ // to do: // at this stage it would be useful to build the hub descriptor // and all information that wanted to be know over an external hub // ... // to do: // so far we have nothing to do anymore // special thing gere is now to get access to a device // especially read and writing data, get its decriptor and // configuration. // This will be part of the jusb driver } else throw new USBException("This constructor is only used either for a external hub or a device",-1); } /** Native function that invokes the CreateFile WinAPI function with the given * device path * @param devicePath A Windows specific device path for that device * @return A Windows handle for that device<br> * if failed it returns USBException.ERROR_INVALID_HANDLE */ public native int openHandle(String devicePath); /** Native function that invokes the CloseFile WinAPI function with the given * handle * @param devHandle A valid device handle. This value must correspond to a former call of openHandle * @return 1: when success and <br>-1: when failed to close the device */ public native int closeHandle(int devHandle); private native String getFriendlyDeviceName(String driverKeyName); /** * * Returns EXTERNAL_HUB or DEVICE, or NO_DEVICE_CONNECTED */ private native int getAttachedDeviceType(int hubHandle,int portIndex); /** * Returns the number of ports that are supported by this hub */ private native int getNumPorts(int hubHandle); /** * Gives the driverkeyname of the device which is attached to the hub * This value corresponds to the registry entry DeviceDesc which can be found * under \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\Vid_xxxx&Pid_xxxx\.. */ private native String getDriverKeyNameOfDeviceOnPort(int hubHandle,int portIndex); /** * Returns the driver key name of that device */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -