// helper private void DisconnectEyetracker(bool DoRescan) { if (FEyetracker != null) { FEyetracker.ConnectionError -= HandleConnectionError; FEyetracker.Dispose(); FEyetracker = null; FConnectionName = string.Empty; FSyncManager.Dispose(); UpdateDeviceStatus(FTrackerInfo.Status); if (!FEyetrackerBrowser.IsStarted) { if (DoRescan) { FEyetrackerBrowser.Start(); } } if (FEyetrackerBrowser.IsStarted) { FEyetrackerBrowser.Stop(); } } }
/// <summary> /// Handles the Shutdown event of the ThisAddIn control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { if (stopped) { return; } stopped = true; syncManager.Dispose(); }
protected override void OnStop() { manager.Dispose(); manager = null; }
// 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; }