public GenericHIDDevice(int index, int VID, int PID, string ID, IntPtr deviceHandle, IHIDInterface hidInterface, string devicePath) : base(index, VID, PID, ID, deviceHandle, hidInterface, devicePath, "") { try { //TODO find way to check if real device is connected cos it can be inside HID list but actually not connected var hidHandle = OpenDeviceIO(this.DevicePath, Native.ACCESS_NONE); byte[] buffer = new byte[256]; if (Native.HidD_GetProductString(hidHandle, buffer, (ulong)buffer.LongLength)) { this.Name = Native.TruncateZeroTerminatedString(new UnicodeEncoding().GetString(buffer)); } _OEMName = Native.ReadRegKey(Native.HKEY_LOCAL_MACHINE, @"SYSTEM\CurrentControlSet\Control\MediaProperties\PrivateProperties\Joystick\OEM\" + "VID_" + VID.ToString("X4") + "&PID_" + PID.ToString("X4"), Native.REGSTR_VAL_JOYOEMNAME); CloseDeviceIO(hidHandle); IsConnected = true; info = new Native.JoyInfoEx(); info.Size = Native.JoyInfoEx.SizeInBytes; info.Flags = Native.JoystickFlags.All; __lastHIDReport = new HIDReport(this.index, CreateInputBuffer(), HIDReport.ReadStatus.NoDataRead); } catch (Exception exception) { throw new Exception(string.Format("Error querying HID device '{0}'.", devicePath), exception); } }
public GenericHIDDevice(int index, int VID, int PID,string ID, IntPtr deviceHandle, IHIDInterface hidInterface, string devicePath):base(index,VID,PID,ID,deviceHandle,hidInterface,devicePath,"") { try { //TODO find way to check if real device is connected cos it can be inside HID list but actually not connected var hidHandle = OpenDeviceIO(this.DevicePath,Native.ACCESS_NONE); byte[] buffer = new byte[256]; if (Native.HidD_GetProductString(hidHandle, buffer, (ulong)buffer.LongLength)) { this.Name = Native.TruncateZeroTerminatedString(new UnicodeEncoding().GetString(buffer)); } _OEMName= Native.ReadRegKey(Native.HKEY_LOCAL_MACHINE, @"SYSTEM\CurrentControlSet\Control\MediaProperties\PrivateProperties\Joystick\OEM\" + "VID_" + VID.ToString("X4") + "&PID_" + PID.ToString("X4"), Native.REGSTR_VAL_JOYOEMNAME); CloseDeviceIO(hidHandle); IsConnected = true; info = new Native.JoyInfoEx(); info.Size = Native.JoyInfoEx.SizeInBytes; info.Flags = Native.JoystickFlags.All; __lastHIDReport = new HIDReport(this.index, CreateInputBuffer(),HIDReport.ReadStatus.NoDataRead); } catch (Exception exception) { throw new Exception(string.Format("Error querying HID device '{0}'.", devicePath), exception); } }