Пример #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());
        }
Пример #2
0
        public static string[] EnumPorts(UInt16 vid, UInt16 pid)
        {
            var arrayList       = new List <string>();
            var hidDevInterface = CUSB.GetHidDevInterface(vid, pid);

            if (hidDevInterface == null)
            {
                return(arrayList.ToArray());
            }
            for (int i = 0; i < hidDevInterface.Length; i++)
            {
                var intPtr = FIO.CreateFile(hidDevInterface[i].Trim(), FIO.GENERIC_READ, 3u, IntPtr.Zero, 3u, 0u, IntPtr.Zero);
                if (intPtr.ToInt32() == -1)
                {
                    continue;
                }
                //var a = "";
                //if (CUSB.GetVersion(intPtr, ref a)) if (a == "UF1.0")
                arrayList.Add(hidDevInterface[i]);

                FIO.CloseHandle(intPtr);
            }
            return(arrayList.ToArray());
        }