comparison USBLib/Windows/USB/UsbHub.cs @ 68:e811297f5aa4

Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
author Ivo Smits <Ivo@UCIS.nl>
date Wed, 16 Oct 2013 16:58:39 +0200
parents 309c705d7460
children 9b898d8b2541
comparison
equal deleted inserted replaced
67:2d16447eff12 68:e811297f5aa4
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.ComponentModel; 3 using System.ComponentModel;
4 using System.Runtime.InteropServices; 4 using System.Runtime.InteropServices;
5 using Microsoft.Win32.SafeHandles; 5 using Microsoft.Win32.SafeHandles;
6 using UCIS.HWLib.Windows.Devices; 6 using UCIS.HWLib.Windows.Devices;
7 using UCIS.USBLib.Descriptor;
7 using UCIS.USBLib.Internal.Windows; 8 using UCIS.USBLib.Internal.Windows;
8 9
9 namespace UCIS.HWLib.Windows.USB { 10 namespace UCIS.HWLib.Windows.USB {
10 public class UsbHub : UsbDevice { 11 public class UsbHub : UsbDevice {
11 internal static SafeFileHandle OpenHandle(String path) { 12 internal static SafeFileHandle OpenHandle(String path) {
57 for (uint index = 1; index <= PortCount; index++) { 58 for (uint index = 1; index <= PortCount; index++) {
58 USB_NODE_CONNECTION_INFORMATION_EX nodeConnection = GetNodeConnectionInformation(handle, index); 59 USB_NODE_CONNECTION_INFORMATION_EX nodeConnection = GetNodeConnectionInformation(handle, index);
59 UsbDevice device; 60 UsbDevice device;
60 if (nodeConnection.ConnectionStatus != USB_CONNECTION_STATUS.DeviceConnected) { 61 if (nodeConnection.ConnectionStatus != USB_CONNECTION_STATUS.DeviceConnected) {
61 device = new UsbDevice(null, this, index); 62 device = new UsbDevice(null, this, index);
62 } else if (nodeConnection.DeviceDescriptor.DeviceClass == (Byte)UsbDeviceClass.HubDevice) { 63 } else if (nodeConnection.DeviceDescriptor.DeviceClass == UsbClassCode.Hub) {
63 int nBytes = Marshal.SizeOf(typeof(USB_NODE_CONNECTION_NAME)); 64 int nBytes = Marshal.SizeOf(typeof(USB_NODE_CONNECTION_NAME));
64 USB_NODE_CONNECTION_NAME nameConnection = new USB_NODE_CONNECTION_NAME(); 65 USB_NODE_CONNECTION_NAME nameConnection = new USB_NODE_CONNECTION_NAME();
65 nameConnection.ConnectionIndex = index; 66 nameConnection.ConnectionIndex = index;
66 if (!Kernel32.DeviceIoControl(handle, UsbApi.IOCTL_USB_GET_NODE_CONNECTION_NAME, ref nameConnection, nBytes, out nameConnection, nBytes, out nBytes, IntPtr.Zero)) 67 if (!Kernel32.DeviceIoControl(handle, UsbApi.IOCTL_USB_GET_NODE_CONNECTION_NAME, ref nameConnection, nBytes, out nameConnection, nBytes, out nBytes, IntPtr.Zero))
67 throw new Win32Exception(Marshal.GetLastWin32Error()); 68 throw new Win32Exception(Marshal.GetLastWin32Error());