// Opens a handle to the devTH device attached the HIDUSB.SYS driver internal unsafe override bool Open(byte dev) { // If this object already has the driver open, close it. if (_hDevice != CyConst.INVALID_HANDLE) { Close(); } int Devices = DeviceCount; if (Devices == 0) { return(false); } if (dev > (Devices - 1)) { return(false); } string pathDetect; _path = PInvoke.GetDevicePath(_drvGuid, dev); pathDetect = _path; if (pathDetect.Contains("&mi_00#") == true || pathDetect.Contains("hid#mshw0030&col01#") == true) { return(false); } _hDevice = PInvoke.GetDeviceHandle(_path, false, ref _Access); if (_hDevice == CyConst.INVALID_HANDLE) { return(false); } _devNum = dev; PInvoke.HidD_GetPreparsedData(_hDevice, ref PreParsedData); PInvoke.HidD_GetAttributes(_hDevice, ref Attributes); PInvoke.HidP_GetCaps(PreParsedData, ref _Capabilities); _Inputs = new CyHidReport(HIDP_REPORT_TYPE.HidP_Input, _Capabilities, PreParsedData); _Outputs = new CyHidReport(HIDP_REPORT_TYPE.HidP_Output, _Capabilities, PreParsedData); _Features = new CyHidReport(HIDP_REPORT_TYPE.HidP_Feature, _Capabilities, PreParsedData); PInvoke.HidD_FreePreparsedData(PreParsedData); PreParsedData = null; byte[] buffer = new byte[512]; fixed(byte *buf = buffer) { char *sChars = (char *)buf; if (PInvoke.HidD_GetManufacturerString(_hDevice, buffer, 512)) { _manufacturer = new string(sChars); } if (PInvoke.HidD_GetProductString(_hDevice, buffer, 512)) { _product = new string(sChars); } if (PInvoke.HidD_GetSerialNumberString(_hDevice, buffer, 512)) { _serialNumber = new string(sChars); } } // Shortcut members. _vendorID = Attributes.VendorID; _productID = Attributes.ProductID; _Version = Attributes.VersionNumber; _Usage = _Capabilities.Usage; _UsagePage = _Capabilities.UsagePage; _driverName = "usbhid.sys"; return(true); }