/// <summary> /// Initializes a new instance of the <see cref="UsbDevice"/> class. /// </summary> /// <param name="deviceDescriptor">The device descriptor.</param> /// <param name="adapterNumber">The adapter number.</param> /// <param name="devicePath">The device path.</param> public UsbDevice(UsbSpec.UsbDeviceDescriptor deviceDescriptor, uint adapterNumber, string devicePath) : base(deviceDescriptor, adapterNumber, devicePath) { }
/// <summary> /// Initializes a new instance of the <see cref="UsbHub"/> class. /// </summary> /// <param name="deviceDescriptor">The device descriptor.</param> /// <param name="devicePath">The device path.</param> public UsbHub(UsbSpec.UsbDeviceDescriptor deviceDescriptor, string devicePath) : base(deviceDescriptor, 0, devicePath) { DeviceDescription = "Standard-USB-Hub"; DevicePath = devicePath; IntPtr hostControllerHandle = IntPtr.Zero; try { hostControllerHandle = KernelApi.CreateFile(devicePath, UsbApi.GenericWrite, UsbApi.FileShareWrite, IntPtr.Zero, UsbApi.OpenExisting, 0, IntPtr.Zero); if (hostControllerHandle.ToInt64() != UsbApi.InvalidHandleValue) { GetRootHubName(hostControllerHandle); // TODO: Get the driver key name for the root hub. IntPtr hubHandle = IntPtr.Zero; try { // Now let's open the hub (based upon the hub name we got above). hubHandle = KernelApi.CreateFile(DevicePath, UsbApi.GenericWrite, UsbApi.FileShareWrite, IntPtr.Zero, UsbApi.OpenExisting, 0, IntPtr.Zero); if (hubHandle.ToInt64() != UsbApi.InvalidHandleValue) { GetUsbNodeInformation(hubHandle); GetUsbHubInformation(hubHandle); GetHubCapabilities(hubHandle); } } finally { if (hubHandle != IntPtr.Zero) { KernelApi.CloseHandle(hubHandle); } } } else { throw new UsbHubException("No port found!"); } } finally { if (hostControllerHandle != IntPtr.Zero) { KernelApi.CloseHandle(hostControllerHandle); } } for (uint index = 1; index <= PortCount; index++) { // Initialize a new port and save the port. try { Devices.Add(DeviceFactory.BuildDevice(this, index, DevicePath)); } catch (Exception e) { CoreTraceSource.Source.TraceEvent(TraceEventType.Error, CoreTraceSource.UsbHubSourceId, "Unhandled exception occurred: {0}", e); } } }
/// <summary> /// Initializes a new instance of the <see cref="UsbDevice"/> class. /// </summary> /// <param name="deviceDescriptor">The device descriptor.</param> /// <param name="adapterNumber">The adapter number.</param> public UsbDevice(UsbSpec.UsbDeviceDescriptor deviceDescriptor, uint adapterNumber) : base(deviceDescriptor, adapterNumber, null) { }