Beispiel #1
0
        /// <summary>
        /// Determines current charging status of the docked instrument.
        /// </summary>
        /// <returns>
        /// The returned DockingStationEvent is always null.
        /// </returns>
        /// <exception cref="InstrumentNotDockedException">
        /// If instrument is undocked
        /// </exception>
        /// <exception cref="InstrumentPingFailedException">
        /// Failure to turn on the instrument.
        /// </exception>
        public DockingStationEvent Execute()
        {
            if (Configuration.DockingStation.Type != DeviceType.MX4 && Configuration.DockingStation.Type != DeviceType.MX6)
            {
                return(null);
            }

            if (!Controller.IsDocked())
            {
                throw new InstrumentNotDockedException();
            }

            Log.Debug(this.Name + ".Execute");

            using (InstrumentController instrumentController = SwitchService.CreateInstrumentController())
            {
                // Turn on the instrument, the ask it for it's charging status
                try
                {
                    // Note that we deliberately do NOT use batch mode.  We're only trying to read a very
                    // few number of messages.  So it's not worth the effort and time it takes to negotiate
                    // faster baud rate and establish a batched connection to the instrument. It's much
                    // quicker to just read the few registers at the slow baud rate.
                    instrumentController.Initialize(InstrumentController.Mode.NoLid /* lid not necessary */);

                    InstrumentSerialNumber = instrumentController.GetSerialNumber();

                    BatteryCode = instrumentController.GetBatteryCode();

                    InstrumentChargePhase = instrumentController.GetChargePhase();

                    Log.Warning(string.Format("{0}: BatteryCode={1}, ChargePhase=\"{2}\"",
                                              this.Name, BatteryCode, InstrumentChargePhase));
                }
                catch (InstrumentPingFailedException ipef)                   // Couldn't turn on the instrument?
                {
                    // will get a ping failure if undocked.
                    if (!Controller.IsDocked())
                    {
                        throw new InstrumentNotDockedException();
                    }

                    Log.Error(this.Name, ipef);
                    throw;
                }
                catch (CommunicationAbortedException cae)                   // thrown by driver when instrument is undocked.
                {
                    Log.Error(this.Name, cae);
                    throw new InstrumentNotDockedException();
                }
            }
            return(null);
        }
        /// <summary>
        /// Executes an instrument discovery operation.
        /// </summary>
        /// <returns>Docking station event</returns>
        public DockingStationEvent Execute()
        {
            InstrumentNothingEvent instrumentNothingEvent;

            using (InstrumentController instrumentController = SwitchService.CreateInstrumentController())
            {
                // Create the return event.
                instrumentNothingEvent = new InstrumentNothingEvent(this);

                // Open the serial port connection needed to communicate with the instrument.
                instrumentController.Initialize();
            }

            return(instrumentNothingEvent);
        }
Beispiel #3
0
        private InstrumentNothingEvent DiscoverInstrument()
        {
            // Create the return event.
            InstrumentNothingEvent instrumentNothingEvent = new InstrumentNothingEvent(this);

            InstrumentController instrumentController = SwitchService.CreateInstrumentController();

            try
            {
                // Open the serial port connection needed to communicate with the instrument.
                instrumentController.Initialize(InstrumentController.Mode.Batch);

                // MX4 is the default instrument controller created for MX4 docking stations.
                if (instrumentController is MX4)
                {
                    // VPRO instrument controller may need created instead depending on type of docked instrument.
                    if (instrumentController.GetInstrumentType() == DeviceType.VPRO)
                    {
                        // Clean up MX4 controller.
                        instrumentController.Dispose();

                        // Create and initialize VPRO controller.
                        instrumentController = new VPRO();
                        instrumentController.Initialize(InstrumentController.Mode.Batch);
                    }
                }

                // If we make it through InstrumentController.Initialize without throwing, then
                // we assume the instrument is now on, or at least it's IrDA is.
                InstrumentOff = false;

                Stopwatch sw = new Stopwatch();
                sw.Start();

                // TxRxRetries value is returned by modbuslibrary.dll. It continally increments the value and never resets it back to zero.
                // So, before reading data from the instrument, we get the current value. Farther below, when we're finished reading, we get
                // the value again, and subtract this starting value to determine how many retries occurred during this particular discovery.
                // Getting this starting value also lets us subtract out any of the retries occurring during initializing above.
                int startTxRxRetries = instrumentController.Driver.TxRxRetries;

                // Retrieve the docked instrument.
                instrumentNothingEvent.DockedInstrument = instrumentController.DiscoverDockedInstrument(true);

                // INS-8228 RHP v7.6,  Service accounts need to perform auto-upgrade on instruments even in error/fail state
                Master.Instance.SwitchService.IsInstrumentInSystemAlarm = instrumentController.IsInstrumentInSystemAlarm;

                sw.Stop();
                int    txRxCount          = instrumentController.Driver.TxRxCount;
                double txRxCountPerSecond = (double)txRxCount / (sw.ElapsedMilliseconds / 1000.0);
                int    txRxRetries        = instrumentController.Driver.TxRxRetries - startTxRxRetries;
                Log.Debug(string.Format("Modbus statistics:  stopwatch={0}ms, TxRx={1} ({2}/s), retries={3}",
                                        sw.ElapsedMilliseconds, txRxCount, txRxCountPerSecond.ToString("f0"), txRxRetries));
            }
            catch (InstrumentSystemAlarmException) // SGF  Nov-23-2009  DSW-355  (DS2 v7.6)
            {
                // If the user docked an instrument in system alarm, then just rethrow up to the service
                // that invoked this discovery and let it deal with it.
                throw;
            }
            catch (HardwareConfigurationException)
            {
                // If user failed to reconfigure the docking station hardware, then just rethrow up to the service
                // that invoked this discovery and let it deal with it.
                throw;
            }
            catch (Exception e)
            {
                Log.Error(this.GetType().ToString() + ".Execute.DiscoverDockedInstrument", e);

                // ********************************************************************
                // See INS-6671 and INS-6682 as to why the second discover was removed.
                // ********************************************************************

                throw;
            } // end-catch
            finally
            {
                instrumentController.Dispose();
            }

            return(instrumentNothingEvent);
        }
        /// <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);
        }
Beispiel #5
0
        /// <summary>
        /// Executes an instrument settings update operation.
        /// </summary>
        /// <returns>Docking station event</returns>
        public DockingStationEvent Execute()
        {
            Stopwatch stopwatch = Log.TimingBegin("INSTRUMENT SETTINGS UPDATE");

            // Check for a docked instrument.
            if (!Master.Instance.ControllerWrapper.IsDocked())
            {
                throw new InstrumentNotDockedException();
            }

            string     serialNumber   = Master.Instance.SwitchService.Instrument.SerialNumber;
            DeviceType instrumentType = Master.Instance.SwitchService.Instrument.Type;

            if (serialNumber == string.Empty || instrumentType == DeviceType.Unknown)
            {
                throw new InstrumentNotDockedException();
            }

            // Create the return event.
            _instrumentSettingsUpdateEvent = new InstrumentSettingsUpdateEvent(this);

            // Retrieve the docking station's information.
            _instrumentSettingsUpdateEvent.DockingStation = Master.Instance.ControllerWrapper.GetDockingStation();
            _instrumentSettingsUpdateEvent.DockedTime     = Master.Instance.SwitchService.DockedTime;

            // Get the settings from the database to update the instrument with.
            Instrument settings = new InstrumentDataAccess().FindApplicableSettings(serialNumber, instrumentType);

            // If no instrument settings found, then there's nothing more we can do.
            // since we can't update the instrument's settings if we have no settings.
            if (settings == null)
            {
                string errMsg = string.Format("Unable to find instrument settings for S/N \"{0}\"", serialNumber);
                _instrumentSettingsUpdateEvent.Errors.Add(new DockingStationError(errMsg, DockingStationErrorLevel.Warning));
                return(_instrumentSettingsUpdateEvent);
            }

            // The settings loaded only apply to the discovered instrument.
            // We don't know if the settings loaded are the defaults are not
            // so we just set the type to what we searched for above.
            settings.Type = instrumentType;

            // Merge the loaded settings with our Instrument.

            using (_instCtrlr = SwitchService.CreateInstrumentController())
            {
                // Open the serial port connection needed to communicate with the instrument.
                _instCtrlr.Initialize(InstrumentController.Mode.Batch);

                // After an instrument settings read, we need to send a command to the instrument
                // to have it clear its base unit log.  Only SafeCore needs this command.
                _instCtrlr.ClearBaseUnits();

                // Update the docked instrument.
                _instrumentSettingsUpdateEvent.DockedInstrument = UpdateInstrument(settings, serialNumber);

                // Settings RefId will contain the ID of the settings used during the Update Event.  Otherwise, will be Nullid.
                // We place it into the event's Instrument in order to upload it to iNet.
                _instrumentSettingsUpdateEvent.DockedInstrument.RefId = settings.RefId;

                if (_instrumentSettingsUpdateEvent.DockingStation.ClearPeaksUponDocking)
                {
                    _instCtrlr.ClearInstrumentSensorPeaks(_instrumentSettingsUpdateEvent.DockedInstrument.InstalledComponents);
                }
            } // end-using

            Log.TimingEnd("INSTRUMENT SETTINGS UPDATE", stopwatch);

            return(_instrumentSettingsUpdateEvent);
        }