Example #1
0
        private static string[] GetHidDevInterface(ushort uVendorId, ushort uProductId)
        {
            string[] allHIDInterFace;
            try
            {
                allHIDInterFace = CUSB.GetAllHIDInterFace();
                if (allHIDInterFace == null || allHIDInterFace.Length == 0)
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
            var arrayList = new List <string>();

            for (int i = 0; i < allHIDInterFace.Length; i++)
            {
                var intPtr = FIO.CreateFile(allHIDInterFace[i], FIO.GENERIC_READ, 3u, IntPtr.Zero, 3u, 0u, IntPtr.Zero);
                if (-1 == intPtr.ToInt32())
                {
                    var err = CMessages.GetLastWin32ErrorToString();
                    //Console.WriteLine(err);
                    continue;
                }

                var hIDD_ATTRIBUTES = default(HID.HIDD_ATTRIBUTES);
                hIDD_ATTRIBUTES.Size = (uint)Marshal.SizeOf(hIDD_ATTRIBUTES);
                if (HID.HidD_GetAttributes(intPtr, ref hIDD_ATTRIBUTES) && uVendorId == hIDD_ATTRIBUTES.VendorID && uProductId == hIDD_ATTRIBUTES.ProductID)
                {
                    arrayList.Add(allHIDInterFace[i]);
                }
                FIO.CloseHandle(intPtr);
            }
            return(arrayList.ToArray());
        }