// Token: 0x0600002B RID: 43 RVA: 0x00003FA4 File Offset: 0x000021A4 public static HIDDevice FindDevice(int nVid, int nPid, Type oType) { string empty = string.Empty; string value = string.Format("vid_{0:x4}&pid_{1:x4}", nVid, nPid); Guid hidguid = Win32Usb.HIDGuid; IntPtr intPtr = Win32Usb.SetupDiGetClassDevs(ref hidguid, null, IntPtr.Zero, 18u); try { Win32Usb.DeviceInterfaceData deviceInterfaceData = default(Win32Usb.DeviceInterfaceData); deviceInterfaceData.Size = Marshal.SizeOf(deviceInterfaceData); int num = 0; while (Win32Usb.SetupDiEnumDeviceInterfaces(intPtr, 0u, ref hidguid, (uint)num, ref deviceInterfaceData)) { string devicePath = HIDDevice.GetDevicePath(intPtr, ref deviceInterfaceData); if (devicePath.IndexOf(value) >= 0) { HIDDevice hiddevice = (HIDDevice)Activator.CreateInstance(oType); hiddevice.Initialise(devicePath); return(hiddevice); } num++; } } catch (Exception ex) { throw HIDDeviceException.GenerateError(ex.ToString()); } finally { Win32Usb.SetupDiDestroyDeviceInfoList(intPtr); } return(null); }
public static HIDDevice FindDevice(int nVid, int nPid, Type oType) { string value = string.Format("vid_{0:x4}&pid_{1:x4}", nVid, nPid); Guid hIDGuid = Win32Usb.HIDGuid; IntPtr intPtr = Win32Usb.SetupDiGetClassDevs(ref hIDGuid, null, IntPtr.Zero, 18u); try { DeviceInterfaceData deviceInterfaceData = default(DeviceInterfaceData); deviceInterfaceData.Size = Marshal.SizeOf(deviceInterfaceData); int num = 0; while (Win32Usb.SetupDiEnumDeviceInterfaces(intPtr, 0u, ref hIDGuid, (uint)num, ref deviceInterfaceData)) { string text = HIDDevice.smethod_0(intPtr, ref deviceInterfaceData); if (text.IndexOf(value) < 0) { num++; continue; } HIDDevice hIDDevice = (HIDDevice)Activator.CreateInstance(oType); hIDDevice.method_0(text); return(hIDDevice); } } catch (Exception ex) { throw GException0.GenerateError(ex.ToString()); } finally { Marshal.GetLastWin32Error(); Win32Usb.SetupDiDestroyDeviceInfoList(intPtr); } return(null); }
public static HIDDevice FindDevice(int nVid, int nPid, Type oType) { string str = $"vid_{nVid:x4}&pid_{nPid:x4}"; Guid hIDGuid = Win32Usb.HIDGuid; IntPtr lpDeviceInfoSet = Win32Usb.SetupDiGetClassDevs(ref hIDGuid, null, IntPtr.Zero, 0x12); try { Win32Usb.DeviceInterfaceData structure = new Win32Usb.DeviceInterfaceData(); structure.Size = Marshal.SizeOf(structure); for (int i = 0; Win32Usb.SetupDiEnumDeviceInterfaces(lpDeviceInfoSet, 0, ref hIDGuid, (uint)i, ref structure); i++) { string devicePath = GetDevicePath(lpDeviceInfoSet, ref structure); if (devicePath.IndexOf(str) >= 0) { HIDDevice device = (HIDDevice)Activator.CreateInstance(oType); device.Initialise(devicePath); return(device); } } } catch (Exception exception) { throw HIDDeviceException.GenerateError(exception.ToString()); } finally { Win32Usb.SetupDiDestroyDeviceInfoList(lpDeviceInfoSet); } return(null); }
/// <summary> /// Checks the devices that are present at the moment and checks if one of those /// is the device you defined by filling in the product id and vendor id. /// </summary> public void CheckDevicePresent() { try { //Mind if the specified device existed before. bool history = false; if (specified_device != null) { history = true; } specified_device = HIDDevice.FindDevice(VendorId, ProductId, CreateDevice()); // look for the device on the USB bus if (specified_device != null) // did we find it? { if (OnSpecifiedDeviceArrived != null) { this.OnSpecifiedDeviceArrived(this, new EventArgs()); } specified_device.DataReceived += new DataReceivedEventHandler(DataRecieved); specified_device.DataSent += new DataSentEventHandler(DataSend); } else { if (OnSpecifiedDeviceRemoved != null && history) { this.OnSpecifiedDeviceRemoved(this, new EventArgs()); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public UsbHidPort() { //initializing in initial state product_id = 0; vendor_id = 0; specified_device = null; device_class = Win32Usb.HIDGuid; InitializeComponent(); }
public UsbHidPort(IContainer container) { //initializing in initial state product_id = 0; vendor_id = 0; specified_device = null; device_class = Win32Usb.HIDGuid; container.Add(this); InitializeComponent(); }
/// <summary> /// Finds a device given its PID and VID /// </summary> /// <param name="nVid">Vendor id for device (VID)</param> /// <param name="nPid">Product id for device (PID)</param> /// <param name="oType">Type of device class to create</param> /// <returns>A new device class of the given type or null</returns> public static HIDDevice FindDevice(int nVid, int nPid, Type oType) { string strPath = string.Empty; string strSearch = string.Format("vid_{0:x4}&pid_{1:x4}", nVid, nPid); // first, build the path search string Guid gHid = HIDGuid; //HidD_GetHidGuid(out gHid); // next, get the GUID from Windows that it uses to represent the HID USB interface IntPtr hInfoSet = SetupDiGetClassDevs(ref gHid, null, IntPtr.Zero, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); // this gets a list of all HID devices currently connected to the computer (InfoSet) try { DeviceInterfaceData oInterface = new DeviceInterfaceData(); // build up a device interface data block oInterface.Size = Marshal.SizeOf(oInterface); // Now iterate through the InfoSet memory block assigned within Windows in the call to SetupDiGetClassDevs // to get device details for each device connected int nIndex = 0; while (SetupDiEnumDeviceInterfaces(hInfoSet, 0, ref gHid, (uint)nIndex, ref oInterface)) // this gets the device interface information for a device at index 'nIndex' in the memory block { string strDevicePath = GetDevicePath(hInfoSet, ref oInterface); // get the device path (see helper method 'GetDevicePath') if (strDevicePath.IndexOf(strSearch) >= 0) // do a string search, if we find the VID/PID string then we found our device! { HIDDevice oNewDevice = (HIDDevice)Activator.CreateInstance(oType); // create an instance of the class for this device oNewDevice.Initialise(strDevicePath); // initialise it with the device path return(oNewDevice); // and return it } nIndex++; // if we get here, we didn't find our device. So move on to the next one. } // MessageBox.Show("请检查是否插入设备!"); } catch (Exception ex) { throw HIDDeviceException.GenerateError(ex.ToString()); //Console.WriteLine(ex.ToString()); } finally { // Before we go, we have to free up the InfoSet memory reserved by SetupDiGetClassDevs SetupDiDestroyDeviceInfoList(hInfoSet); } //string a = @"\\?\hid#vid_0483&pid_5750#7&2e4989f7&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"; //HIDDevice oNewDevice1 = (HIDDevice)Activator.CreateInstance(oType); //oNewDevice1.Initialise(a); // initialise it with the device path //return oNewDevice1; return(null); // oops, didn't find our device }
/// <summary> /// Finds a device given its PID and VID /// </summary> /// <param name="nVid">Vendor id for device (VID)</param> /// <param name="nPid">Product id for device (PID)</param> /// <param name="oType">Type of device class to create</param> /// <returns>A new device class of the given type or null</returns> public static HIDDevice FindDevice(int nVid, int nPid, Type oType) { string strPath = string.Empty; string strSearch = @"#vid_" + nVid.ToString("x4") + "&pid_" + nPid.ToString("x4") + "#"; //string strSearch = string.Format("VID_{0:X4}&PID_{1:X4}", nVid, nPid); // first, build the path search string Guid gHid = HIDGuid; HidD_GetHidGuid(ref gHid); // next, get the GUID from Windows that it uses to represent the HID USB interface IntPtr hInfoSet = SetupDiGetClassDevs(ref gHid, IntPtr.Zero, IntPtr.Zero, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); // this gets a list of all HID devices currently connected to the computer (InfoSet) try { var oInterface = new DeviceInterfaceData(); // build up a device interface data block oInterface.Size = Marshal.SizeOf(oInterface); //oInterface.Size = (IntPtr.Size == 4) ? (4 + Marshal.SystemDefaultCharSize) : 8; // Now iterate through the InfoSet memory block assigned within Windows in the call to SetupDiGetClassDevs // to get device details for each device connected int nIndex = 0; while (SetupDiEnumDeviceInterfaces(hInfoSet, IntPtr.Zero, ref gHid, nIndex, ref oInterface)) // this gets the device interface information for a device at index 'nIndex' in the memory block { string strDevicePath = GetDevicePath(hInfoSet, ref oInterface); // get the device path (see helper method 'GetDevicePath') if (strDevicePath.IndexOf(strSearch) >= 0) // do a string search, if we find the VID/PID string then we found our device! { HIDDevice oNewDevice = (HIDDevice)Activator.CreateInstance(oType); // create an instance of the class for this device oNewDevice.Initialise(strDevicePath); // initialise it with the device path return(oNewDevice); // and return it } nIndex++; // if we get here, we didn't find our device. So move on to the next one. } } catch (Exception ex) { throw HIDDeviceException.GenerateError(ex.ToString()); //Console.WriteLine(ex.ToString()); } finally { // Before we go, we have to free up the InfoSet memory reserved by SetupDiGetClassDevs SetupDiDestroyDeviceInfoList(hInfoSet); } return(null); // oops, didn't find our device }
/// <summary> /// Finds a device given its PID and VID /// </summary> /// <param name="nVid">Vendor id for device (VID)</param> /// <param name="nPid">Product id for device (PID)</param> /// <param name="oType">Type of device class to create</param> /// <returns>A new device class of the given type or null</returns> public static HIDDevice FindDevice(int nVid, int nPid) { string strPath = string.Empty; string strSearch = string.Format("vid_{0:x4}&pid_{1:x4}", nVid, nPid); // first, build the path search string Guid gHid = HIDGuid; //HidD_GetHidGuid(out gHid); // next, get the GUID from Windows that it uses to represent the HID USB interface IntPtr hInfoSet = SetupDiGetClassDevs(ref gHid, null, IntPtr.Zero, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); // this gets a list of all HID devices currently connected to the computer (InfoSet) try { DeviceInterfaceData oInterface = new DeviceInterfaceData(); // build up a device interface data block oInterface.Size = Marshal.SizeOf(oInterface); // Now iterate through the InfoSet memory block assigned within Windows in the call to SetupDiGetClassDevs // to get device details for each device connected int nIndex = 0; while (SetupDiEnumDeviceInterfaces(hInfoSet, 0, ref gHid, (uint)nIndex, ref oInterface)) // this gets the device interface information for a device at index 'nIndex' in the memory block { string strDevicePath = GetDevicePath(hInfoSet, ref oInterface); // get the device path (see helper method 'GetDevicePath') if (strDevicePath.IndexOf(strSearch) >= 0) // do a string search, if we find the VID/PID string then we found our device! { HIDDevice oNewDevice = new HIDDevice(); oNewDevice.Initialise(strDevicePath); // initialise it with the device path return oNewDevice; // and return it } nIndex++; // if we get here, we didn't find our device. So move on to the next one. } } catch(Exception ex) { throw HIDDeviceException.GenerateError(ex.ToString()); //Console.WriteLine(ex.ToString()); } finally { // Before we go, we have to free up the InfoSet memory reserved by SetupDiGetClassDevs SetupDiDestroyDeviceInfoList(hInfoSet); } return null; // oops, didn't find our device }
/// <summary> /// Constructor /// </summary> /// <param name="oDev">Constructing device</param> public Report(HIDDevice oDev) { // Do nothing }
/// <summary> /// Конструктор Feature Reports /// </summary> /// <param name="oDev"></param> public FeatureReport(HIDDevice oDev) : base(oDev) { SetBuffer(new byte[oDev.FeatureReportLength]); }
public static SpecifiedDevice FindSpecifiedDevice(int vendor_id, int product_id) => ((SpecifiedDevice)HIDDevice.FindDevice(vendor_id, product_id, typeof(SpecifiedDevice)));
/// <summary> /// Construction. Do nothing /// </summary> /// <param name="oDev">Creating device</param> public InputReport(HIDDevice oDev) : base(oDev) { }
/// <summary> /// Construction. Setup the buffer with the correct output report length dictated by the device /// </summary> /// <param name="oDev">Creating device</param> public OutputReport(HIDDevice oDev) : base(oDev) { SetBuffer(new byte[oDev.OutputReportLength + 1 ]); //SetBuffer(new byte[oDev.OutputReportLength]); }
/// <summary> /// Finds a device given its PID and VID /// </summary> /// <param name="nVid">Vendor id for device (VID)</param> /// <param name="nPid">Product id for device (PID)</param> /// <param name="oType">Type of device class to create</param> /// <returns>A new device class of the given type or null</returns> public static HIDDevice FindDevice(int nVid, int nPid, Type oType, string nProduct) { string strPath = string.Empty; string strSearch = string.Format("vid_{0:x4}&pid_{1:x4}", nVid, nPid); // first, build the path search string Guid gHid = HIDGuid; // next, get the GUID from Windows that it uses to represent the HID USB interface //HidD_GetHidGuid(out gHid); // this gets a list of all HID devices currently connected to the computer (InfoSet) IntPtr hInfoSet = SetupDiGetClassDevs(ref gHid, null, IntPtr.Zero, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); //IntPtr hInfoSet = SetupDiGetClassDevs(ref gHid, "USB", IntPtr.Zero, DIGCF_ALLCLASSES | DIGCF_PRESENT); try { DeviceInterfaceData oInterface = new DeviceInterfaceData(); // build up a device interface data block oInterface.Size = Marshal.SizeOf(oInterface); // Now iterate through the InfoSet memory block assigned within Windows in the call to SetupDiGetClassDevs // to get device details for each device connected int nIndex = 0; // this gets the device interface information for a device at index 'nIndex' in the memory block while (SetupDiEnumDeviceInterfaces(hInfoSet, 0, ref gHid, (uint)nIndex, ref oInterface)) { string strDevicePath = GetDevicePath(hInfoSet, ref oInterface); // get the device path (see helper method 'GetDevicePath') if (strDevicePath.IndexOf(strSearch) >= 0) // do a string search, if we find the VID/PID string then we found our device! { HIDDevice oNewDevice = (HIDDevice)Activator.CreateInstance(oType); // create an instance of the class for this device oNewDevice.Initialise(strDevicePath); // initialise it with the device path if (String.IsNullOrEmpty(nProduct)) { return(oNewDevice); // возвращяем первый попавшийся девайс, если нет предпочтения определённому производителю } else { string deviceProduct = null; byte[] arrBuff = new byte[255]; // читаем производителя с девайса HidD_GetProductString(oNewDevice.m_hHandle, arrBuff, arrBuff.Length); // переводим массив в строку foreach (char b in arrBuff) { // нет проверки на спец знаки\символы if (b != 0) { deviceProduct += b.ToString(); } } // от возникновения мелких ошибок написания в разных регистрах nProduct = nProduct.ToLower(); deviceProduct = deviceProduct.ToLower(); // ну и проверяем - тот ли производитель if (String.Equals(nProduct, deviceProduct)) { return(oNewDevice); } else { oNewDevice.Dispose(); // закрываем девайс, он нам не подходит } } } nIndex++; // if we get here, we didn't find our device. So move on to the next one. } } catch (Exception ex) { throw HIDDeviceException.GenerateError(ex.ToString()); //Console.WriteLine(ex.ToString()); } finally { // Before we go, we have to free up the InfoSet memory reserved by SetupDiGetClassDevs SetupDiDestroyDeviceInfoList(hInfoSet); } return(null); // oops, didn't find our device }
/// <summary> /// Checks the devices that are present at the moment and checks if one of those /// is the device you defined by filling in the product id and vendor id. /// </summary> public void CheckDevicePresent() { try { //Mind if the specified device existed before. bool history = false; if(specified_device != null ){ history = true; } specified_device = HIDDevice.FindDevice(VendorId, ProductId, CreateDevice()); // look for the device on the USB bus if (specified_device != null) // did we find it? { if (OnSpecifiedDeviceArrived != null) { this.OnSpecifiedDeviceArrived(this, new EventArgs()); } specified_device.DataReceived += new DataReceivedEventHandler(DataRecieved); specified_device.DataSent += new DataSentEventHandler(DataSend); } else { if (OnSpecifiedDeviceRemoved != null && history) { this.OnSpecifiedDeviceRemoved(this, new EventArgs()); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
DefaultImportReport(HIDDevice device) : base(device) { }
public RequestBuffer(HIDDevice device) : base(device) { }
public Report(HIDDevice oDev) { }
public SpecifiedFeatureReport(HIDDevice oDev) : base(oDev) { }
// Token: 0x0600005B RID: 91 RVA: 0x00008E9A File Offset: 0x0000709A public SpecifiedInputReport(HIDDevice oDev) : base(oDev) { }
public InputReport(HIDDevice oDev) : base(oDev) { }
public SpecifiedInputReport(HIDDevice oDev) : base(oDev) { }
// Token: 0x0600009E RID: 158 RVA: 0x00009A85 File Offset: 0x00007C85 public OutputReport(HIDDevice oDev) : base(oDev) { base.SetBuffer(new byte[oDev.OutputReportLength]); }
/// <summary> /// Construction. Setup the buffer with the correct output report length dictated by the device /// </summary> /// <param name="oDev">Creating device</param> public OutputReport(HIDDevice oDev) : base(oDev) { device = oDev; SetBuffer(new byte[oDev.OutputReportLength]); }