/* browse all HID class devices */ public List <HIDInfo> BrowseHID() { /* hid device class guid */ Guid gHid; /* list of device information */ List <HIDInfo> info = new List <HIDInfo>(); /* obtain hid guid */ HIDAPIs.HidD_GetHidGuid(out gHid); /* get list of present hid devices */ var hInfoSet = HIDAPIs.SetupDiGetClassDevs(ref gHid, null, IntPtr.Zero, HIDAPIs.DIGCF_DEVICEINTERFACE | HIDAPIs.DIGCF_PRESENT); /* allocate mem for interface descriptor */ var iface = new HIDAPIs.DeviceInterfaceData(); /* set size field */ iface.Size = Marshal.SizeOf(iface); /* interface index */ uint index = 0; /* iterate through all interfaces */ while (HIDAPIs.SetupDiEnumDeviceInterfaces(hInfoSet, 0, ref gHid, index, ref iface)) { bool isWork = false; HIDInfo hidInfo = new HIDInfo(hInfoSet, iface, out isWork); if (isWork) { info.Add(hidInfo); } /* next, please */ index++; } /* clean up */ if (HIDAPIs.SetupDiDestroyDeviceInfoList(hInfoSet) == false) { /* fail! */ throw new Win32Exception(); } /* return list */ return(info); }
public bool Initialize() { var hidLst = HIDAPIs.BrowseHID(); //hidDev = hidLst.Find(x => x.HIDInfoStruct.Pid == HeadSetConstants.HeadSetPID && x.HIDInfoStruct.Vid == HeadSetConstants.HeadSetVID); hidDev = hidLst.Find(x => x.HIDInfoStruct.Pid == HeadSetConstants.HeadSetZazuPID && x.HIDInfoStruct.Vid == HeadSetConstants.HeadSetVID); if (hidDev == null) { Utilities.Logger(HeadSetConstants.LogHeadSet, $"{HeadSetConstants.HeadSetPID} {HeadSetConstants.HeadSetVID} not found!"); return(false); } bool rev = hidDev.HIDOpenAsync(); if (!rev) { Utilities.Logger(HeadSetConstants.LogHeadSet, $"hidDev Open Failed"); } return(rev); }