/// <summary> /// Executes an instrument bump test operation. /// </summary> /// <returns>The completed event for this bump test.</returns> /// <exception cref="FailedBumpTestException"> /// If anything extraordinary happened during the bump test. /// </exception> public DockingStationEvent Execute() { //Clear if any flags before initiating calibration once again Pump.IsBadPumpTubing = false; // iNetDS Master.Instance.SwitchService.BadPumpTubingDetectedDuringCal = false; // iNetDS Master.Instance.SwitchService.BadPumpTubingDetectedDuringBump = false; // iNetDS Stopwatch operationStopwatch = Log.TimingBegin("INSTRUMENT BUMP TEST"); // iNetDS _returnEvent = new InstrumentBumpTestEvent(this); _returnEvent.DockedInstrument = this.Instrument; // TODO _returnEvent.DockingStation = this.DockingStation; // TODO //_detailsBuilder = new DetailsBuilder(EventDetails); // _detailsBuilder = new DetailsBuilder(InstrumentHelper.EventDetails); // IDS //Throw Exception if Instrument is undocked if (!Master.Instance.ControllerWrapper.IsDocked()) { throw new InstrumentNotDockedException(); } _returnEvent.Trigger = Trigger; _returnEvent.IsSensorFailureModeEnabled = IsSensorFailureModeEnabled; // DSW-1034 RHP Tango TODO IDS _returnEvent.IsSCSensorFailureModeEnabled = IsSCSensorFailureModeEnabled; // DSW-1068 RHP v9.5 TODO IDS Log.Debug(string.Format("{0}.Execute {1}", Name, _returnEvent.DockedInstrument.SerialNumber)); // Add the detail header. //_detailsBuilder.Add("", "DETAILS_BUMP_TEST_HEADER", string.Empty); // IDS //_detailsBuilder.AddNewLine(); // IDS //_detailsBuilder.Add(" ", "DETAILS_INSTRUMENT_BUMPTHRESHOLD", this.BumpThreshold); // IDS //_detailsBuilder.Add(" ", "DETAILS_INSTRUMENT_BUMPTIMEOUT", this.BumpTimeout); // IDS _returnEvent.DockedInstrument.InstalledComponents = InstrumentController.SortSensorsByBumpOrder(_returnEvent.DockedInstrument.InstalledComponents); // #region LogDebug Log.Debug("Candidate gases..."); int pointCount = 0; foreach (GasEndPoint gasEndPoint in GasEndPoints) { string msg = "GasEndPoint #" + ++pointCount; Log.Debug(msg); Cylinder cyl = gasEndPoint.Cylinder; msg = "...Pos " + gasEndPoint.Position + ", FactID=" + cyl.FactoryId + ", Part=" + cyl.PartNumber + ", Fresh=" + cyl.IsFreshAir + ", ZeroAir=" + cyl.IsZeroAir + ", Pressure=" + cyl.Pressure.ToString(); if (gasEndPoint.Cylinder.Volume != DomainModelConstant.NullInt) { msg += ", Vol=" + gasEndPoint.Cylinder.Volume; } Log.Debug(msg); msg = "......"; foreach (GasConcentration gasCon in cyl.GasConcentrations) { msg += "[" + gasCon.Type.Code + " "; msg += (gasCon.Concentration == DomainModelConstant.NullDouble) ? "fresh" : gasCon.Concentration.ToString(); msg += "]"; } Log.Debug(msg); } Log.Debug("Going to BUMP sensors in following ORDER..."); int bumpOrder = 1; foreach (InstalledComponent ic in _returnEvent.DockedInstrument.InstalledComponents) { if (!(ic.Component is Sensor)) { continue; // It its not a sensor, ignore it. } Log.Debug("...#" + bumpOrder++ + ", Position " + ic.Position + ", UID=" + ic.Component.Uid + ", " + ic.Component.Type.Code); } #endregion // Open the serial port connection needed to communicate with the instrument. try { Stopwatch pingStopwatch = Log.TimingBegin("BUMP - PING"); _instrumentController.Initialize(); // Add a new line and section to the details. //_detailsBuilder.AddNewLine(); Log.TimingEnd("BUMP - PING", pingStopwatch); // See if there are any already failed sensors - go to calibration if there are. // TODO move this section for IDS prior to initiating Bump Test, probably something similar to iNetDS Scheduler // Load the BumpTimout and BumpThreshold from the database needed to perform the bump. LoadBumpLimits(); // TODO update for IDS, LOAD THESE INTO INSTRUMETN ACTION BEFORE BUMP TEST BumpInstrument(); // Need to determine the next time this instrument will be bumped. // Put this date into the event so it can be uploaded to iNet, and also // update the global next date that's held in the switch service. _returnEvent.NextUtcScheduledDate = Master.Instance.SwitchService.NextUtcBumpDate = Master.Instance.Scheduler.GetNextGasOperationDate(_returnEvent); } finally { _instrumentController.Dispose(); } Log.TimingEnd("INSTRUMENT BUMP TEST", operationStopwatch); // IDS Updates Sensor's Bump Test Status on Cached Instrument - TODO TO BE HANDLED IN EVENT PROCESSOR FOR IDS. // Send back the results. return(_returnEvent); }
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> /// IOperating implementation. Performs an instrument calibration operation. /// </summary> /// <returns>Docking station event</returns> public DockingStationEvent Execute() { //Clear if any flags before initiating calibration once again Pump.IsBadPumpTubing = false; Master.Instance.SwitchService.BadPumpTubingDetectedDuringCal = false; Master.Instance.SwitchService.BadPumpTubingDetectedDuringBump = false; Stopwatch stopwatch = Log.TimingBegin("INSTRUMENT CALIBRATION"); _returnEvent.DockedInstrument = (ISC.iNet.DS.DomainModel.Instrument)Master.Instance.SwitchService.Instrument.Clone(); _returnEvent.DockingStation = Master.Instance.ControllerWrapper.GetDockingStation(); Log.Debug( string.Format( "{0}.Execute {1}", Name, _returnEvent.DockedInstrument.SerialNumber ) ); // Sort sensors by calibration order. _returnEvent.DockedInstrument.InstalledComponents = InstrumentController.SortSensorsByCalibrationOrder( _returnEvent.DockedInstrument.InstalledComponents ); #region LogDebug Log.Debug( "Candidate gases..." ); int pointCount = 0; foreach ( GasEndPoint gasEndPoint in GasEndPoints ) { string msg = "GasEndPoint #" + ++pointCount; Log.Debug(msg); Cylinder cyl = gasEndPoint.Cylinder; msg = "...Pos: " + gasEndPoint.Position //+ ", ID: " + cyl.ID + ", FactID: " + cyl.FactoryId + ", Part: " + cyl.PartNumber + ", Fresh: " + cyl.IsFreshAir + ", ZeroAir: " + cyl.IsZeroAir + ", Pressure: " + cyl.Pressure.ToString(); Log.Debug( msg ); msg = "......"; foreach ( GasConcentration gasCon in cyl.GasConcentrations ) { msg += "[" + gasCon.Type.Code + " "; msg += ( gasCon.Concentration == DomainModelConstant.NullDouble ) ? "fresh" : gasCon.Concentration.ToString(); msg += "]"; } Log.Debug( msg ); } Log.Debug( "Going to CALIBRATE sensors in following ORDER..." ); int calOrder = 1; foreach ( InstalledComponent ic in _returnEvent.DockedInstrument.InstalledComponents ) { if ( !( ic.Component is Sensor ) ) continue; // Skip non-sensors. Log.Debug( "...#" + calOrder++ + ", Position " + ic.Position + ", UID=" + ic.Component.Uid + ", " + ic.Component.Type.Code ); } #endregion try { _instrumentController.Initialize(); CalibrateInstrument(); // Need to determine the next time this instrument will be calibrated. // Put this date into the event so it can be uploaded to iNet, and also // update the global next date that's held in the switch service. _returnEvent.NextUtcScheduledDate = Master.Instance.SwitchService.NextUtcCalibrationDate = Master.Instance.Scheduler.GetNextGasOperationDate( _returnEvent ); } finally { // Dispose of the operation utility. _instrumentController.Dispose(); } Log.TimingEnd( "INSTRUMENT CALIBRATION", stopwatch ); return _returnEvent; }