// Ignore Spelling: Uut using NLog; using Raytheon.Instruments; using Raytheon.Units; using System; using System.Windows; using System.Collections.Generic; using System.Drawing; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; namespace MeasurementManagerLib { public class SpaceChamberLSPSMeasurementManager { private INetCdfData netCdfData_ = null; private readonly ILspsChamber lspsChamber_; private readonly ILogger _logger; /// /// TODO: add video recorder instrument name as parameter /// constructor that uses instrument manager for creating an instrument /// /// /// public SpaceChamberLSPSMeasurementManager(IInstrumentManager instrumentManager, string lspsChamber, string netCdfData) { _logger = LogManager.GetCurrentClassLogger(); _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); lspsChamber_ = instrumentManager.GetInstrument(lspsChamber); if (lspsChamber_ == null) { throw new Exception($"Instrument manager failed to create LSPS Chamber Device {lspsChamber}. Check your settings."); } lspsChamber_.Initialize(); netCdfData_ = instrumentManager.GetInstrument(netCdfData); if (netCdfData_ == null) { throw new Exception($"Instrument manager failed to create NetCdfData Device {netCdfData}. Check your settings."); } } /// /// shuts down LSPS manager, clears resources /// public void Shutdown() { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); lspsChamber_?.Shutdown(); } #region Autofill functions /// /// Auto Fill Cool Down /// public void AutoFillCoolDown(int pollingRateInMs = 1000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.AutoFillCoolDown(); Raytheon.Instruments.LSPS.AutoFillState state; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Autofill to transition to cooling. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); state = lspsChamber_.GetAutoFillState(); } while (state != Raytheon.Instruments.LSPS.AutoFillState.COOLING); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Auto Fill Warm Up /// public void AutoFillWarmUp(int pollingRateInMs = 1000, int timeOutInMs = 10000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.AutoFillWarmUp(); Raytheon.Instruments.LSPS.AutoFillState state; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Autofill to transition to cooling. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); state = lspsChamber_.GetAutoFillState(); } while (state != Raytheon.Instruments.LSPS.AutoFillState.WARMING); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Auto Fill Force /// public void AutoFillForce() { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_?.AutoFillForce(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Auto Fill Turn Off /// public void AutoFillTurnOff(int pollingRateInMs = 1000, int timeOutInMs = 60000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.AutoFillTurnOff(); Raytheon.Instruments.LSPS.AutoFillState state; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Autofill to transition to cooling. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); state = lspsChamber_.GetAutoFillState(); } while (state != Raytheon.Instruments.LSPS.AutoFillState.OFF); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } #endregion #region NIF Functions /// /// Close Gate Valve /// public void CloseLspsGateValve(int pollingRateInMs = 1000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_?.CloseLspsGateValve(); WaitForLspsGateValveOperation(Raytheon.Instruments.LSPS.GateValvePosition.CLOSE, pollingRateInMs, timeOutInMs); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Open Gate Valve /// public void OpenLspsGateValve(int pollingRateInMs = 1000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_?.OpenLspsGateValve(); WaitForLspsGateValveOperation(Raytheon.Instruments.LSPS.GateValvePosition.OPEN, pollingRateInMs, timeOutInMs); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Wait for UUT Gate Valve to be in position /// private void WaitForLspsGateValveOperation(Raytheon.Instruments.LSPS.GateValvePosition gateValvePosition, int pollingRateInMs, int timeOutInMs) { int val = 0; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for LSPS Gate Valve to {gateValvePosition.ToString()}. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); val = lspsChamber_.GetInputIndex((int)gateValvePosition); } while (val == 0); stopwatch.Stop(); } /// /// Get UUT Gate Valve Position /// public double GetTemperature(Raytheon.Instruments.LSPS.TemperatureIndex tempIndex) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { return lspsChamber_.GetTemperature(tempIndex); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } #endregion #region RIO Functions /// /// Close Gate Valve /// public void CloseVhfGateValve(int pollingRateInMs = 1000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_?.CloseVhfGateValve(); WaitForVhfGateValveOperation(Raytheon.Instruments.LSPS.GateValvePosition.CLOSE, pollingRateInMs, timeOutInMs); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Open Gate Valve /// public void OpenVhfGateValve(int pollingRateInMs = 1000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_?.OpenVhfGateValve(); WaitForVhfGateValveOperation(Raytheon.Instruments.LSPS.GateValvePosition.OPEN, pollingRateInMs, timeOutInMs); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Wait for VHF Gate Valve to be in position /// private void WaitForVhfGateValveOperation(Raytheon.Instruments.LSPS.GateValvePosition gateValvePosition, int pollingRateInMs, int timeOutInMs) { int val = 0; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for VHF Gate Valve to {gateValvePosition.ToString()}. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); if (gateValvePosition == Raytheon.Instruments.LSPS.GateValvePosition.OPEN) val = lspsChamber_.GetVhfGateValveOpenInput(); else val = lspsChamber_.GetVhfGateValveClosedInput(); } while (val == 0); stopwatch.Stop(); } /// /// Verify Gate Valve Chamber Pressure /// public void VerifyGateValveChamberPressure(double minLimit, double maxLimit) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { double val = lspsChamber_.GetVhfGateValveChamberPressure(); if (val < minLimit || val > maxLimit) { throw new Exception($"Gate valve chamber pressure is out of range. Measured: {val}. Limits: [{minLimit}, {maxLimit}]"); } } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Verify Gate Valve Canister Pressure /// public void VerifyGateValveCanisterPressure(double minLimit, double maxLimit) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { double val = lspsChamber_.GetVhfGateValveUutPressure(); if (val < minLimit || val > maxLimit) { throw new Exception($"Gate valve canister pressure is out of range. Measured: {val}. Limits: [{minLimit}, {maxLimit}]"); } } catch (Exception ex) { _logger.Error(ex.Message); throw; } } #endregion #region Chamber Vacuum Functions /// /// Verify Chamber Pressure (CVAC) /// public void VerifyLspsChamberPressure(double minLimit, double maxLimit) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { double val = lspsChamber_.GetLspsChamberPressure(); if (val < minLimit || val > maxLimit) { throw new Exception($"PLC Chamber pressure is out of range. Measured: {val}. Limits: [{minLimit}, {maxLimit}]"); } } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Verify Sensor Pressure (SVAC) /// public void VerifyLspsUutPressure(double minLimit, double maxLimit) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { double val = lspsChamber_.GetLspsUutPressure(); if (val < minLimit || val > maxLimit) { throw new Exception($"PLC Chamber pressure is out of range. Measured: {val}. Limits: [{minLimit}, {maxLimit}]"); } } catch (Exception ex) { _logger.Error(ex.Message); throw; } } #endregion #region GALIL Functions public void FilterWheelHome(int pollingRateInMs = 2000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.FilterWheelHome(); Raytheon.Instruments.LSPS.TargetAndFilterWheelStatus status; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for FilterWheel to home. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); status = lspsChamber_.GetFilterWheelStatus(); } while (status != Raytheon.Instruments.LSPS.TargetAndFilterWheelStatus.IN_POSITION); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Set Filter Wheel position /// /// public void SetFilterWheelPosition(int position, int pollingRateInMs = 2000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SetFilterWheelPosition(position); Raytheon.Instruments.LSPS.TargetAndFilterWheelStatus status; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for FilterWheel to move. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); status = lspsChamber_.GetFilterWheelStatus(); } while (status != Raytheon.Instruments.LSPS.TargetAndFilterWheelStatus.IN_POSITION); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Get Filter Wheel position /// /// public int GetFilterWheelPosition() { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { return lspsChamber_.GetFilterWheelPosition(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void TargetWheelHome(int pollingRateInMs = 2000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.TargetWheelHome(); Raytheon.Instruments.LSPS.TargetAndFilterWheelStatus status; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for TargetWheel to home. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); status = lspsChamber_.GetTargetWheelStatus(); } while (status != Raytheon.Instruments.LSPS.TargetAndFilterWheelStatus.IN_POSITION); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Sets target wheel position /// /// public void SetTargetWheelPosition(int position, int pollingRateInMs = 2000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SetTargetWheelPosition(position); Raytheon.Instruments.LSPS.TargetAndFilterWheelStatus status; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for TargetWheel to move. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); status = lspsChamber_.GetTargetWheelStatus(); } while (status != Raytheon.Instruments.LSPS.TargetAndFilterWheelStatus.IN_POSITION); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void SteeringMirrorHome(int pollingRateInMs = 2000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SteeringMirrorHome(); Tuple steeringMirrorStatus; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Steering Mirror to home. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); steeringMirrorStatus = lspsChamber_.GetSteeringMirrorStatus(); } while (steeringMirrorStatus.Item1 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION || steeringMirrorStatus.Item2 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Get target wheel position /// /// public int GetTargetWheelPosition() { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { return lspsChamber_.GetTargetWheelPosition(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void SteeringMirrorStop(int pollingRateInMs = 2000, int timeOutInMs = 10000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SteeringMirrorStop(); Tuple steeringMirrorStatus; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Steering Mirror to stop. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); steeringMirrorStatus = lspsChamber_.GetSteeringMirrorStatus(); } while (steeringMirrorStatus.Item1 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION || steeringMirrorStatus.Item2 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void SteeringMirrorMove(double az, double el, double speed, Raytheon.Instruments.LSPS.WaitOption waitOption = Raytheon.Instruments.LSPS.WaitOption.WAIT, int pollingRateInMs = 2000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SteeringMirrorMove(az, el, speed); if (waitOption == Raytheon.Instruments.LSPS.WaitOption.WAIT) { Tuple steeringMirrorStatus; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Steering Mirror to move. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); steeringMirrorStatus = lspsChamber_.GetSteeringMirrorStatus(); } while (steeringMirrorStatus.Item1 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION || steeringMirrorStatus.Item2 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION); stopwatch.Stop(); } } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public Tuple SteeringMirrorGetBeamAngles() { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { return lspsChamber_.SteeringMirrorGetBeamAngles(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void SteeringMirrorSetBeamSpeed(double speed) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_?.SteeringMirrorSetBeamSpeed(speed); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void SteeringMirrorSetRightLeftArrowAngle(double angle) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_?.SteeringMirrorSetRightLeftArrowAngle(angle); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void SteeringMirrorSetUpDownArrowAngle(double angle) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_?.SteeringMirrorSetUpDownArrowAngle(angle); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void SteeringMirrorLoadProfile(string profileFilePath) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_?.SteeringMirrorLoadProfileFromFile(profileFilePath); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void SteeringMirrorResetProfile() { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_?.SteeringMirrorResetProfile(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void SteeringMirrorRunProfile(Raytheon.Instruments.LSPS.SteeringMirrorProfileMode profileMode = Raytheon.Instruments.LSPS.SteeringMirrorProfileMode.LEARNED, Raytheon.Instruments.LSPS.SteeringMirrorMovementMode movementMode = Raytheon.Instruments.LSPS.SteeringMirrorMovementMode.ABSOLUTE, Raytheon.Instruments.LSPS.WaitOption waitOption = Raytheon.Instruments.LSPS.WaitOption.NO_WAIT, int pollingRateInMs = 2000, int timeOutInMs = 360000 ) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SteeringMirrorSetBeamSpeed(12000); lspsChamber_.SteeringMirrorRunProfile(profileMode, movementMode); if (waitOption == Raytheon.Instruments.LSPS.WaitOption.WAIT) { Tuple steeringMirrorStatus; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Steering Mirror to complete profile move. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); steeringMirrorStatus = lspsChamber_.GetSteeringMirrorStatus(); } while (steeringMirrorStatus.Item1 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION || steeringMirrorStatus.Item2 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION); stopwatch.Stop(); } } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void SteeringMirrorMoveToBeginningOfProfile(Raytheon.Instruments.LSPS.WaitOption waitOption = Raytheon.Instruments.LSPS.WaitOption.WAIT, int pollingRateInMs = 2000, int timeOutInMs = 240000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SteeringMirrorMoveToBeginningOfProfile(); if (waitOption == Raytheon.Instruments.LSPS.WaitOption.WAIT) { Tuple steeringMirrorStatus; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Steering Mirror to move. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); steeringMirrorStatus = lspsChamber_.GetSteeringMirrorStatus(); } while (steeringMirrorStatus.Item1 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION || steeringMirrorStatus.Item2 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION); stopwatch.Stop(); } } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void SteeringMirrorRunNextStepInProfile(Raytheon.Instruments.LSPS.WaitOption waitOption = Raytheon.Instruments.LSPS.WaitOption.WAIT, int pollingRateInMs = 2000, int timeOutInMs = 30000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SteeringMirrorRunNextStepInProfile(); if (waitOption == Raytheon.Instruments.LSPS.WaitOption.WAIT) { Tuple steeringMirrorStatus; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Steering Mirror to move. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); steeringMirrorStatus = lspsChamber_.GetSteeringMirrorStatus(); } while (steeringMirrorStatus.Item1 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION || steeringMirrorStatus.Item2 != Raytheon.Instruments.LSPS.SteeringMirrorStatus.IN_POSITION); stopwatch.Stop(); } } catch (Exception ex) { _logger.Error(ex.Message); throw; } } #endregion #region BlackBody Functions /// /// Set BlackBody Setpoint Temperature /// /// /// /// public void SetBlackBodySetpointTemperature(double temperature, Raytheon.Instruments.LSPS.WaitOption waitOption = Raytheon.Instruments.LSPS.WaitOption.NO_WAIT, int pollingRateInMs = 2000, int timeOutInMs = 600000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SetBlackBodySetpointTemperature(temperature); if (waitOption == Raytheon.Instruments.LSPS.WaitOption.WAIT) { ConfirmBlackBodySetpointTemperature(temperature, pollingRateInMs, timeOutInMs); } } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Confirm BlackBody Setpoint Temperature /// /// /// /// public void ConfirmBlackBodySetpointTemperature(double temperature, int pollingRateInMs = 2000, int timeOutInMs = 600000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { const double TEMP_DELTA_ALLOWED = 0.1; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Tuple temp; do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for blackbody to reach temperature setpoint. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); temp = lspsChamber_.GetBlackbodyTemperature(); } while (Math.Abs(temp.Item1 - temperature) >= TEMP_DELTA_ALLOWED); Tuple stability; do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for blackbody's temperature to stabilize. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); stability = lspsChamber_.GetBlackbodyStability(); } while (stability.Item1 != Raytheon.Instruments.LSPS.Stability.STABLE); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } #endregion #region Chopper Functions /// /// Set Chopper Frequency /// /// public void SetChopperFrequency(double frequency, int pollingRateInMs = 1000, int timeOutInMs = 600000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SetChopperFrequency(frequency); const double FREQ_DELTA_ALLOWED = 0.0001; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Chopper to reach frequency setpoint. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); } while (Math.Abs(lspsChamber_.GetChopperFrequency() - frequency) >= FREQ_DELTA_ALLOWED); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Chopper to stabilize. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); } while (lspsChamber_.GetChopperStability() != Raytheon.Instruments.LSPS.Stability.STABLE); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Turn off Chopper wheel /// public void TurnOffChopperWheel(int pollingRateInMs = 1000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.TurnOffChopperWheel(); Raytheon.Instruments.LSPS.ChopperState state; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Chopper Wheel to turn off. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); state = lspsChamber_.GetChopperState(); } while (state != Raytheon.Instruments.LSPS.ChopperState.OFF); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Stop chopper wheel at open position /// public void SetStopOpen(int pollingRateInMs = 1000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SetStopOpen(); Raytheon.Instruments.LSPS.ChopperState state; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Chopper Wheel to stop in Open position. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); state = lspsChamber_.GetChopperState(); } while (state != Raytheon.Instruments.LSPS.ChopperState.STOP_OPEN); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Chopper Wheel to stabilize. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); } while (lspsChamber_.GetChopperStability() != Raytheon.Instruments.LSPS.Stability.STABLE); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } /// /// Stop chopper wheel at closed position /// public void SetStopClosed(int pollingRateInMs = 1000, int timeOutInMs = 120000) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SetStopClosed(); Raytheon.Instruments.LSPS.ChopperState state; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Chopper Wheel to stop in Closed position. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); state = lspsChamber_.GetChopperState(); } while (state != Raytheon.Instruments.LSPS.ChopperState.STOP_CLOSE); do { if (stopwatch.ElapsedMilliseconds > timeOutInMs) { throw new Exception($"Timed out waiting for Chopper Wheel to stabilize. Timeout value: {timeOutInMs} ms"); } Thread.Sleep(pollingRateInMs); } while (lspsChamber_.GetChopperStability() != Raytheon.Instruments.LSPS.Stability.STABLE); stopwatch.Stop(); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } #endregion #region Misc Functions /// /// Send A Command. Only for SET commands. /// DO NOT use for GET Commands as they require processing of returned data /// /// public void SendACommand(string command) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { lspsChamber_.SendACommand(command); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void ProcessNcdfData(string prefix, string suffix, string testDataPath) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); try { netCdfData_.ProcessNcdfData(prefix, suffix, testDataPath); } catch (Exception ex) { _logger.Error(ex.Message); throw; } } public void AddNcdfAttributes() { //-----------------------------Autofill------------------------------------ netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_AUTOFILL_TIMETOFILL, lspsChamber_.GetTimeToFill(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_AUTOFILL_STATE, lspsChamber_.GetAutoFillState().ToString(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); //-----------------------------Blackbody------------------------------------ netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.MEASURED_BLACK_BODY_TEMPERATURE, lspsChamber_.GetBlackbodyTemperature().Item1, Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_BB_RATE_O_CHANGE, lspsChamber_.GetBlackbodyRateOfChange(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_BB_CTRL_STATE, lspsChamber_.GetBlackbodyControlState().ToString(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_BB_HEATER, lspsChamber_.GetBlackbodyHeaterPercent(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_BB_SETPOINT, lspsChamber_.GetBlackbodySetpoint(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_BB_STABILITY_A, lspsChamber_.GetBlackbodyStability().Item1.ToString(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_BB_STABILITY_B, lspsChamber_.GetBlackbodyStability().Item2.ToString(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_BB_BIT, lspsChamber_.GetBlackbodyBIT(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); //-----------------------------CVAC------------------------------------ netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_C_VAC, lspsChamber_.GetLspsChamberPressure(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_S_VAC, lspsChamber_.GetLspsUutPressure(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); //-----------------------------Chopper------------------------------------ netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_CHOPPER_FREQ, lspsChamber_.GetChopperFrequency(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_CHOPPER_STABILITY, lspsChamber_.GetChopperStability().ToString(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_CHOPPER_STATE, lspsChamber_.GetChopperState().ToString(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); //-----------------------------Galil------------------------------------ netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.TARGET_WHEEL_POSITION, lspsChamber_.GetTargetWheelPosition(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.MEASURED_APERTURE_POSITION, lspsChamber_.GetTargetWheelPosition(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.MEASURED_AZ_POSITION, lspsChamber_.SteeringMirrorGetBeamAngles().Item1, Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.MEASURED_EL_POSITION, lspsChamber_.SteeringMirrorGetBeamAngles().Item2, Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.MEASURED_FILTER_POSITION, lspsChamber_.GetFilterWheelPosition(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.SCAN_PATTERN, "oscillate", Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); //-----------------------------NIF------------------------------------ netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_NIF_TEMP_TANK_TOP, lspsChamber_.GetTemperature(Raytheon.Instruments.LSPS.TemperatureIndex.TANK_TOP), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_NIF_TEMP_TANK_BOTTOM, lspsChamber_.GetTemperature(Raytheon.Instruments.LSPS.TemperatureIndex.TANK_BOTTOM), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.RADCAL_GATE_VALVE, lspsChamber_.GetLspsGateValvePosition().ToString(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.L_S_P_S_GATE_VALVE_STATUS, lspsChamber_.GetLspsGateValvePosition().ToString(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); //-----------------------------RIO------------------------------------ netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.VHF_GV_CHAMBER_VAC, lspsChamber_.GetVhfGateValveChamberPressure(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); netCdfData_.SetValue(Raytheon.Instruments.NCDF.Names.VHF_GV_UUT_VAC, lspsChamber_.GetVhfGateValveUutPressure(), Raytheon.Instruments.NCDF.AttrPosition.GLOBAL); } /// /// Balance On Pixel Location /// /// /// /// /// /// public void BalanceOnPixelLocation(int pixelX, int pixelY, double chopperRate, double minAmp, double maxOE) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); //_lspsVideo?.BalanceOnPixelLocation(pixelX, pixelY, chopperRate, minAmp, maxOE); } /// /// Center Target On Pixel /// /// /// /// //public void CenterTargetOnPixel(int curTargetX, int curTargetY, Point endPt) //{ // logger_?.Trace($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); // //_lspsVideo?.CenterTargetOnPixel(curTargetX, curTargetY, endPt); //} /// /// Moves to pixel location for the Seeker /// /// /// /// /// /// /// public void MoveToPixelLocationSeeker(int pixelX, int pixelY, double chopperRate, double minAmp, double maxOE) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); //_lspsVideo?.MoveToPixelLocationSeeker(pixelX, pixelY, chopperRate, minAmp, maxOE); } /// /// Moves to pixel location for the Sensor /// /// /// /// /// /// /// public void MoveToPixelLocationSensor(int pixelX, int pixelY, double chopperRate, double minAmp, double maxOE) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); //_lspsVideo?.MoveToPixelLocationSensor(pixelX, pixelY, chopperRate, minAmp, maxOE); } /// /// Move UUT Rel /// /// /// public void MoveUutRel(double az, double el) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); //_lspsChamber?.MoveUutRel(az, el); } /// /// Seeker Find Target No Move /// /// /// /// /// /// public void SeekerFindTargetNoMove(int targetX, int targetY, double chopperRate, double minAmp, double maxOE) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); //_lspsVideo?.SeekerFindTargetNoMove(targetX, targetY, chopperRate, minAmp, maxOE); } /// /// Sensor Find Target No Move /// /// /// /// /// /// public void SensorFindTargetNoMove(int targetX, int targetY, double chopperRate, double minAmp, double maxOE) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); //_lspsVideo?.SensorFindTargetNoMove(targetX, targetY, chopperRate, minAmp, maxOE); } /// /// Center Target On Pixel /// /// /// /// /// /// public void CenterTargetOnPixel(int pixelX, int pixelY, double chopperRate, double minAmp, double maxOE) { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method..."); //Point endPt = new Point(pixelX, pixelY); // Interface signature is different //_lspsVideo?.CenterTargetOnPixel(0, 0, endPt); } #endregion } }