Exemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="oDev">Constructing device</param>
 public BuzzInputReport(HIDDevice oDev)
     : base(oDev)
 {
     // Create the button states
     m_arrButtons = new ButtonStates[NUM_HANDSETS];
     for (int i = 0; i < NUM_HANDSETS; i++)
     {
         m_arrButtons[i] = new ButtonStates();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Finds all devices that match a 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 list of devices</returns>
        public static List <HIDDevice> FindDevices(int nVid, int nPid, Type oType)
        {
            List <HIDDevice> devices = new List <HIDDevice>();

            string strPath   = string.Empty;
            string strSearch = string.Format("vid_{0:x4}&pid_{1:x4}", nVid, nPid); // first, build the path search string
            Guid   gHid;

            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
                        devices.Add(oNewDevice);
                    }

                    nIndex++;
                }
            }
            finally
            {
                // Before we go, we have to free up the InfoSet memory reserved by SetupDiGetClassDevs
                SetupDiDestroyDeviceInfoList(hInfoSet);
            }

            return(devices);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="oDev">Device constructing this report</param>
 public BuzzOutputReport(HIDDevice oDev) : base(oDev)
 {
 }
Exemplo n.º 4
0
 /// <summary>
 /// Construction. Do nothing
 /// </summary>
 /// <param name="oDev">Creating device</param>
 public InputReport(HIDDevice oDev) : base(oDev)
 {
 }
Exemplo n.º 5
0
 /// <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]);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="oDev">Constructing device</param>
 public Report(HIDDevice oDev)
 {
     // Do nothing
 }