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

@@ -0,0 +1,2 @@
Pickering Switch Relay 40-156-001
Pickering Switch Relay 40-137-101

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
}
}

View File

@@ -31,71 +31,64 @@
// POC: Alex Kravchenko (1118268)
// **********************************************************************************************************
using NLog;
using Raytheon.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Reflection;
using NLog;
using Raytheon.Common;
namespace Raytheon.Instruments
{
[ExportInstrumentFactory(ModelNumber = "SwitchPickeringPipx40Factory")]
public class SwitchPickeringPipx40Factory : IInstrumentFactory
{
/// <summary>
/// The supported interfaces
/// </summary>
private readonly List<Type> _supportedInterfaces = new List<Type>();
private ILogger _logger;
private readonly IConfigurationManager _configurationManager;
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
private static string DefaultPath;
[ExportInstrumentFactory(ModelNumber = "SwitchPickeringPipx40Factory")]
public class SwitchPickeringPipx40Factory : IInstrumentFactory
{
private readonly List<Type> _supportedInterfaces = new List<Type>();
public SwitchPickeringPipx40Factory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
private readonly IConfigurationManager _configurationManager;
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
private static string DefaultPath;
/// <summary>
/// COECommDeviceInstrumentFactory injection constructor
/// </summary>
/// <param name="configManager"></param>
/// <param name="simEngine"></param>
/// <param name="logger"></param>
[ImportingConstructor]
public SwitchPickeringPipx40Factory([Import(AllowDefault = false)] IConfigurationManager configManager,
[Import(AllowDefault = true)] string defaultConfigPath = null)
{
DefaultPath = defaultConfigPath;
public SwitchPickeringPipx40Factory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
if (LogManager.Configuration == null)
{
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
}
/// <summary>
/// SwitchPickeringPipx40Factory injection constructor
/// </summary>
[ImportingConstructor]
public SwitchPickeringPipx40Factory([Import(AllowDefault = false)] IConfigurationManager configManager,
[Import(AllowDefault = true)] string defaultConfigPath = null)
{
DefaultPath = defaultConfigPath;
_configurationManager = configManager ?? GetConfigurationManager();
_supportedInterfaces.Add(typeof(ISwitch));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
_logger = LogManager.GetLogger(name);
return new SwitchPickeringPipx40(name, _configurationManager, _logger);
}
catch (Exception)
{
throw;
}
}
if (LogManager.Configuration == null)
{
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
}
_configurationManager = configManager ?? GetConfigurationManager();
_supportedInterfaces.Add(typeof(ISwitch));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
return new SwitchPickeringPipx40(name, _configurationManager);
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Gets the instrument
@@ -106,12 +99,10 @@ namespace Raytheon.Instruments
{
try
{
_logger = LogManager.GetLogger(name);
if (simulateHw)
return new SwitchSim(name, _configurationManager, _logger);
return new SwitchSim(name, _configurationManager);
else
return new SwitchPickeringPipx40(name, _configurationManager, _logger);
return new SwitchPickeringPipx40(name, _configurationManager);
}
catch (Exception)
{
@@ -124,17 +115,17 @@ namespace Raytheon.Instruments
/// </summary>
/// <returns></returns>
public ICollection<Type> GetSupportedInterfaces()
{
return _supportedInterfaces.ToArray();
}
{
return _supportedInterfaces.ToArray();
}
/// <summary>
/// returns configuration based on the predefined path or default path c:/ProgramData/Raytheon/InstrumentManagerService
/// </summary>
/// <returns></returns>
private static IConfigurationManager GetConfigurationManager()
{
return string.IsNullOrEmpty(DefaultPath) ? new RaytheonConfigurationManager() : new RaytheonConfigurationManager(DefaultPath);
}
}
/// <summary>
/// returns configuration based on the predefined path or default path c:/ProgramData/Raytheon/InstrumentManagerService
/// </summary>
/// <returns></returns>
private static IConfigurationManager GetConfigurationManager()
{
return string.IsNullOrEmpty(DefaultPath) ? new RaytheonConfigurationManager() : new RaytheonConfigurationManager(DefaultPath);
}
}
}