Major upgrade

This commit is contained in:
Duc
2025-10-24 15:18:11 -07:00
parent fd85735c93
commit ce583d1664
478 changed files with 237518 additions and 47610 deletions

View File

@@ -22,339 +22,306 @@ using Raytheon.Common;
namespace Raytheon.Instruments
{
/// <summary>
/// A simulated implementation of the ISwitch interface.
/// </summary>
public class SwitchNiPxi : ISwitch, IDisposable
{
#region PrivateMemberVariables
/// <summary>
/// A simulated implementation of the ISwitch interface.
/// </summary>
public class SwitchNiPxi : ISwitch, IDisposable
{
#region PrivateMemberVariables
private NISwitch _niSwitch;
private string _name;
private readonly string _address;
private readonly string _topology;
private State _state;
private SelfTestResult _selfTestResult;
private NISwitch _niSwitch;
private string _name;
private readonly string _address;
private readonly string _topology;
private State _state;
private SelfTestResult _selfTestResult;
/// <summary>
/// NLog logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Raytheon configuration
/// </summary>
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
private readonly ILogger _logger;
#endregion
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
#region PrivateFunctions
#endregion
/// <summary>
/// The Finalizer
/// </summary>
~SwitchNiPxi()
{
Dispose(false);
}
#region PrivateFunctions
/// <summary>
/// Dispose of this object's resources.
/// </summary>
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
protected virtual void Dispose(bool disposing)
{
try
{
if (disposing)
{
if (_state == State.Ready)
{
_niSwitch.Utility.Reset();
/// <summary>
/// The Finalizer
/// </summary>
~SwitchNiPxi()
{
Dispose(false);
}
_niSwitch.Close();
/// <summary>
/// Dispose of this object's resources.
/// </summary>
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (_state == State.Ready)
{
_niSwitch.Utility.Reset();
_niSwitch.Dispose();
_niSwitch.Close();
_state = State.Uninitialized;
}
}
}
catch (Exception)
{
try
{
//ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
}
catch (Exception)
{
//Do not rethrow. Exception from error logger that has already been garbage collected
}
}
}
_niSwitch.Dispose();
#endregion
_state = State.Uninitialized;
}
}
}
#region PublicFunctions
#endregion
/// <summary>
/// SwitchNiPxi factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchNiPxi(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
#region PublicFunctions
_logger = logger;
/// <summary>
/// SwitchNiPxi factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchNiPxi(string deviceName, IConfigurationManager configurationManager)
{
Name = deviceName;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_address = _configuration.GetConfigurationValue("SwitchNiPxi", "Address", "");
_topology = _configuration.GetConfigurationValue("SwitchNiPxi", "Topology", "");
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
_address = _configuration.GetConfigurationValue("SwitchNiPxi", "Address", "");
_topology = _configuration.GetConfigurationValue("SwitchNiPxi", "Topology", "");
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="address"></param>
public SwitchNiPxi(string name, string address, string topology = "")
{
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_address = address;
_topology = topology;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
// set in Initialize()
_niSwitch = null;
/// <summary>
///
/// </summary>
/// <param name="deviceName"></param>
/// <param name="address"></param>
public SwitchNiPxi(string deviceName, string address, string topology = "")
{
_name = deviceName;
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_address = address;
_topology = topology;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
// set in Initialize()
_niSwitch = null;
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Connect(string path)
{
_niSwitch.RelayOperations.RelayControl(path, SwitchRelayAction.CloseRelay);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Disconnect(string path)
{
_niSwitch.RelayOperations.RelayControl(path, SwitchRelayAction.OpenRelay);
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Connect(string path)
{
_niSwitch.RelayOperations.RelayControl(path, SwitchRelayAction.CloseRelay);
}
/// <summary>
///
/// </summary>
public void DisconnectAll()
{
_niSwitch.Path.DisconnectAll();
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Disconnect(string path)
{
_niSwitch.RelayOperations.RelayControl(path, SwitchRelayAction.OpenRelay);
}
/// <summary>
/// Dispose of this object.
/// </summary>
public void Dispose()
{
try
{
Dispose(true);
/// <summary>
///
/// </summary>
public void DisconnectAll()
{
_niSwitch.Path.DisconnectAll();
}
GC.SuppressFinalize(this);
}
catch (Exception)
{
try
{
//ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
}
catch (Exception)
{
//Do not rethrow. Exception from error logger that has already been garbage collected
}
}
}
/// <summary>
/// Dispose of this object.
/// </summary>
public void Dispose()
{
Dispose(true);
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a NI Switch";
}
}
GC.SuppressFinalize(this);
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a NI Switch";
}
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool IsDebounced
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
if (_state == State.Uninitialized)
{
_niSwitch = new NISwitch(_address, _topology, false, true);
/// <summary>
///
/// </summary>
public bool IsDebounced
{
get
{
throw new NotImplementedException();
}
}
//_niSwitch.ModuleCharacteristics.PowerDownLatchingRelaysAfterDebounce
/// <summary>
///
/// </summary>
public void Initialize()
{
if (_state == State.Uninitialized)
{
_niSwitch = new NISwitch(_address, _topology, false, true);
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
//_niSwitch.ModuleCharacteristics.PowerDownLatchingRelaysAfterDebounce
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
Ivi.Driver.SelfTestResult res = _niSwitch.Utility.SelfTest();
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
if (res.Code != 0)
{
_selfTestResult = Raytheon.Instruments.SelfTestResult.Fail;
throw new Exception("self test returned: " + res.Code + "," + res.Message + " on card " + _name);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
Ivi.Driver.SelfTestResult res = _niSwitch.Utility.SelfTest();
_selfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
if (res.Code != 0)
{
_selfTestResult = Raytheon.Instruments.SelfTestResult.Fail;
throw new Exception("self test returned: " + res.Code + "," + res.Message + " on card " + _name);
}
return _selfTestResult;
}
_selfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
/// <summary>
///
/// </summary>
public void Reset()
{
_niSwitch.Utility.Reset();
}
return _selfTestResult;
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public void Reset()
{
_niSwitch.Utility.Reset();
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
_niSwitch.Utility.Reset();
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
_niSwitch.Close();
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
_niSwitch.Utility.Reset();
_niSwitch.Dispose();
_niSwitch.Close();
_state = State.Uninitialized;
}
}
_niSwitch.Dispose();
#endregion
}
_state = State.Uninitialized;
}
}
#endregion
}
}