private string GetSerialNumber() { if (_usbConnectInfomation.DeviceDescriptor.iSerialNumber <= 0) { return(string.Empty); } var request = new USB_DESCRIPTOR_REQUEST { ConnectionIndex = _portNo, SetupPacket = { wValue = (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + _usbConnectInfomation.DeviceDescriptor.iSerialNumber) } }; request.SetupPacket.wLength = (short)Marshal.SizeOf(request); // Language Code request.SetupPacket.wIndex = 0x409; var usbDescriptorRequest = DeviceIoControlInvoker.Invoke( _hubHandle, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, request); return(usbDescriptorRequest.StringDescriptor.bString); }
public IUsbDevice Create(IUsbNode parentNode) { var driverKeyName = DeviceIoControlInvoker.Invoke( _hubHandle, IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME, new USB_NODE_CONNECTION_DRIVERKEY_NAME() { ConnectionIndex = _portNo }).DriverKeyName; var deviceMetaData = EnumerableDeviceMetaData(_targetDevice) .FirstOrDefault(data => data.DriverKeyName == driverKeyName); var usbDevice = new UsbDevice( _portNo, _usbConnectInfomation.DeviceDescriptor.idVendor, _usbConnectInfomation.DeviceDescriptor.idProduct, (UsbSupportSpeed)_usbConnectInfomation.Speed, ConvertUsbDeviceType(_usbConnectInfomation.DeviceDescriptor.bcdUSB), driverKeyName, deviceMetaData?.DevicePath, deviceMetaData?.DeviceDescription, GetSerialNumber(), parentNode); return(_usbConnectInfomation.DeviceDescriptor.bDeviceClass == 0xEF ? CreateUsbDeviceWithMiDevice(usbDevice) : usbDevice); }
private static HostController Create(string hostControllerPath) { using (var hostHanle = NativeMethods.CreateFile( hostControllerPath, NativeMethods.GENERIC_WRITE, NativeMethods.FILE_SHARE_WRITE, IntPtr.Zero, NativeMethods.OPEN_EXISTING, 0, IntPtr.Zero)) { NativeMethods.ThrowIfSetLastError(!hostHanle.IsInvalid); var usbRootHubName = DeviceIoControlInvoker.Invoke <USB_ROOT_HUB_NAME>(hostHanle, NativeMethods.IOCTL_USB_GET_ROOT_HUB_NAME); return(new HostController(hostControllerPath, usbRootHubName.DevicePath())); } }
private static IReadOnlyList <IUsbDevice> Create(SafeFileHandle hubHandle, IUsbNode parentNode) { var nodeInformation = DeviceIoControlInvoker .Invoke(hubHandle, NativeMethods.IOCTL_USB_GET_NODE_INFORMATION, new USB_NODE_INFORMATION { NodeType = 0 }); var usbDevices = new List <IUsbDevice>(); var portNumber = nodeInformation.UsbNodeUnion.HubInformation.HubDescriptor.bNumberOfPorts; for (uint portNo = 1; portNo <= portNumber; portNo++) { var usbDeviceFactory = AbstractUsbDeviceFactory.CreateFactory(hubHandle, portNo); usbDevices.Add(usbDeviceFactory.Create(parentNode)); } return(usbDevices); }
internal static IUsbDeviceFactory CreateFactory(SafeFileHandle hubHandle, uint portNo) { var conneectInfomation = DeviceIoControlInvoker.Invoke( hubHandle, NativeMethods.IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX, new USB_NODE_CONNECTION_INFORMATION_EX { ConnectionIndex = portNo }); if (conneectInfomation.ConnectionStatus != 1) { return(new UnConnectUsbDeviceFactory(portNo)); } if (Convert.ToBoolean(conneectInfomation.DeviceIsHub)) { return(new UsbHubFactory(hubHandle, portNo, conneectInfomation)); } return(new UsbDeviceFactory(hubHandle, portNo, conneectInfomation)); }