/// <summary>
        /// This thread code starts the device, reads and frame, and then
        /// sleeps.  When the PictureBox paint event wakes it up, then it reads
        /// another frame.  When the form is closing, it stops the device and
        /// exits.
        /// </summary>
        private void ReaderThreadTask()
        {
            this.Display(string.Format("Reading from device.  Updating Every: {0} ms.\n", MinDelayBetweenReads));

            // Load QuickLink DLL files.
            QuickLink QL;

            try
            {
                QL = new QuickLink();
                this.Display("QuickLink loaded.  Be sure to start QuickGlance, if you have not already.\n");
            }
            catch (Exception e)
            {
                this.Display(string.Format("Failed to load QuickLink.  MSG: {0}.\n", e.Message));
                // Can't continue without QuickLink.
                return;
            }

            // Create an empty frame structure to hold the data we read.
            ImageData iDat = new ImageData();

            while (true)
            {
                // Sleep while the last frame is in use and we aren't shutting down.
                lock (this.l)
                    while (this.frameInUse && !this.isClosing)
                    {
                        Monitor.Wait(this.l);
                    }

                // Break if the program is closing.
                if (this.isClosing)
                {
                    break;
                }

                // Read a new data sample.
                bool success = QL.GetImageData(MaxFrameWaitTime, ref iDat);
                if (success)
                {
                    // Tell the paint event handler to display the frame.
                    this.frameInUse = true;

                    // Update the form's display.
                    UpdateReadout(ref iDat);

                    if (MinDelayBetweenReads > 0)
                    {
                        Thread.Sleep(MinDelayBetweenReads);
                    }
                }
                else
                {
                    // Failed.
                }
            }
        }
Example #2
0
        private static void Main(string[] args)
        {
            // Load Quick Glance; and load the QuickLink DLLs into our
            // address space.
            QuickLink QL;

            try
            {
                QL = new QuickLink();
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("Failed to load QuickLink.  MSG: {0}.", e.Message));
                // Can't continue without QuickLink.
                return;
            }

            // Create an empty frame to hold newly read data.
            ImageData iDat = new ImageData();

            Console.WriteLine("Time, Width, Height" +
                              ", Left Eye Found, Left Eye Calibrated, Left Eye Pupil X, Left Eye Pupil Y, Left Eye Pupil Diameter, Left Eye Glint1 X, Left Eye Glint1 Y, Left Eye Glint2 X, Left Eye Glint2 Y, Left Eye GazePoint X, Left Eye GazePoint Y" +
                              ", Right Eye Found, Right Eye Calibrated, Right Eye Pupil X, Right Eye Pupil Y, Right Eye Pupil Diameter, Right Eye Glint1 X, Right Eye Glint1 Y, Right Eye Glint2 X, Right Eye Glint2 Y, Right Eye GazePoint X, Right Eye GazePoint Y");

            while (true)
            {
                // Read a new data sample.
                if (QL.GetImageData(MaxFrameWaitTime, ref iDat))
                {
                    string headerString   = string.Format("{0},{1},{2}", iDat.Time, iDat.Width, iDat.Height);
                    string leftEyeString  = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", iDat.LeftEye.Found, iDat.LeftEye.Calibrated, iDat.LeftEye.Pupil.x, iDat.LeftEye.Pupil.y, iDat.LeftEye.PupilDiameter, iDat.LeftEye.Glint1.x, iDat.LeftEye.Glint1.y, iDat.LeftEye.Glint2.x, iDat.LeftEye.Glint2.y, iDat.LeftEye.GazePoint.x, iDat.LeftEye.GazePoint.y);
                    string rightEyeString = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", iDat.RightEye.Found, iDat.RightEye.Calibrated, iDat.RightEye.Pupil.x, iDat.RightEye.Pupil.y, iDat.RightEye.PupilDiameter, iDat.RightEye.Glint1.x, iDat.RightEye.Glint1.y, iDat.RightEye.Glint2.x, iDat.RightEye.Glint2.y, iDat.RightEye.GazePoint.x, iDat.RightEye.GazePoint.y);

                    Console.WriteLine(string.Format("{0},{1},{2}", headerString, leftEyeString, rightEyeString));
                }

                if (MinDelayBetweenReads > 0)
                {
                    Thread.Sleep(MinDelayBetweenReads);
                }
            }
        }