public bool ReadManufacturer(out byte[] data) { data = new byte[254]; IntPtr hidHandle = IntPtr.Zero; bool success = false; try { if (IsOpen) { hidHandle = Handle; } else { hidHandle = OpenDeviceIO(_devicePath, NativeMethods.ACCESS_NONE); } success = NativeMethods.HidD_GetManufacturerString(hidHandle, ref data[0], data.Length); } catch (Exception exception) { throw new Exception(string.Format("Error accessing HID device '{0}'.", _devicePath), exception); } finally { if (hidHandle != IntPtr.Zero && hidHandle != Handle) { CloseDeviceIO(hidHandle); } } return(success); }
public bool ReadManufacturer(out byte[] data) { data = new byte[64]; IntPtr intPtr = IntPtr.Zero; bool result = false; try { intPtr = OpenDeviceIO(_devicePath, 0u); result = NativeMethods.HidD_GetManufacturerString(intPtr, ref data[0], data.Length); } catch (Exception innerException) { throw new Exception($"Error accessing HID device '{_devicePath}'.", innerException); } finally { if (intPtr != IntPtr.Zero) { CloseDeviceIO(intPtr); } } return(result); }