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,388 +22,353 @@ using SwitchMeasurementInstrumentsLib.Pickering60LxiSoap;
namespace Raytheon.Instruments
{
/// <summary>
/// A Pickering implementation of the IRelaySwitch interface
/// </summary>
public class SwitchPickeringLxi60_522_Soap : ISwitch, IDisposable
{
#region PrivateMemberVariables
/// <summary>
/// A Pickering implementation of the IRelaySwitch interface
/// </summary>
public class SwitchPickeringLxi60_522_Soap : ISwitch, IDisposable
{
#region PrivateMemberVariables
private string _name;
private PiCards _card;
private readonly int _subUnit;
private State _state;
private SelfTestResult _selfTestResult;
private string _name;
private PiCards _card;
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>
/// The Finalizer
/// </summary>
~SwitchPickeringLxi60_522_Soap()
{
Dispose(false);
}
#region PrivateFunctions
/// <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)
{
_card.ClearAll();
_card.Dispose();
_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
}
}
}
/// <summary>
/// The Finalizer
/// </summary>
~SwitchPickeringLxi60_522_Soap()
{
Dispose(false);
}
/// <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)
{
int ret = _card.OpBit(_subUnit, Convert.ToInt32(relay), true);
/// <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)
{
_card.ClearAll();
_card.Dispose();
_state = State.Uninitialized;
}
}
}
if (ret != 0)
{
throw new Exception("OpBit failed with a ret of: " + ret);
}
}
/// <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)
{
int ret = _card.OpBit(_subUnit, Convert.ToInt32(relay), true);
/// <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)
{
int ret = _card.OpBit(_subUnit, Convert.ToInt32(relay), false);
if (ret != 0)
{
throw new Exception("OpBit failed with a ret of: " + ret);
}
}
if (ret != 0)
{
throw new Exception("OpBit failed with a ret of: " + ret);
}
}
/// <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)
{
int ret = _card.OpBit(_subUnit, Convert.ToInt32(relay), false);
/// <summary>
/// Opens all relays on the card
/// </summary>
private void RelayOpenAll()
{
int ret = _card.ClearCard();
if (ret != 0)
{
throw new Exception("OpBit failed with a ret of: " + ret);
}
}
if (ret != 0)
{
throw new Exception("OpBit failed with a ret of: " + ret);
}
}
/// <summary>
/// Opens all relays on the card
/// </summary>
private void RelayOpenAll()
{
int ret = _card.ClearCard();
#endregion
if (ret != 0)
{
throw new Exception("OpBit failed with a ret of: " + ret);
}
}
#region PublicFunctions
#endregion
/// <summary>
/// SwitchPickeringLxi60_522_Soap factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchPickeringLxi60_522_Soap(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
#region PublicFunctions
_logger = logger;
/// <summary>
/// SwitchPickeringLxi60_522_Soap factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public SwitchPickeringLxi60_522_Soap(string deviceName, IConfigurationManager configurationManager)
{
Name = deviceName;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
var address = _configuration.GetConfigurationValue("SwitchPickeringLxi60_522_Soap", "Address", "127.0.0.1");
var deviceNumber = _configuration.GetConfigurationValue<long>("SwitchPickeringLxi60_522_Soap", "DeviceNumber", 0);
var busNumber = _configuration.GetConfigurationValue<long>("SwitchPickeringLxi60_522_Soap", "BusNumber", 0);
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_subUnit = _configuration.GetConfigurationValue("SwitchPickeringLxi60_522_Soap", "SubUnit", 0);
var address = _configuration.GetConfigurationValue(Name, Switch.ConfigXml.LXI_IP_ADDRESS.ToString());
Int64.TryParse(_configuration.GetConfigurationValue(Name, Switch.ConfigXml.DEVICE_NUMBER.ToString()), out long deviceNumber);
Int64.TryParse(_configuration.GetConfigurationValue(Name, Switch.ConfigXml.BUS_NUMBER.ToString()), out long busNumber);
Int32.TryParse(_configuration.GetConfigurationValue(Name, Switch.ConfigXml.SUB_UNIT.ToString()), out _subUnit);
_card = new PiCards
{
Url = $"http://{address}/bin/picards"
};
_card = new PiCards
{
Url = $"http://{address}/bin/picards"
};
LocationHeader lh = new LocationHeader
{
Slot = deviceNumber,
Bus = busNumber
};
LocationHeader lh = new LocationHeader
{
Slot = deviceNumber,
Bus = busNumber
};
_card.CardLocation = lh;
_card.CardLocation = lh;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="address"></param>
/// <param name="deviceNumber"></param>
/// <param name="busNumber"></param>
/// <param name="subUnit"></param>
public SwitchPickeringLxi60_522_Soap(string name, string address, int deviceNumber, int busNumber, int subUnit)
{
_name = name;
/// <summary>
///
/// </summary>
/// <param name="deviceName"></param>
/// <param name="address"></param>
/// <param name="deviceNumber"></param>
/// <param name="busNumber"></param>
/// <param name="subUnit"></param>
public SwitchPickeringLxi60_522_Soap(string deviceName, string address, int deviceNumber, int busNumber, int subUnit)
{
_name = deviceName;
_logger = LogManager.GetCurrentClassLogger();
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_subUnit = subUnit;
_subUnit = subUnit;
_card = new PiCards();
_card = new PiCards();
string tempAddress = "http://" + address + "/bin/picards";
_card.Url = tempAddress;
string tempAddress = "http://" + address + "/bin/picards";
_card.Url = tempAddress;
LocationHeader lh = new LocationHeader();
lh.Slot = deviceNumber;
lh.Bus = busNumber;
LocationHeader lh = new LocationHeader();
lh.Slot = deviceNumber;
lh.Bus = busNumber;
_card.CardLocation = lh;
_card.CardLocation = lh;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Connect(string path)
{
RelayClose(path);
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Connect(string path)
{
RelayClose(path);
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Disconnect(string path)
{
RelayOpen(path);
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void Disconnect(string path)
{
RelayOpen(path);
}
/// <summary>
///
/// </summary>
public void DisconnectAll()
{
RelayOpenAll();
}
/// <summary>
///
/// </summary>
public void DisconnectAll()
{
RelayOpenAll();
}
/// <summary>
/// Dispose of the resources contained by this object
/// </summary>
public void Dispose()
{
try
{
Dispose(true);
/// <summary>
/// Dispose of the resources contained by this object
/// </summary>
public void Dispose()
{
Dispose(true);
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
}
}
}
GC.SuppressFinalize(this);
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a Pickering Switch";
}
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a Pickering Switch";
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
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());
}
}
/// <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>
public bool IsDebounced
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool IsDebounced
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void Reset()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void Reset()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
_card.ClearAll();
_card.Dispose();
_state = State.Uninitialized;
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
_card.ClearAll();
_card.Dispose();
_state = State.Uninitialized;
}
}
#endregion
}
#endregion
}
}

View File

@@ -31,72 +31,67 @@
// POC: Alex Kravchenko (1118268)
// **********************************************************************************************************
using NLog;
using Raytheon.Common;
using SwitchMeasurementInstrumentsLib;
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 = "SwitchPickeringLxi60_522_SoapFactory")]
public class SwitchPickeringLxi60_522_SoapFactory : 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 = "SwitchPickeringLxi60_522_SoapFactory")]
public class SwitchPickeringLxi60_522_SoapFactory : IInstrumentFactory
{
private readonly List<Type> _supportedInterfaces = new List<Type>();
public SwitchPickeringLxi60_522_SoapFactory(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 SwitchPickeringLxi60_522_SoapFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
[Import(AllowDefault = true)] string defaultConfigPath = null)
{
DefaultPath = defaultConfigPath;
public SwitchPickeringLxi60_522_SoapFactory(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>
/// COECommDeviceInstrumentFactory injection constructor
/// </summary>
/// <param name="configManager"></param>
/// <param name="simEngine"></param>
/// <param name="logger"></param>
[ImportingConstructor]
public SwitchPickeringLxi60_522_SoapFactory([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 SwitchPickeringLxi60_522_Soap(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 SwitchPickeringLxi60_522_Soap(name, _configurationManager);
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Gets the instrument
@@ -107,12 +102,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 SwitchPickeringLxi60_522_Soap(name, _configurationManager, _logger);
return new SwitchPickeringLxi60_522_Soap(name, _configurationManager);
}
catch (Exception)
{
@@ -125,17 +118,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);
}
}
}