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

@@ -23,382 +23,348 @@ using Raytheon.Common;
namespace Raytheon.Instruments
{
/// <summary>
/// A Pickering implementation of the IRelaySwitch interface
/// </summary>
public class SwitchPickeringPipx40 : ISwitch
{
#region PrivateMemberVariables
private readonly int _handle;
private string _name;
private readonly int _subUnit;
private State _state;
private SelfTestResult _selfTestResult;
/// <summary>
/// A Pickering implementation of the IRelaySwitch interface
/// </summary>
public class SwitchPickeringPipx40 : ISwitch
{
#region PrivateMemberVariables
private readonly int _handle;
private string _name;
private readonly int _subUnit;
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>
/// Dispose of the resources contained by this object
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
try
{
if (disposing)
{
if (_state == State.Ready)
{
RelayOpenAll();
Pickering.Pipx40.Interop.Pipx40Module.Reset(_handle);
Pickering.Pipx40.Interop.Pipx40Module.Close(_handle);
_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
}
}
}
#region PrivateFunctions
/// <summary>
/// Close a single relay
/// The relay string should be the string form of an integer that represents the bit to close
/// </summary>
/// <param name="relay">The relay to close</param>
private void RelayClose(string relay)
{
//VI_ON energizes
int ret = Pickering.Pipx40.Interop.Pipx40Module.SetChannelState(_handle, _subUnit, Convert.ToInt32(relay), 1);
//pipx40_operateSwitch
if (ret != 0)
{
throw new Exception("Pickering.Pipx40.Interop.Pipx40Module.SetChannelState() return: " + ret.ToString());
}
}
/// <summary>
/// Dispose of the resources contained by this object
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (_state == State.Ready)
{
RelayOpenAll();
Pickering.Pipx40.Interop.Pipx40Module.Reset(_handle);
Pickering.Pipx40.Interop.Pipx40Module.Close(_handle);
_state = State.Uninitialized;
}
}
}
/// <summary>
/// Opens a single relay
/// The relay strings should be the string form of an integer that represents the bit to close
/// </summary>
/// <param name="relay">The relay to open</param>
private void RelayOpen(string relay)
{
//VI_OFF energizes
int ret = Pickering.Pipx40.Interop.Pipx40Module.SetChannelState(_handle, _subUnit, Convert.ToInt32(relay), 0);
//pipx40_operateSwitch
if (ret != 0)
{
throw new Exception("Pickering.Pipx40.Interop.Pipx40Module.SetChannelState() return: " + ret.ToString());
}
}
/// <summary>
/// Close a single relay
/// The relay string should be the string form of an integer that represents the bit to close
/// </summary>
/// <param name="relay">The relay to close</param>
private void RelayClose(string relay)
{
//VI_ON energizes
int ret = Pickering.Pipx40.Interop.Pipx40Module.SetChannelState(_handle, _subUnit, Convert.ToInt32(relay), 1);
//pipx40_operateSwitch
if (ret != 0)
{
throw new Exception("Pickering.Pipx40.Interop.Pipx40Module.SetChannelState() return: " + ret.ToString());
}
}
/// <summary>
/// Opens all relays on the card
/// </summary>
private void RelayOpenAll()
{
Pickering.Pipx40.Interop.Pipx40Module.ClearCard(_handle);
/// <summary>
/// Opens a single relay
/// The relay strings should be the string form of an integer that represents the bit to close
/// </summary>
/// <param name="relay">The relay to open</param>
private void RelayOpen(string relay)
{
//VI_OFF energizes
int ret = Pickering.Pipx40.Interop.Pipx40Module.SetChannelState(_handle, _subUnit, Convert.ToInt32(relay), 0);
//pipx40_operateSwitch
if (ret != 0)
{
throw new Exception("Pickering.Pipx40.Interop.Pipx40Module.SetChannelState() return: " + ret.ToString());
}
}
//Pickering.Pipx40.Interop.Pipx40Module.ClearSub(_handle, _subUnit);
}
/// <summary>
/// Opens all relays on the card
/// </summary>
private void RelayOpenAll()
{
Pickering.Pipx40.Interop.Pipx40Module.ClearCard(_handle);
private void SelfTest()
{
SelftestFault stFault = new SelftestFault();
//Pickering.Pipx40.Interop.Pipx40Module.ClearSub(_handle, _subUnit);
}
StringBuilder message = new StringBuilder();
private void SelfTest()
{
SelftestFault stFault = new SelftestFault();
int ret = Pickering.Pipx40.Interop.Pipx40Module.SelfTest(_handle, ref stFault, message);
StringBuilder message = new StringBuilder();
if (ret != 0)
{
throw new Exception("Pickering.Pipx40.Interop.Pipx40Module.SelfTest() return: " + ret.ToString() + ", " + message.ToString());
}
}
int ret = Pickering.Pipx40.Interop.Pipx40Module.SelfTest(_handle, ref stFault, message);
#endregion
if (ret != 0)
{
throw new Exception("Pickering.Pipx40.Interop.Pipx40Module.SelfTest() return: " + ret.ToString() + ", " + message.ToString());
}
}
#region PublicFunctions
#endregion
/// <summary>
/// SwitchPickeringPipx40 factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchPickeringPipx40(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
#region PublicFunctions
_logger = logger;
/// <summary>
/// SwitchPickeringPipx40 factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchPickeringPipx40(string deviceName, IConfigurationManager configurationManager)
{
Name = deviceName;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_subUnit = _configuration.GetConfigurationValue("SwitchPickeringPipx40", "SubUnit", 0);
int ret = Pipx40Module.Init(Name, 0, 1, ref _handle);
if (ret != 0)
{
throw new Exception("Pickering.Pipx40.Interop.Pipx40Module.Init() return: " + ret.ToString());
}
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
_subUnit = _configuration.GetConfigurationValue("SwitchPickeringPipx40", "SubUnit", 0);
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="address"></param>
/// <param name="subUnit"></param>
public SwitchPickeringPipx40(string name, string address, int subUnit)
{
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_subUnit = subUnit;
int ret = Pipx40Module.Init(Name, 0, 1, ref _handle);
if (ret != 0)
{
throw new Exception("Pickering.Pipx40.Interop.Pipx40Module.Init() return: " + ret.ToString());
}
int ret = Pipx40Module.Init(name, 0, 1, ref _handle);
if (ret != 0)
{
throw new Exception("Pickering.Pipx40.Interop.Pipx40Module.Init() return: " + ret.ToString());
}
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <param name="deviceName"></param>
/// <param name="address"></param>
/// <param name="subUnit"></param>
public SwitchPickeringPipx40(string deviceName, string address, int subUnit)
{
_name = deviceName;
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_subUnit = subUnit;
/// <summary>
/// The Finalizer
/// </summary>
~SwitchPickeringPipx40()
{
Dispose(false);
}
int ret = Pipx40Module.Init(deviceName, 0, 1, ref _handle);
if (ret != 0)
{
throw new Exception("Pickering.Pipx40.Interop.Pipx40Module.Init() return: " + ret.ToString());
}
/// <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)
{
RelayClose(path);
}
/// <summary>
/// The Finalizer
/// </summary>
~SwitchPickeringPipx40()
{
Dispose(false);
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Disconnect(string path)
{
RelayOpen(path);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void DisconnectAll()
{
RelayOpenAll();
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Connect(string path)
{
RelayClose(path);
}
/// <summary>
/// Dispose of the resources contained by this object
/// </summary>
public void Dispose()
{
try
{
Dispose(true);
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Disconnect(string path)
{
RelayOpen(path);
}
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>
///
/// </summary>
public void DisconnectAll()
{
RelayOpenAll();
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a Pickering Switch";
}
}
/// <summary>
/// Dispose of the resources contained by this object
/// </summary>
public void Dispose()
{
Dispose(true);
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
GC.SuppressFinalize(this);
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a Pickering Switch";
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void Initialize()
{
if (_state == State.Uninitialized)
{
// nothing to initialize here
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
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 string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
///
/// </summary>
public void Initialize()
{
if (_state == State.Uninitialized)
{
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public bool IsDebounced
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Reset()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
public void Reset()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
RelayOpenAll();
Pickering.Pipx40.Interop.Pipx40Module.Reset(_handle);
Pickering.Pipx40.Interop.Pipx40Module.Close(_handle);
_state = State.Uninitialized;
}
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
#endregion
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
RelayOpenAll();
Pickering.Pipx40.Interop.Pipx40Module.Reset(_handle);
Pickering.Pipx40.Interop.Pipx40Module.Close(_handle);
_state = State.Uninitialized;
}
}
#endregion
}
}