コード例 #1
0
        /// <summary>
        /// Connects to eyetracker and subscribes to events. Events are received on background thread.
        /// </summary>
        public void Connect()
        {
            try
            {
                eyetracker = EyetrackerFactory.CreateEyetracker(info, EventThreadingOptions.BackgroundThread);

                // subscribe to eyetracker events
                eyetracker.ConnectionError += ConnectionError;
                foreach (EventHandler <FramerateChangedEventArgs> handler in framerateChangedHandlers)
                {
                    eyetracker.FramerateChanged += handler;
                }
                foreach (EventHandler <GazeDataEventArgs> handler in gazeDataHandlers)
                {
                    eyetracker.GazeDataReceived += handler;
                }

                eyetracker.StartTracking();
            }
            catch (EyetrackerException ee)
            {
                Disconnect();
                if (ee.ErrorCode == 0x20000402)
                {
                    throw new Exception("Failed to upgrade protocol. Upgrade firmware to version 2.0.0 or higher.", ee);
                }

                throw ee;
            }
            catch (Exception e)
            {
                Disconnect();
                throw e;
            }
        }
コード例 #2
0
        // establich connection to eyetracker device
        private void ConnectToTrackerAndStartTracking(EyetrackerInfo info)
        {
            try
            {
                if (FEyetracker == null)
                {
                    // get tracker representation from EyetrackerInfo
                    FEyetracker = EyetrackerFactory.CreateEyetracker(info);
                }

                FEyetracker.ConnectionError -= HandleConnectionError;

                // Trigger device-status-update event for IS1Node
                UpdateDeviceStatus(FTrackerInfo.Status);

                FConnectionName = info.ProductId;
                if (FSyncManager == null)
                {
                    FSyncManager = new SyncManager(FClock, info);
                    FSyncManager.SyncStateChanged += HandleSyncStateChanged;
                }

                SyncState st = FSyncManager.SyncState;
                if (st.StateFlag == SyncStateFlag.Unsynchronized)
                {
                    // TODO: handle the case that eyetracker is unsynchronized to make sure that et-status gets OK
                }

                // register eventhandlers
                FEyetracker.ConnectionError += HandleConnectionError;

                // trigger device-status-update event for IS1Node
                UpdateDeviceStatus(FTrackerInfo.Status);
            }
            catch (EyetrackerException ee)
            {
                if (ee.ErrorCode == 0x20000402)
                {
                    // trigger custom-error event for IS1Node
                    OnCustomError("EyetrackerException occured (errorCode " + ee.ErrorCode.ToString() + ") - Failed to upgrade protocol." +
                                  "This probably means that the firmware needs to be upgraded to a version that supports the new sdk.");
                }
                else
                {
                    // trigger custom-error event for IS1Node
                    OnCustomError("EyetrackerException occured (errorCode " + ee.ErrorCode.ToString() + ") - Eyetracker responded with error" + ee);
                }
                DisconnectEyetracker(false);
            }
            catch (Exception e)
            {
                // trigger custom-error event for IS1Node
                OnCustomError("Could not connect to eyetracker. " + "Connection failed" + "(" + e.Message + ")");
                DisconnectEyetracker(false);
            }
        }
コード例 #3
0
ファイル: TobiiTracker.cs プロジェクト: zhjh-stack/ogama
        /// <summary>
        /// This methods connects to the tracker.
        /// </summary>
        /// <param name="info">
        /// A <see cref="EyetrackerInfo"/>with information about the
        ///   eyetracker to connect to.
        /// </param>
        private void ConnectToTracker(EyetrackerInfo info)
        {
            try
            {
                connectedTracker = EyetrackerFactory.CreateEyetracker(info);
                connectedTracker.ConnectionError       += this.HandleConnectionError;
                this.tobiiSettings.ConnectedTrackerName = connectedTracker.GetUnitName();

                this.tobiiClock  = new Clock();
                this.syncManager = new SyncManager(this.tobiiClock, info);

                connectedTracker.GazeDataReceived += this.ConnectedTrackerGazeDataReceived;
                connectedTracker.StartTracking();
            }
            catch (EyetrackerException ee)
            {
                if (ee.ErrorCode == 0x20000402)
                {
                    MessageBox.Show(
                        Resources.TobiiTracker_ConnectToTrackerFailed,
                        "Upgrade Failed",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Eyetracker responded with error " + ee, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                this.DisconnectTracker();
            }
            catch (Exception)
            {
                MessageBox.Show(
                    "Could not connect to eyetracker.",
                    "Connection Failed",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                this.DisconnectTracker();
            }
        }
コード例 #4
0
        /// <summary>
        /// Connects to eyetracker and subscribes to events. Events are received on background thread.
        /// </summary>
        public void Connect()
        {
            try
            {
                eyetracker = EyetrackerFactory.CreateEyetracker(info, EventThreadingOptions.BackgroundThread);
                eyetracker.ConnectionError += ConnectionError;
                eyetracker.StartTracking();
            }
            catch (EyetrackerException ee)
            {
                Disconnect();
                if (ee.ErrorCode == 0x20000402)
                {
                    throw new Exception("Failed to upgrade protocol. Upgrade firmware to version 2.0.0 or higher.", ee);
                }

                throw ee;
            }
            catch (Exception e)
            {
                Disconnect();
                throw e;
            }
        }
コード例 #5
0
ファイル: EyetrackerNode.cs プロジェクト: vnmone/vvvv-sdk
        // called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FInit)
            {
                FEyetrackerInfoIn.Changed += new SpreadChangedEventHander <EyetrackerInfo>(FEyetrackerInfo_Changed);
            }

            if (!FXConfigSetToOutput && FUpdateIn.IsChanged && FUpdateIn[0] == true)
            {
                ReadAndOutputXConfig();
            }

            // Enabled true
            if ((FConnectionChanged || FEnable.IsChanged) && FEnable[0] == true)
            {
                try
                {
                    if (FEyetrackerInfo != null)
                    {
                        FEyetrackerOut.SliceCount = FEyetrackerInfoIn.SliceCount;
                        if (FSyncManager == null)
                        {
                            FClock       = new Clock();
                            FSyncManager = new SyncManager(FClock, FEyetrackerInfo);
                            FSyncManager.SyncManagerError += new EventHandler(FSyncManager_SyncManagerError);
                            FSyncManager.SyncStateChanged += new EventHandler <SyncStateChangedEventArgs>(FSyncManager_SyncStateChanged);
                        }

                        if (FEyetracker == null)
                        {
                            // get tracker representation from EyetrackerInfo
                            FEyetracker = EyetrackerFactory.CreateEyetracker(FEyetrackerInfo);
                            FEyetracker.ConnectionError       += new EventHandler <ConnectionErrorEventArgs>(FEyetracker_ConnectionError);
                            FEyetracker.XConfigurationChanged += new EventHandler <XConfigurationChangedEventArgs>(FEyetracker_XConfigurationChanged);
                            FEyetracker.FramerateChanged      += new EventHandler <FramerateChangedEventArgs>(FEyetracker_FramerateChanged);
                            FEyetrackerOut[0] = FEyetracker;
                            ReadAndOutputXConfig();
                        }
                    }
                }
                catch (EyetrackerException ex)
                {
                    if (ex.ErrorCode == 0x20000402)
                    {
                        // trigger custom-error event for IS1Node
                        FLogger.Log(LogType.Error, "EyetrackerException occured (errorCode " + ex.ErrorCode.ToString() + ") - Failed to upgrade protocol." +
                                    "This probably means that the firmware needs to be upgraded to a version that supports the new sdk.");
                    }
                    else
                    {
                        FLogger.Log(LogType.Error, "Error Code: " + ex.ErrorCode + " Message: " + ex.Message);
                    }
                }
                catch (Exception e)
                {
                    FLogger.Log(LogType.Error, "Could not connect to eyetracker. " + "Connection failed" + "(" + e.Message + ")");
                }
            }

            // Enabled false
            else if ((FConnectionChanged || FEnable.IsChanged) && FEnable[0] == false)
            {
                // disconnect and stop eye tracker correctly
                if (FEyetracker != null)
                {
                    FEyetracker.ConnectionError -= new EventHandler <ConnectionErrorEventArgs>(FEyetracker_ConnectionError);
                    FEyetracker.Dispose();
                    FEyetracker = null;
                    FEyetrackerOut.SliceCount = 1;
                }
                if (FSyncManager != null)
                {
                    FSyncManager.SyncManagerError -= new EventHandler(FSyncManager_SyncManagerError);
                    FSyncManager.SyncStateChanged -= new EventHandler <SyncStateChangedEventArgs>(FSyncManager_SyncStateChanged);
                    FSyncManager.Dispose();
                    FSyncManager = null;
                    FClock       = null;
                }
                frameCount   = 0;
                noXConfCount = 0;
            }

            // input params changed
            if (FSyncManager != null && FEyetracker != null)
            {
                if (FFramerateIn.IsChanged)
                {
                    FEyetracker.SetFramerate(FFramerateIn[0]);
                }

                if (FUpdateIn.IsChanged && FUpdateIn[0] == true)
                {
                    FSerial[0] = FEyetracker.GetUnitInfo().SerialNumber;
                    IList <float> Framerate = FEyetracker.EnumerateFramerates();
                    FFramerates.SliceCount = Framerate.Count;
                    if (Framerate.Count == 1)
                    {
                        FCurrentFramerate[0] = Framerate[0];
                    }
                    for (int i = 0; i < Framerate.Count; i++)
                    {
                        FFramerates[i] = Framerate[i];
                    }
                    try
                    {
                        IList <string> IlluminationModes = FEyetracker.EnumerateIlluminationModes();
                        FIlluminationMode.SliceCount = IlluminationModes.Count;
                        for (int i = 0; i < IlluminationModes.Count; i++)
                        {
                            FIlluminationMode[i] = IlluminationModes[i];
                        }
                    }
                    catch (EyetrackerException ex)
                    {
                        FLogger.Log(LogType.Error, "Could not set illumination mode, " + ex.Message);
                    }

                    XConfiguration x = FEyetracker.GetXConfiguration();
                    FLowerLeft[0]  = new Vector3D(x.LowerLeft.X, x.LowerLeft.Y, x.LowerLeft.Z) * 0.1;
                    FUpperLeft[0]  = new Vector3D(x.UpperLeft.X, x.UpperLeft.Y, x.UpperLeft.Z) * 0.1;
                    FUpperRight[0] = new Vector3D(x.UpperRight.X, x.UpperRight.Y, x.UpperRight.Z) * 0.1;
                }
                if (FXConfigurationIn.IsChanged)
                {
                    try
                    {
                        if (FXConfigurationIn[0] != null)
                        {
                            FEyetracker.SetXConfiguration(FXConfigurationIn[0]);
                        }
                    }
                    catch (Exception ee)
                    {
                        FLogger.Log(LogType.Error, "Could not set XConfiguration, " + ee.Message);
                    }
                }
            }

            if (FConnectionChanged && FEyetrackerInfo == null)
            {
                // Eyetracker has been disconnected, (recognized by error)
            }

            if (FEyetrackerInfoIn.IsChanged)
            {
            }
            FConnectionChanged = false;
            FInit = false;
        }