Esempio n. 1
0
        /// <summary>
        /// Used if only one device is connected, finds the serial number automatically
        /// Throws an exception if more than one device is found
        /// </summary>
        public HU320()
        {
            HIDInterface.interfaceDetails[] devices = HIDInterface.getConnectedDevices();
            int numExpectedDevices = 0;
            int deviceIndex        = 0;

            for (int i = 0; i < devices.Length; i++)
            {
                if ((devices[i].VID == DEFAULT_VID) && (devices[i].PID == DEFAULT_PID))
                {
                    numExpectedDevices++;
                    deviceIndex = i;
                }
            }

            if (numExpectedDevices == 0)
            {
                throw new Exception("No HU320 devices could be found!");
            }
            else if (numExpectedDevices > 1)
            {
                throw new Exception("Only one HU320 may be connected, " + numExpectedDevices.ToString() + " found.");
            }

            init(devices[deviceIndex].VID, devices[deviceIndex].PID, (ushort)devices[deviceIndex].serialNumber);
        }
Esempio n. 2
0
        /// <summary>
        /// Queries the operating system for the serial numbers of the devices conneced with the specified VID/PID
        /// </summary>
        /// <param name="VID">VID to search for</param>
        /// <param name="PID">PID to search for</param>
        /// <returns>Array of the connected device's serial numbers</returns>
        public static int[] getConnectedDevices(ushort VID, ushort PID)
        {
            HIDInterface.interfaceDetails[] devs = HIDInterface.getConnectedDevices();

            //find how many devices fit the expected type
            int numExpectedDevices = 0;

            foreach (HIDInterface.interfaceDetails D in devs)
            {
                if ((D.VID == VID) && (D.PID == PID))
                {
                    numExpectedDevices++;
                }
            }

            //create an array of the matching serial numbers
            int[] SNs        = new int[numExpectedDevices];
            int   matchIndex = 0;

            for (int i = 0; i < devs.Length; i++)
            {
                if ((devs[i].VID == VID) && (devs[i].PID == PID))
                {
                    SNs[matchIndex] = devs[i].serialNumber;
                    matchIndex++;
                }
            }
            return(SNs);
        }