/// <summary> /// Executes a turn off instrument operation. /// </summary> /// <returns>A InstrumentTurnOffEvent, which contains the TurnOffAction /// indicating what exactly the Execute() decided to do. /// </returns> /// <exception cref="InstrumentNotDockedException">If an instrument is not docked.</exception> public DockingStationEvent Execute() { string funcName = Name + ".Execute"; Log.Debug(funcName + ", Reason=" + _reason); InstrumentTurnOffEvent _returnEvent = new InstrumentTurnOffEvent(this); #if DEBUG // When debugging, don't turn off the GBPROs since they annoyingly take too long to turn back on. if (Configuration.DockingStation.Type == DeviceType.GBPRO) { _returnEvent.TurnOffAction = TurnOffAction.None; Log.Info(string.Format("{0}.Execute doing nothing due to DEBUG directive", Name)); return(_returnEvent); } #endif _returnEvent.TurnOffAction = GetTurnOffAction(); if (_returnEvent.TurnOffAction == TurnOffAction.NotSupported) { Log.Warning(string.Format("{0}: Docked {1}'s cannot be turned off.", funcName, Configuration.DockingStation.Type)); return(_returnEvent); } else if (_returnEvent.TurnOffAction == TurnOffAction.None) { Log.Warning(string.Format("{0}: Docked {1} should already be off.", funcName, Configuration.DockingStation.Type)); return(_returnEvent); } else { if (!Controller.IsDocked()) { throw new InstrumentNotDockedException(); } using (InstrumentController instrumentController = SwitchService.CreateInstrumentController()) { // Note that we specify NoPing. This causes the instrument controller to *not* call the // driver's connect method. instrumentController.Initialize(InstrumentController.Mode.NoPing); try { if (_returnEvent.TurnOffAction == TurnOffAction.Shutdown) { // Even the instruments which cannot shutdown will have this called // so their sensors get turned off. instrumentController.TurnOff(); } else if (_returnEvent.TurnOffAction == TurnOffAction.TurnOffSensors) { if (instrumentController.GetOperatingMode() == OperatingMode.WarmingUp) { // MX6 instrument does not support going to Charging mode when it is currently WarmingUp. // So we need to try again later after the instrument has transitioned to Running. _returnEvent.TurnOffAction = TurnOffAction.Postponed; Log.Debug(funcName + ", WAITING FOR WARM UP TO COMPLETE. TURN OFF POSTPONED."); } else { // This should only need to be called for MX6 rechargeable instruments. instrumentController.TurnOnSensors(false, false); } } } catch (CommunicationException ce) { Log.Debug(funcName + " caught CommunicationException: " + (Log.Level >= LogLevel.Trace ? ce.ToString() : ce.Message)); Log.Debug(funcName + " FAILED. Instrument might already be in OFF state."); } } } return(_returnEvent); }