Exemple #1
0
        /// <summary>
        /// Get the deviceIDs of every eye tracker device detected on the system.  When the method
        /// returns successfully, the <paramref name="deviceIds"/> array will be sized exactly to contain
        /// the number of devices detected.  So, for example, if there is one device detected then the
        /// array will have length 1; if 10 devices are detected then the array will have length 10; if
        /// no devices are detected then the array will have length 0.
        /// </summary>
        /// <param name="deviceIds">
        /// A reference to an uninitialized integer array which will contain the ID of every device
        /// detected on the system upon the method's successful return.
        /// </param>
        /// <returns>
        /// The success of the method.  Returns <see cref="QLError.QL_ERROR_OK"/> on success.
        /// </returns>
        /// <exception cref="DllNotFoundException">
        /// The QuickLink2 DLLs ("QuickLink2.dll," "PGRFlyCapture.dll," and "SMX11MX.dll") must be placed
        /// in the same directory as your program's binary executable; otherwise, this exception will be
        /// thrown.
        /// </exception>
        public static QLError DeviceEnumerate(out int[] deviceIds)
        {
            int numDevices = 1;

            deviceIds = new int[numDevices];

            QLError error = QuickLink2API.QLDevice_Enumerate(ref numDevices, deviceIds);

            if (error == QLError.QL_ERROR_BUFFER_TOO_SMALL)
            {
                // Array too small.  Try again with a properly sized array.
                deviceIds = new int[numDevices];
                error     = QuickLink2API.QLDevice_Enumerate(ref numDevices, deviceIds);
            }

            if (numDevices == 0)
            {
                deviceIds = new int[0];
                return(error);
            }

            for (int i = 0; i < numDevices; i++)
            {
                if (deviceIds[i] <= 0)
                {
                    Console.WriteLine("Illegal device ID detected in data returned from QLDevice_Enumerate()!  Position {0} contains ID {1}.", i, deviceIds[i]);
                    return(QLError.QL_ERROR_INTERNAL_ERROR);
                }
            }

            return(error);
        }
Exemple #2
0
        public static int QL2Initialize(string path)
        {
            QLError      qlerror  = QLError.QL_ERROR_OK;
            int          deviceId = 0;
            QLDeviceInfo deviceInfo;
            //int settingsId;
            int numDevices = 1;

            int[] deviceIds = new int[numDevices];
            qlerror = QuickLink2API.QLDevice_Enumerate(ref numDevices, deviceIds);

            QuickLink2API.QLDevice_GetInfo(deviceIds[0], out deviceInfo);
            if (qlerror != QLError.QL_ERROR_OK)
            {
                Debug.Log("QLDevice_Enumerate() failed with error code " + qlerror);
                return(0);
            }

            else if (numDevices == 0)
            {
                Debug.Log("No devices present.");
                return(0);
            }
            else if (numDevices == 1)
            {
                deviceId = deviceIds[0];
            }
            else if (numDevices > 1)
            {
                Debug.Log("QLDevice_Enumerate() found " + numDevices + " devices");
                return(0);
            }

            // QuickLink2API.QLSettings_Create(0, out settingsId);

            // QuickLink2API.QLSettings_Load(path, ref settingsId);

            // QuickLink2API.QLDevice_GetInfo(deviceId, out deviceInfo);

            // string serialNumberName = "SN_";
            // serialNumberName += deviceInfo.serialNumber;

            // qlerror = QuickLink2API.QLDevice_SetPassword(deviceId, "CTR6JLYD");

            // if (qlerror != QLError.QL_ERROR_OK)
            // {
            //     System.Console.WriteLine("What is the password for the device? ");
            //     string userPassword = System.Console.ReadLine();

            //     qlerror = QuickLink2API.QLDevice_SetPassword(deviceId, userPassword);
            //     if (qlerror != QLError.QL_ERROR_OK)
            //     {
            //         System.Console.WriteLine("Invalid password. Error = {0}", qlerror);
            //         return 0;
            //     }

            //     QuickLink2API.QLSettings_SetValueString(settingsId, serialNumberName, userPassword);
            //     QuickLink2API.QLSettings_Save(path, settingsId);
            // }

            return(deviceId);
        }
        public static int QL2Initialize(string path)
        {
            QLError      qlerror  = QLError.QL_ERROR_OK;
            int          deviceId = 0;
            QLDeviceInfo deviceInfo;
            int          settingsId;

            //Enumerate the bus to find out which eye trackers are connected to the computer.
            const int bufferSize = 100;

            int[] deviceIds  = new int[bufferSize];
            int   numDevices = bufferSize;

            qlerror = QuickLink2API.QLDevice_Enumerate(ref numDevices, deviceIds);

            // If the enumeration failed then return 0.
            if (qlerror != QLError.QL_ERROR_OK)
            {
                System.Console.WriteLine("QLDevice_Enumerate() failed with error code {0}.", qlerror);
                return(0);
            }

            // If no devices were found then return 0.
            else if (numDevices == 0)
            {
                System.Console.WriteLine("No devices present.");
                return(0);
            }

            // If there was only one device connected then use it without prompting the user.
            else if (numDevices == 1)
            {
                deviceId = deviceIds[0];
            }

            // If there is more than one device then ask which one to use.
            else if (numDevices > 1)
            {
                System.Console.WriteLine("QLDevice_Enumerate() found {0} devices\n", numDevices);

                //Get the information for each eye tracker and print it to the screen.
                for (int i = 0; i < numDevices; i++)
                {
                    QuickLink2API.QLDevice_GetInfo(deviceIds[i], out deviceInfo);
                    System.Console.WriteLine("Device {0}", i);
                    System.Console.WriteLine("\tdeviceInfo.modelName = {0}", deviceInfo.modelName);
                    System.Console.WriteLine("\tdeviceInfo.serialNumber = {0}\n", deviceInfo.serialNumber);
                }

                //Ask which device to use
                int deviceToUse = -1;

                System.Console.WriteLine("Which device would you like to use?");
                deviceToUse = Convert.ToInt32(System.Console.ReadLine());

                //Check to make sure the user's input is valid.  If it is not valid, then return 0
                if ((deviceToUse < 0) || (deviceToUse >= numDevices))
                {
                    System.Console.WriteLine("Invalid device: {0} \n", deviceToUse);
                    return(0);
                }

                //if the device is valid then select it as the device to use.
                else
                {
                    deviceId = deviceIds[deviceToUse];
                }
            }

            // Create a blank settings container. QLSettings_Load() can create a
            // settings container but it won't if the file fails to load. By calling
            // QLSettings_Create() we ensure that a container is created regardless.
            qlerror = QuickLink2API.QLSettings_Create(0, out settingsId);

            //Load the file with the stored password.
            qlerror = QuickLink2API.QLSettings_Load(path, ref settingsId);

            //Get the device info so we can access the serial number.
            QuickLink2API.QLDevice_GetInfo(deviceId, out deviceInfo);

            // Create an application defined setting name using the serial number. The
            // settings containers can be used to hold settings other than the
            // QuickLink2 defined setting. Using it to store the password for future
            // use as we are doing here is a good example.
            string serialNumberName = "SN_";

            serialNumberName += deviceInfo.serialNumber;

            // Create a buffer for getting the stored password.
            const int passwordBufferSize = 128;

            System.Text.StringBuilder password = new System.Text.StringBuilder(passwordBufferSize + 1);

            // Check for the password in the settings file.
            QuickLink2API.QLSettings_GetValueString(
                settingsId,
                serialNumberName,
                passwordBufferSize, password);

            //Try setting the password for the device.
            qlerror = QuickLink2API.QLDevice_SetPassword(deviceId, password.ToString());

            if (qlerror != QLError.QL_ERROR_OK)
            {
                System.Console.WriteLine("What is the password for the device? ");
                string userPassword = System.Console.ReadLine();

                //Set the password for the device
                qlerror = QuickLink2API.QLDevice_SetPassword(deviceId, userPassword);

                //If the password is not correct then print an error and return 0.
                if (qlerror != QLError.QL_ERROR_OK)
                {
                    System.Console.WriteLine("Invalid password. Error = {0}", qlerror);
                    return(0);
                }

                // Set the password for the device in the settings container.
                QuickLink2API.QLSettings_SetValueString(settingsId, serialNumberName, userPassword);

                // Save the settings container to file.
                QuickLink2API.QLSettings_Save(path, settingsId);
            }

            return(deviceId);
        }