comparison USBLib/Windows/USB/UsbHub.cs @ 87:9b898d8b2541

Small improvements in Windows USB device handling
author Ivo Smits <Ivo@UCIS.nl>
date Thu, 05 Jun 2014 00:46:15 +0200
parents e811297f5aa4
children
comparison
equal deleted inserted replaced
86:5d1b72ba44dc 87:9b898d8b2541
20 20
21 private void GetNodeInformation() { 21 private void GetNodeInformation() {
22 if (HasNodeInformation) return; 22 if (HasNodeInformation) return;
23 NodeInformation = new USB_NODE_INFORMATION(); 23 NodeInformation = new USB_NODE_INFORMATION();
24 int nBytes = Marshal.SizeOf(typeof(USB_NODE_INFORMATION)); 24 int nBytes = Marshal.SizeOf(typeof(USB_NODE_INFORMATION));
25 using (SafeFileHandle handle = OpenHandle()) 25 using (SafeFileHandle handle = OpenHandle())
26 if (!Kernel32.DeviceIoControl(handle, UsbApi.IOCTL_USB_GET_NODE_INFORMATION, ref NodeInformation, nBytes, out NodeInformation, nBytes, out nBytes, IntPtr.Zero)) 26 HasNodeInformation = Kernel32.DeviceIoControl(handle, UsbApi.IOCTL_USB_GET_NODE_INFORMATION, ref NodeInformation, nBytes, out NodeInformation, nBytes, out nBytes, IntPtr.Zero);
27 throw new Win32Exception(Marshal.GetLastWin32Error());
28 } 27 }
29 28
30 public bool IsRootHub { get; private set; } 29 public bool IsRootHub { get; private set; }
31 public int PortCount { get { GetNodeInformation(); return NodeInformation.HubInformation.HubDescriptor.bNumberOfPorts; } } 30 public int PortCount { get { GetNodeInformation(); return NodeInformation.HubInformation.HubDescriptor.bNumberOfPorts; } }
32 public bool IsBusPowered { get { GetNodeInformation(); return NodeInformation.HubInformation.HubIsBusPowered; } } 31 public bool IsBusPowered { get { GetNodeInformation(); return NodeInformation.HubInformation.HubIsBusPowered; } }