Major upgrade
This commit is contained in:
@@ -22,11 +22,11 @@
|
||||
// accordance with DoD-5220.22-M or OPNAVINST 5510.1h.
|
||||
//>>***************************************************************************
|
||||
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
@@ -35,449 +35,413 @@ namespace Raytheon.Instruments
|
||||
/// It only supports individual relay mode at this time.
|
||||
/// </summary>
|
||||
public class SwitchKeysightScpi : ISwitch
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
private const string READ_ERROR_STATUS_CMD = "SYST:ERR?";
|
||||
private const string _SELFTESTCMD = "*TST?";
|
||||
private const string _RESETCMD = "*RST";
|
||||
//@@@ add scpi commands here
|
||||
|
||||
private int _PORT = 5025;
|
||||
private const int _READ_TIMEOUT = 5000;
|
||||
private byte[] _readBuffer;
|
||||
private NetworkStream _tcpStream;
|
||||
private string _name;
|
||||
|
||||
/// <summary>
|
||||
/// NLog logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Raytheon configuration
|
||||
/// </summary>
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#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 && _tcpStream != null)
|
||||
{
|
||||
}
|
||||
}
|
||||
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>
|
||||
/// Convert scpi data to string
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
private string ConvertToString(ref byte[] data)
|
||||
{
|
||||
string rsp = System.Text.Encoding.ASCII.GetString(data);
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the error code.
|
||||
/// </summary>
|
||||
/// <returns>The error code (number).</returns>
|
||||
private int GetErrorCode()
|
||||
{
|
||||
// not calling IOQuery() here so IOQuery() can call GetErrorCode() after each query
|
||||
string command = READ_ERROR_STATUS_CMD + "\n";
|
||||
|
||||
// convert to a byte array
|
||||
byte[] commandBuffer = Encoding.ASCII.GetBytes(command);
|
||||
|
||||
// send the data out
|
||||
_tcpStream.Write(commandBuffer, 0, commandBuffer.Length);
|
||||
|
||||
// clear our buffer
|
||||
Array.Clear(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// read the response
|
||||
int numBytesRead = _tcpStream.Read(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// convert to a string
|
||||
string rspStr = ConvertToString(ref _readBuffer);
|
||||
|
||||
// parse the response
|
||||
string[] tokens = rspStr.Split(',');
|
||||
|
||||
int ret = Util.ConvertStringToInt32(tokens[0]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Send a command to the DMM and get the response
|
||||
/// </summary>
|
||||
/// <param name="commandString">The command to send</param>
|
||||
/// <returns>The DMM response</returns>
|
||||
private string IOQuery(string commandString)
|
||||
{
|
||||
// send the command
|
||||
IOWrite(commandString);
|
||||
|
||||
// clear our buffer
|
||||
Array.Clear(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// read from the response
|
||||
int numBytesRead = _tcpStream.Read(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// convert response to a string
|
||||
string rspStr = ConvertToString(ref _readBuffer);
|
||||
|
||||
// check for errors
|
||||
int err = GetErrorCode();
|
||||
if (err != 0)
|
||||
{
|
||||
throw new Exception("SwitchKeysightScpi:IOQuery() - returned error code: " + err.ToString());
|
||||
}
|
||||
|
||||
return rspStr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a SCPI Command to the instrument.
|
||||
/// </summary>
|
||||
/// <param name="commandString">The SCPI Command to be sent to the instrument.</param>
|
||||
private void IOWrite(string commandString)
|
||||
{
|
||||
// convert to a byte array
|
||||
byte[] commandBuffer = Encoding.ASCII.GetBytes(commandString);
|
||||
|
||||
// send the data out
|
||||
_tcpStream.Write(commandBuffer, 0, commandBuffer.Length);
|
||||
|
||||
// check for errors
|
||||
int err = GetErrorCode();
|
||||
if (err != 0)
|
||||
{
|
||||
throw new Exception("SwitchKeysightScpi:IOQuery() - returned error code: " + err.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform self-test.
|
||||
/// </summary>
|
||||
private void SelfTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
// change the timeout to account for the long self test
|
||||
_tcpStream.ReadTimeout = 30000;
|
||||
|
||||
// send the command and get the response
|
||||
string command = _SELFTESTCMD + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
// parse the response
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
int rsp = Util.ConvertStringToInt32(tokens[0]);
|
||||
|
||||
if (rsp != 0)
|
||||
{
|
||||
string errorMsg = "returned an error: " + rsp.ToString() + "," + rspStr;
|
||||
throw new Exception(errorMsg);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// restore the timeout
|
||||
_tcpStream.ReadTimeout = _READ_TIMEOUT;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// SwitchKeysightScpi factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchKeysightScpi(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
var address = _configuration.GetConfigurationValue("SwitchKeysightScpi", "Address", "127.0.0.1");
|
||||
_PORT = _configuration.GetConfigurationValue("SwitchKeysightScpi", "Port", 5025);
|
||||
|
||||
const int READ_BUFFER_SIZE = 512;
|
||||
|
||||
_readBuffer = new byte[READ_BUFFER_SIZE];
|
||||
|
||||
TcpClient dmmSocketConn = new TcpClient(address, _PORT);
|
||||
_tcpStream = dmmSocketConn.GetStream();
|
||||
_tcpStream.ReadTimeout = _READ_TIMEOUT;
|
||||
|
||||
SelfTest();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for RelaySwitch card.
|
||||
/// </summary>
|
||||
/// <param name="address">The address of the RelaySwitch.</param>
|
||||
/// <param name="options">The options used for setting up the instrument.</param>
|
||||
public SwitchKeysightScpi(string name, string address)
|
||||
{
|
||||
const int READ_BUFFER_SIZE = 512;
|
||||
|
||||
_name = name;
|
||||
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
_readBuffer = new byte[READ_BUFFER_SIZE];
|
||||
|
||||
TcpClient dmmSocketConn = new TcpClient(address, _PORT);
|
||||
_tcpStream = dmmSocketConn.GetStream();
|
||||
_tcpStream.ReadTimeout = _READ_TIMEOUT;
|
||||
|
||||
SelfTest();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizer.
|
||||
/// </summary>
|
||||
~SwitchKeysightScpi()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close a single relay.
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to close.</param>
|
||||
public void Connect(string path)
|
||||
{
|
||||
// send the command
|
||||
|
||||
//IOWrite(command);
|
||||
|
||||
//read back to verify state of relay?
|
||||
|
||||
|
||||
//"ROUT:CLOS (@3923)"
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open a single relay.
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to open.</param>
|
||||
public void Disconnect(string path)
|
||||
{
|
||||
// send the command
|
||||
|
||||
//IOWrite(command);
|
||||
|
||||
//read back to verify state of relay?
|
||||
//"ROUT:OPEN (@3923)")
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisconnectAll()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Keysight 34980A switch";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool IsDebounced
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
IOWrite(_RESETCMD + "\n");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
if (_tcpStream != null)
|
||||
{
|
||||
Reset();
|
||||
_tcpStream.Dispose();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
private const string READ_ERROR_STATUS_CMD = "SYST:ERR?";
|
||||
private const string _SELFTESTCMD = "*TST?";
|
||||
private const string _RESETCMD = "*RST";
|
||||
//@@@ add scpi commands here
|
||||
|
||||
private int _PORT = 5025;
|
||||
private const int _READ_TIMEOUT = 5000;
|
||||
private byte[] _readBuffer;
|
||||
private NetworkStream _tcpStream;
|
||||
private string _name;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert scpi data to string
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
private string ConvertToString(ref byte[] data)
|
||||
{
|
||||
string rsp = System.Text.Encoding.ASCII.GetString(data);
|
||||
return rsp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the error code.
|
||||
/// </summary>
|
||||
/// <returns>The error code (number).</returns>
|
||||
private int GetErrorCode()
|
||||
{
|
||||
// not calling IOQuery() here so IOQuery() can call GetErrorCode() after each query
|
||||
string command = READ_ERROR_STATUS_CMD + "\n";
|
||||
|
||||
// convert to a byte array
|
||||
byte[] commandBuffer = Encoding.ASCII.GetBytes(command);
|
||||
|
||||
// send the data out
|
||||
_tcpStream.Write(commandBuffer, 0, commandBuffer.Length);
|
||||
|
||||
// clear our buffer
|
||||
Array.Clear(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// read the response
|
||||
int numBytesRead = _tcpStream.Read(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// convert to a string
|
||||
string rspStr = ConvertToString(ref _readBuffer);
|
||||
|
||||
// parse the response
|
||||
string[] tokens = rspStr.Split(',');
|
||||
|
||||
int ret = Util.ConvertStringToInt32(tokens[0]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Send a command to the DMM and get the response
|
||||
/// </summary>
|
||||
/// <param name="commandString">The command to send</param>
|
||||
/// <returns>The DMM response</returns>
|
||||
private string IOQuery(string commandString)
|
||||
{
|
||||
// send the command
|
||||
IOWrite(commandString);
|
||||
|
||||
// clear our buffer
|
||||
Array.Clear(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// read from the response
|
||||
int numBytesRead = _tcpStream.Read(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
// convert response to a string
|
||||
string rspStr = ConvertToString(ref _readBuffer);
|
||||
|
||||
// check for errors
|
||||
int err = GetErrorCode();
|
||||
if (err != 0)
|
||||
{
|
||||
throw new Exception("SwitchKeysightScpi:IOQuery() - returned error code: " + err.ToString());
|
||||
}
|
||||
|
||||
return rspStr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a SCPI Command to the instrument.
|
||||
/// </summary>
|
||||
/// <param name="commandString">The SCPI Command to be sent to the instrument.</param>
|
||||
private void IOWrite(string commandString)
|
||||
{
|
||||
// convert to a byte array
|
||||
byte[] commandBuffer = Encoding.ASCII.GetBytes(commandString);
|
||||
|
||||
// send the data out
|
||||
_tcpStream.Write(commandBuffer, 0, commandBuffer.Length);
|
||||
|
||||
// check for errors
|
||||
int err = GetErrorCode();
|
||||
if (err != 0)
|
||||
{
|
||||
throw new Exception("SwitchKeysightScpi:IOQuery() - returned error code: " + err.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform self-test.
|
||||
/// </summary>
|
||||
private void SelfTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
// change the timeout to account for the long self test
|
||||
_tcpStream.ReadTimeout = 30000;
|
||||
|
||||
// send the command and get the response
|
||||
string command = _SELFTESTCMD + "\n";
|
||||
string rspStr = IOQuery(command);
|
||||
|
||||
// parse the response
|
||||
string[] tokens = rspStr.Split('\n');
|
||||
|
||||
int rsp = Util.ConvertStringToInt32(tokens[0]);
|
||||
|
||||
if (rsp != 0)
|
||||
{
|
||||
string errorMsg = "returned an error: " + rsp.ToString() + "," + rspStr;
|
||||
throw new Exception(errorMsg);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// restore the timeout
|
||||
_tcpStream.ReadTimeout = _READ_TIMEOUT;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// SwitchKeysightScpi factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchKeysightScpi(string deviceName, IConfigurationManager configurationManager)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
var address = _configuration.GetConfigurationValue("SwitchKeysightScpi", "Address", "127.0.0.1");
|
||||
_PORT = _configuration.GetConfigurationValue("SwitchKeysightScpi", "Port", 5025);
|
||||
|
||||
const int READ_BUFFER_SIZE = 512;
|
||||
|
||||
_readBuffer = new byte[READ_BUFFER_SIZE];
|
||||
|
||||
TcpClient dmmSocketConn = new TcpClient(address, _PORT);
|
||||
_tcpStream = dmmSocketConn.GetStream();
|
||||
_tcpStream.ReadTimeout = _READ_TIMEOUT;
|
||||
|
||||
SelfTest();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for RelaySwitch card.
|
||||
/// </summary>
|
||||
/// <param name="address">The address of the RelaySwitch.</param>
|
||||
/// <param name="options">The options used for setting up the instrument.</param>
|
||||
public SwitchKeysightScpi(string deviceName, string address)
|
||||
{
|
||||
const int READ_BUFFER_SIZE = 512;
|
||||
|
||||
_name = deviceName;
|
||||
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
|
||||
_readBuffer = new byte[READ_BUFFER_SIZE];
|
||||
|
||||
TcpClient dmmSocketConn = new TcpClient(address, _PORT);
|
||||
_tcpStream = dmmSocketConn.GetStream();
|
||||
_tcpStream.ReadTimeout = _READ_TIMEOUT;
|
||||
|
||||
SelfTest();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizer.
|
||||
/// </summary>
|
||||
~SwitchKeysightScpi()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close a single relay.
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to close.</param>
|
||||
public void Connect(string path)
|
||||
{
|
||||
// send the command
|
||||
|
||||
//IOWrite(command);
|
||||
|
||||
//read back to verify state of relay?
|
||||
|
||||
|
||||
//"ROUT:CLOS (@3923)"
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open a single relay.
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to open.</param>
|
||||
public void Disconnect(string path)
|
||||
{
|
||||
// send the command
|
||||
|
||||
//IOWrite(command);
|
||||
|
||||
//read back to verify state of relay?
|
||||
//"ROUT:OPEN (@3923)")
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisconnectAll()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Keysight 34980A switch";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool IsDebounced
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
IOWrite(_RESETCMD + "\n");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
if (_tcpStream != null)
|
||||
{
|
||||
Reset();
|
||||
_tcpStream.Dispose();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = "SwitchKeysightScpiFactory")]
|
||||
public class SwitchKeysightScpiFactory : 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 = "SwitchKeysightScpiFactory")]
|
||||
public class SwitchKeysightScpiFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public SwitchKeysightScpiFactory(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 SwitchKeysightScpiFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public SwitchKeysightScpiFactory(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>
|
||||
/// SwitchKeysightScpiFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public SwitchKeysightScpiFactory([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 SwitchKeysightScpi(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 SwitchKeysightScpi(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 SwitchKeysightScpi(name, _configurationManager, _logger);
|
||||
return new SwitchKeysightScpi(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 107 KiB |
@@ -0,0 +1,9 @@
|
||||
;format is signal_name = range|resolution|delay(ms)|scale factor|relays|type|cable, connector and pin id|lower_limit|upper_limit
|
||||
;Type is TWO or FOUR for two wire and four wire measurements
|
||||
;Relay Format: [Card_Name]:[Path]
|
||||
; [Card_Name] - Must match the name of the switch card defined in the Instrument.xml
|
||||
; [Path] - [subUnit#].[channel_x1].[channel_y1],[subUnit#].[channel_x2].[channel_y2]
|
||||
; x1 is routed to y1, x2 is routed to y2, y1 goes to DMM + input, y2 goes to DMM - input
|
||||
;Cable and Pin Id Format: [Cable_Id]_[Connecto_Id]_[Pin_Id]_[Cable_Id]_[Connector_Id]_[Pin_Id]
|
||||
[DmmReadResistance]
|
||||
W3_AUD_GDNC_FILTER = NO_PCODE|-1|0.001|100|1|PICKERING_SWITCH_MATRIX_64X4:0.17.1,0.16.2|TWO|W1_P3_52_W1_P4_4|0.0|5.0
|
||||
@@ -0,0 +1 @@
|
||||
Pickering Matrix Switch 40-585A-001
|
||||
@@ -0,0 +1,347 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using System;
|
||||
using NLog;
|
||||
using Pickering.Lxi.Piplx;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A Pickering implementation of the IRelaySwitch interface
|
||||
/// </summary>
|
||||
public class SwitchMatrixPickering40x : ISwitch
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
private string _name;
|
||||
private string _lxiIpAddress;
|
||||
private int _deviceNum;
|
||||
private int _busNum;
|
||||
private PiplxCard _switchMatrixCard;
|
||||
private State _state;
|
||||
private SelfTestResult _selfTestResult;
|
||||
private object _syncObj = new Object();
|
||||
PiplxManager _piplxManager;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Close/open relay pair defined in the path
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to close</param>
|
||||
private void OperateRelays(string path, bool state)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// split path into 2 items. Each item contains channel information
|
||||
string[] channelArray = path.Split(',');
|
||||
|
||||
if (channelArray.Length != 2)
|
||||
{
|
||||
throw new Exception($"Invalid path: {path}. Expected format: [subunit].[channel_x].[channel_y],[subunit].[channel_x].[channel_y]");
|
||||
}
|
||||
|
||||
for (int i = 0; i < channelArray.Length; i++)
|
||||
{
|
||||
string[] itemArray = channelArray[i].Split('.');
|
||||
|
||||
if (itemArray.Length != 3)
|
||||
{
|
||||
throw new Exception($"Invalid path: {path}. Expected format: [subunit].[channel_x].[channel_y]");
|
||||
}
|
||||
|
||||
int itemIndex = 0;
|
||||
if (int.TryParse(itemArray[itemIndex++], out int subUnitIndex) && int.TryParse(itemArray[itemIndex++], out int xIndex) && int.TryParse(itemArray[itemIndex++], out int yIndex))
|
||||
{
|
||||
MatrixSubunit subUnit = (MatrixSubunit)_switchMatrixCard.Subunits[subUnitIndex];
|
||||
|
||||
subUnit.OperateCrosspoint(yIndex, xIndex, state);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid path: {channelArray[i]}. Expected format: [subunit].[channel_x].[channel_y]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens all relays on the card
|
||||
/// </summary>
|
||||
private void RelayOpenAll()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
for (int i = 0; i < _switchMatrixCard.Subunits.Count; i++)
|
||||
{
|
||||
MatrixSubunit subUnit = (MatrixSubunit)_switchMatrixCard.Subunits[i];
|
||||
subUnit.ClearSubunit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// SwitchMatrixPickering40x factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchMatrixPickering40x(string deviceName, IConfigurationManager configurationManager)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_lxiIpAddress = _configuration.GetConfigurationValue(Name, "LXI_IP_ADDRESS");
|
||||
Int32.TryParse(_configuration.GetConfigurationValue(Name, "DEVICE_NUMBER"), out _deviceNum);
|
||||
Int32.TryParse(_configuration.GetConfigurationValue(Name, "BUS_NUMBER"), out _busNum);
|
||||
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Finalizer
|
||||
/// </summary>
|
||||
~SwitchMatrixPickering40x()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
public void Connect(string path)
|
||||
{
|
||||
OperateRelays(path, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
public void Disconnect(string path)
|
||||
{
|
||||
OperateRelays(path, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisconnectAll()
|
||||
{
|
||||
RelayOpenAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Pickering Switch";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
_piplxManager = new PiplxManager(_lxiIpAddress);
|
||||
|
||||
foreach (PiplxCard card in _piplxManager.Cards)
|
||||
{
|
||||
PiplxCardInfo info = (PiplxCardInfo)card.Info;
|
||||
|
||||
if (info.Device == _deviceNum && info.Bus == _busNum)
|
||||
{
|
||||
_switchMatrixCard = card;
|
||||
|
||||
_switchMatrixCard.Open();
|
||||
|
||||
RelayOpenAll();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_switchMatrixCard == null)
|
||||
{
|
||||
throw new Exception($"No switch matrix card exists in LXI chassis with DEVICE_NUMBER={_deviceNum} and BUS_NUMBER={_busNum}");
|
||||
}
|
||||
|
||||
_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 string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selfTestResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
if (_switchMatrixCard != null && _switchMatrixCard.IsOpen())
|
||||
{
|
||||
RelayOpenAll();
|
||||
_switchMatrixCard.Close();
|
||||
}
|
||||
|
||||
if (_piplxManager != null && _piplxManager.Connected)
|
||||
_piplxManager.Disconnect();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>Raytheon.Instruments.SwitchMatrixPickering40x</AssemblyName>
|
||||
<Product>Switch Matrix Pickering 40x implementation</Product>
|
||||
<Description>Switch Matrix Pickering 40x implementation</Description>
|
||||
<OutputType>Library</OutputType>
|
||||
|
||||
<!-- Static versioning (Suitable for Development) -->
|
||||
<!-- Disable the line below for dynamic versioning -->
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog" Version="5.0.0" />
|
||||
<PackageReference Include="Raytheon.Common" Version="1.0.0" />
|
||||
<PackageReference Include="Raytheon.Instruments.Switch.Contracts" Version="1.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SwitchSim\SwitchSim.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Pickering.Lxi.Communication">
|
||||
<HintPath>..\..\Common\COTS\Pickering\Pickering.Lxi.Communication.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Pickering.Lxi.Piplx">
|
||||
<HintPath>..\..\Common\COTS\Pickering\Pickering.Lxi.Piplx.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Copy all *.dlls and *.pdb in the output folder to a temp folder -->
|
||||
<Target Name="CopyFiles" AfterTargets="AfterBuild">
|
||||
<ItemGroup>
|
||||
<FILES_1 Include="$(OutDir)*.dll" />
|
||||
<FILES_2 Include="$(OutDir)*.pdb" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(FILES_1)" DestinationFolder="$(HalTempFolder)" />
|
||||
<Copy SourceFiles="@(FILES_2)" DestinationFolder="$(HalTempFolder)" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -0,0 +1,131 @@
|
||||
// **********************************************************************************************************
|
||||
// SwitchMatrixPickering40xFactory.cs
|
||||
// 2/20/2023
|
||||
// NGI - Next Generation Interceptor
|
||||
//
|
||||
// Contract No. HQ0856-21-C-0003/1022000209
|
||||
//
|
||||
// THIS DOCUMENT DOES NOT CONTAIN TECHNOLOGY OR TECHNICAL DATA CONTROLLED UNDER EITHER THE U.S.
|
||||
// INTERNATIONAL TRAFFIC IN ARMS REGULATIONS OR THE U.S. EXPORT ADMINISTRATION REGULATIONS.
|
||||
//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION PROPRIETARY TO RAYTHEON
|
||||
// COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT.
|
||||
// DISCLOSURE TO UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO RAYTHEON
|
||||
// COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS CONTENTS SHALL BE FURNISHED OR DISCLOSED
|
||||
// TO OR COPIED OR USED BY PERSONS OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF
|
||||
// RAYTHEON COMPANY.
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// DESTRUCTION NOTICE: FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN DOD 5220.22-M,
|
||||
// NATIONAL INDUSTRIAL SECURITY PROGRAM OPERATING MANUAL, FEBRUARY 2006,
|
||||
// INCORPORATING CHANGE 1, MARCH 28, 2013, CHAPTER 5, SECTION 7, OR DODM 5200.01-VOLUME 3,
|
||||
// DOD INFORMATION SECURITY PROGRAM: PROTECTION OF CLASSIFIED INFORMATION, ENCLOSURE 3,
|
||||
// SECTION 17. FOR CONTROLLED UNCLASSIFIED INFORMATION FOLLOW THE PROCEDURES IN DODM 5200.01-VOLUME 4,
|
||||
// INFORMATION SECURITY PROGRAM: CONTROLLED UNCLASSIFIED INFORMATION.
|
||||
//
|
||||
// CONTROLLED BY: MISSILE DEFENSE AGENCY
|
||||
// CONTROLLED BY: GROUND-BASED MIDCOURSE DEFENSE PROGRAM OFFICE
|
||||
// CUI CATEGORY: CTI
|
||||
// DISTRIBUTION/DISSEMINATION CONTROL: F
|
||||
// POC: Alex Kravchenko (1118268)
|
||||
// **********************************************************************************************************
|
||||
|
||||
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 = "SwitchMatrixPickering40xFactory")]
|
||||
public class SwitchMatrixPickering40xFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
|
||||
private static string DefaultPath;
|
||||
|
||||
public SwitchMatrixPickering40xFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SwitchMatrixPickering40xFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public SwitchMatrixPickering40xFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
|
||||
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 SwitchMatrixPickering40x(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public object GetInstrument(string name, bool simulateHw)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (simulateHw)
|
||||
return new SwitchSim(name, _configurationManager);
|
||||
else
|
||||
return new SwitchMatrixPickering40x(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets supported interfaces
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICollection<Type> GetSupportedInterfaces()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 319 KiB |
@@ -0,0 +1,24 @@
|
||||
;format is signal_name = range|resolution|min_delay(ms)|max_delay(ms)|scale factor|relays|type|cable, connector and pin id|lower_limit|upper_limit
|
||||
;Range format for Raptor Squib Meter:
|
||||
; Refer to 101-SQB-RAK Meter Customer Command Set Verion 1.0.8.pdf, page 13 on range setting
|
||||
; There is no auto range
|
||||
; Possible ranges:
|
||||
; 0 No Range
|
||||
; 1 DIODE Range
|
||||
; 2 20 Ohm
|
||||
; 3 200 Ohm
|
||||
; 4 2K Ohm
|
||||
; 5 20K Ohm
|
||||
; 6 200K Ohm
|
||||
; 7 2M Ohm
|
||||
;Type is TWO or FOUR for two wire and four wire measurements
|
||||
;Relay Format: [Card_Name]:[Path]
|
||||
; [Card_Name] - Must match the name of the switch card defined in the Instrument.xml
|
||||
; [Path] - [card#].[channel#],[card#].[channel#]
|
||||
; If card# = 0, then all cards are treated as 1 virtual card.
|
||||
; That means the number of channels = # of cards x 96 (channels)
|
||||
; If card# > 0, then each card is treated as individual card.
|
||||
; The number of channels = 96
|
||||
;Cable and Pin Id Format: [Cable_Id]_[Connecto_Id]_[Pin_Id]_[Cable_Id]_[Connector_Id]_[Pin_Id]
|
||||
[DmmReadResistance]
|
||||
SIGNAL_1 = NO_PCODE|7|0.001|100|1|PICKERING_SWITCH_MULTIPLEXER_96X4:0.1,0.96|FOUR|W1_P3_52_W1_P4_4|0.0|5.0
|
||||
@@ -0,0 +1,2 @@
|
||||
Pickering LXI Chassis 65-200-002
|
||||
Pickering LXI Multiplexer 65-260-901
|
||||
@@ -0,0 +1,510 @@
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using System;
|
||||
using NLog;
|
||||
using Pickering.Lxi.Piplx;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A Pickering implementation of the IRelaySwitch interface
|
||||
/// </summary>
|
||||
public class SwitchMultiplexerPickering60x : ISwitch
|
||||
{
|
||||
enum SubUnit
|
||||
{
|
||||
HiMux,
|
||||
LoMux,
|
||||
Switch,
|
||||
Matrix
|
||||
}
|
||||
|
||||
#region PrivateMemberVariables
|
||||
private string _name;
|
||||
private string _lxiIpAddress;
|
||||
private bool _isSingleCardMode;
|
||||
private int _cardNumWithConnectedDmm;
|
||||
private int _cardStartingIndex = 0;
|
||||
private int _virtualCardCount = 1;
|
||||
private int _numBusSelectPerCard = 0;
|
||||
// Only used to route a closed channel from one card to another card that is connected to DMM to make measurement
|
||||
// There's no use case for us to be switching between the bus select channels, so we pick one channel to route signals from one card to another
|
||||
static private int _busSelectMatrixChanNum = 1;
|
||||
private State _state;
|
||||
private SelfTestResult _selfTestResult;
|
||||
private object _syncObj = new Object();
|
||||
private PiplxManager _piplxManager;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PrivateFunctions
|
||||
|
||||
/// <summary>
|
||||
/// Close/open relay pair defined in the path
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to open</param>
|
||||
private void OperateRelays(string path, bool state)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
// split path into 2 items. Each item contains channel information
|
||||
string[] channelArray = path.Split(',');
|
||||
|
||||
if (channelArray.Length != 2)
|
||||
{
|
||||
throw new Exception($"Invalid path: {path}. Expected format: [Card_Index].[Switch_Chan_Num],[Card_Index].[Switch_Chan_Num]");
|
||||
}
|
||||
|
||||
string channelInfo;
|
||||
int hiChannelNum = 0;
|
||||
int loChannelNum = 0;
|
||||
int hiCardNum = 0;
|
||||
int loCardNum = 0;
|
||||
for (int i = 0; i < channelArray.Length; i++)
|
||||
{
|
||||
channelInfo = channelArray[i].Trim();
|
||||
|
||||
string[] itemArray = channelInfo.Split('.');
|
||||
|
||||
int itemIndex = 0;
|
||||
if (int.TryParse(itemArray[itemIndex++], out int cardIndex) && int.TryParse(itemArray[itemIndex++], out int channelNum))
|
||||
{
|
||||
if (_isSingleCardMode)
|
||||
{
|
||||
if (cardIndex != _cardStartingIndex)
|
||||
throw new Exception($"Invalid card index: {cardIndex}. Card index can only be 0 when operating in single card mode");
|
||||
}
|
||||
else if (cardIndex < _cardStartingIndex || cardIndex >= _piplxManager.CardsCount)
|
||||
{
|
||||
throw new Exception($"Invalid card index: {cardIndex}. Card index can only be between {_cardStartingIndex} and {_piplxManager.CardsCount - 1} when operating in individual card mode");
|
||||
}
|
||||
|
||||
// close/open the channel relay
|
||||
GetSwitchSubUnit(cardIndex).OperateBit(channelNum, state);
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
// close/open Hi mux relay
|
||||
GetHiMuxSubUnit(cardIndex).OperateBit(channelNum, state);
|
||||
hiCardNum = cardIndex;
|
||||
hiChannelNum = channelNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
// close/open Lo mux relay
|
||||
GetLoMuxSubUnit(cardIndex).OperateBit(channelNum, state);
|
||||
loCardNum = cardIndex;
|
||||
loChannelNum = channelNum;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid channel information: {channelInfo}. Expected format: [Card_Index].[Switch_Chan_Num]");
|
||||
}
|
||||
}
|
||||
|
||||
if (hiChannelNum > 0 && loChannelNum > 0)
|
||||
{
|
||||
if (_isSingleCardMode)
|
||||
{
|
||||
// calculate physical number of switching channels per physical card
|
||||
int phyNumChanPerCard = GetSwitchSubUnit(_cardStartingIndex).BitsCount / (_piplxManager.CardsCount - 1);
|
||||
|
||||
// calculate physical card number for Hi side
|
||||
int phyHiCardNum = (int)Math.Ceiling((double)hiChannelNum / (double)phyNumChanPerCard);
|
||||
|
||||
// calculate physical card number for Lo side
|
||||
int phyLoCardNum = (int)Math.Ceiling((double)loChannelNum / (double)phyNumChanPerCard);
|
||||
|
||||
if (phyHiCardNum != _cardNumWithConnectedDmm)
|
||||
{
|
||||
// calculate virtual bus select matrix channel on the card that is being switched
|
||||
int virtualBusSelectMatrixChanNum = (phyHiCardNum * _numBusSelectPerCard) + (_busSelectMatrixChanNum - _numBusSelectPerCard);
|
||||
|
||||
// open/close the bus select channel so we can route the Hi channel from this card to the card connected to the DMM
|
||||
GetMatrixSubUnit(_cardStartingIndex).OperateCrosspoint(1, virtualBusSelectMatrixChanNum, state);
|
||||
}
|
||||
|
||||
if (phyLoCardNum != _cardNumWithConnectedDmm)
|
||||
{
|
||||
// calculate virtual bus select matrix channel on the card that is being switched
|
||||
int virtualBusSelectMatrixChanNum = (phyLoCardNum * _numBusSelectPerCard) + (_busSelectMatrixChanNum - _numBusSelectPerCard);
|
||||
|
||||
// open/close the bus select channel so we can route the Lo channel from this card to the card connected to the DMM
|
||||
GetMatrixSubUnit(_cardStartingIndex).OperateCrosspoint(2, virtualBusSelectMatrixChanNum, state);
|
||||
}
|
||||
}
|
||||
else if (hiCardNum > 0 && loCardNum > 0)
|
||||
{
|
||||
if (hiCardNum != _cardNumWithConnectedDmm)
|
||||
{
|
||||
// open/close the bus select channel so we can route the Hi channel from this card to the card connected to the DMM
|
||||
GetMatrixSubUnit(hiCardNum).OperateCrosspoint(1, _busSelectMatrixChanNum, state);
|
||||
}
|
||||
|
||||
if (loCardNum != _cardNumWithConnectedDmm)
|
||||
{
|
||||
// open/close the bus select channel so we can route the Lo channel from this card to the card connected to the DMM
|
||||
GetMatrixSubUnit(loCardNum).OperateCrosspoint(2, _busSelectMatrixChanNum, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens all relays on the card
|
||||
/// </summary>
|
||||
private void RelayOpenAll()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
for (int i = _cardStartingIndex; i < _virtualCardCount; i++)
|
||||
{
|
||||
if (_piplxManager.Cards[i].IsOpen())
|
||||
{
|
||||
GetHiMuxSubUnit(i).ClearSubunit();
|
||||
GetLoMuxSubUnit(i).ClearSubunit();
|
||||
GetSwitchSubUnit(i).ClearSubunit();
|
||||
GetMatrixSubUnit(i).ClearSubunit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Hi Mux Sub Unit
|
||||
/// </summary>
|
||||
private MultiplexerSubunit GetHiMuxSubUnit(int cardIndex)
|
||||
{
|
||||
return (MultiplexerSubunit)((PiplxCard)_piplxManager.Cards[cardIndex]).OutputSubunits[(int)SubUnit.HiMux];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Low Mux Sub Unit
|
||||
/// </summary>
|
||||
private MultiplexerSubunit GetLoMuxSubUnit(int cardIndex)
|
||||
{
|
||||
return (MultiplexerSubunit)((PiplxCard)_piplxManager.Cards[cardIndex]).OutputSubunits[(int)SubUnit.LoMux];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Switch Sub Unit
|
||||
/// </summary>
|
||||
private SwitchSubunit GetSwitchSubUnit(int cardIndex)
|
||||
{
|
||||
return (SwitchSubunit)((PiplxCard)_piplxManager.Cards[cardIndex]).OutputSubunits[(int)SubUnit.Switch];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Matrix Sub Unit
|
||||
/// </summary>
|
||||
private MatrixSubunit GetMatrixSubUnit(int cardIndex)
|
||||
{
|
||||
return (MatrixSubunit)((PiplxCard)_piplxManager.Cards[cardIndex]).OutputSubunits[(int)SubUnit.Matrix];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// SwitchMultiplexerPickering60x factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchMultiplexerPickering60x(string deviceName, IConfigurationManager configurationManager)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_lxiIpAddress = _configuration.GetConfigurationValue(Name, "LXI_IP_ADDRESS");
|
||||
bool.TryParse(_configuration.GetConfigurationValue(Name, "IS_SINGLE_CARD_MODE"), out _isSingleCardMode);
|
||||
Int32.TryParse(_configuration.GetConfigurationValue(Name, "CARD_NUMBER_WITH_CONNECTED_DMM"), out _cardNumWithConnectedDmm);
|
||||
Int32.TryParse(_configuration.GetConfigurationValue(Name, "BUS_SELECT_MATRIX_CHANNEL_NUMBER"), out _busSelectMatrixChanNum);
|
||||
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Finalizer
|
||||
/// </summary>
|
||||
~SwitchMultiplexerPickering60x()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
public void Connect(string path)
|
||||
{
|
||||
OperateRelays(path, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
public void Disconnect(string path)
|
||||
{
|
||||
OperateRelays(path, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisconnectAll()
|
||||
{
|
||||
RelayOpenAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Pickering Switch";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
_piplxManager = new PiplxManager(_lxiIpAddress);
|
||||
|
||||
if (!_isSingleCardMode)
|
||||
{
|
||||
_cardStartingIndex = 1;
|
||||
_virtualCardCount = _piplxManager.CardsCount;
|
||||
_numBusSelectPerCard = GetMatrixSubUnit(_cardStartingIndex).BitsCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
// calculate number of bus select channels per card
|
||||
_numBusSelectPerCard = (GetMatrixSubUnit(_cardStartingIndex).BitsCount / (_piplxManager.CardsCount - 1)) / 2;
|
||||
}
|
||||
|
||||
if (_busSelectMatrixChanNum < 1 || _busSelectMatrixChanNum > _numBusSelectPerCard)
|
||||
{
|
||||
throw new Exception($"Invalid bus select channel: {_busSelectMatrixChanNum}. Number must be between 1 and {_numBusSelectPerCard}");
|
||||
}
|
||||
|
||||
if (_cardNumWithConnectedDmm < 1 || _cardNumWithConnectedDmm >= _piplxManager.CardsCount)
|
||||
{
|
||||
throw new Exception($"Invalid card number: {_cardNumWithConnectedDmm} for the card that is connected to DMM. Number must be between 1 and {_piplxManager.CardsCount - 1}");
|
||||
}
|
||||
|
||||
for (int i = _cardStartingIndex; i < _virtualCardCount; i++)
|
||||
{
|
||||
_piplxManager.Cards[i].Open();
|
||||
|
||||
GetHiMuxSubUnit(i).ClearSubunit();
|
||||
GetLoMuxSubUnit(i).ClearSubunit();
|
||||
GetSwitchSubUnit(i).ClearSubunit();
|
||||
GetMatrixSubUnit(i).ClearSubunit();
|
||||
}
|
||||
|
||||
if (_isSingleCardMode)
|
||||
{
|
||||
// calculate virtual bus select matrix channel on the card that's connected to the DMM
|
||||
int virtualBusSelectMatrixChanNum = (_cardNumWithConnectedDmm * _numBusSelectPerCard) + (_busSelectMatrixChanNum - _numBusSelectPerCard);
|
||||
|
||||
// close the bus select relay on the card that is connected to DMM
|
||||
// so we can route channels on other cards to this card in order to make DMM measurements
|
||||
// close the Hi channel
|
||||
GetMatrixSubUnit(_cardStartingIndex).OperateCrosspoint(1, virtualBusSelectMatrixChanNum, true);
|
||||
// close the Lo channel
|
||||
GetMatrixSubUnit(_cardStartingIndex).OperateCrosspoint(2, virtualBusSelectMatrixChanNum, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// close the bus select relay on the card that is connected to DMM
|
||||
// so we can route channels on other cards to this card in order to make DMM measurements
|
||||
// close the Hi channel
|
||||
GetMatrixSubUnit(_cardNumWithConnectedDmm).OperateCrosspoint(1, _busSelectMatrixChanNum, true);
|
||||
// close the Lo channel
|
||||
GetMatrixSubUnit(_cardNumWithConnectedDmm).OperateCrosspoint(2, _busSelectMatrixChanNum, true);
|
||||
}
|
||||
|
||||
_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 string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selfTestResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
RelayOpenAll();
|
||||
|
||||
for (int i = _cardStartingIndex; i < _virtualCardCount; i++)
|
||||
{
|
||||
if (_piplxManager.Cards[i].IsOpen())
|
||||
{
|
||||
_piplxManager.Cards[i].Close();
|
||||
}
|
||||
}
|
||||
|
||||
if (_piplxManager != null && _piplxManager.Connected)
|
||||
{
|
||||
_piplxManager.Disconnect();
|
||||
}
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>Raytheon.Instruments.SwitchMultiplexerPickering60x</AssemblyName>
|
||||
<Product>Switch Multiplexer Pickering 60x implementation</Product>
|
||||
<Description>Switch Multiplexer Pickering 60x implementation</Description>
|
||||
<OutputType>Library</OutputType>
|
||||
|
||||
<!-- Static versioning (Suitable for Development) -->
|
||||
<!-- Disable the line below for dynamic versioning -->
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog" Version="5.0.0" />
|
||||
<PackageReference Include="Raytheon.Common" Version="1.0.0" />
|
||||
<PackageReference Include="Raytheon.Instruments.Switch.Contracts" Version="1.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SwitchSim\SwitchSim.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Pickering.Lxi.Communication">
|
||||
<HintPath>..\..\Common\COTS\Pickering\Pickering.Lxi.Communication.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Pickering.Lxi.Piplx">
|
||||
<HintPath>..\..\Common\COTS\Pickering\Pickering.Lxi.Piplx.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Copy all *.dlls and *.pdb in the output folder to a temp folder -->
|
||||
<Target Name="CopyFiles" AfterTargets="AfterBuild">
|
||||
<ItemGroup>
|
||||
<FILES_1 Include="$(OutDir)*.dll" />
|
||||
<FILES_2 Include="$(OutDir)*.pdb" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(FILES_1)" DestinationFolder="$(HalTempFolder)" />
|
||||
<Copy SourceFiles="@(FILES_2)" DestinationFolder="$(HalTempFolder)" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -0,0 +1,131 @@
|
||||
// **********************************************************************************************************
|
||||
// SwitchMatrixPickering40xFactory.cs
|
||||
// 2/20/2023
|
||||
// NGI - Next Generation Interceptor
|
||||
//
|
||||
// Contract No. HQ0856-21-C-0003/1022000209
|
||||
//
|
||||
// THIS DOCUMENT DOES NOT CONTAIN TECHNOLOGY OR TECHNICAL DATA CONTROLLED UNDER EITHER THE U.S.
|
||||
// INTERNATIONAL TRAFFIC IN ARMS REGULATIONS OR THE U.S. EXPORT ADMINISTRATION REGULATIONS.
|
||||
//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION PROPRIETARY TO RAYTHEON
|
||||
// COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT.
|
||||
// DISCLOSURE TO UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO RAYTHEON
|
||||
// COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS CONTENTS SHALL BE FURNISHED OR DISCLOSED
|
||||
// TO OR COPIED OR USED BY PERSONS OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF
|
||||
// RAYTHEON COMPANY.
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// DESTRUCTION NOTICE: FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN DOD 5220.22-M,
|
||||
// NATIONAL INDUSTRIAL SECURITY PROGRAM OPERATING MANUAL, FEBRUARY 2006,
|
||||
// INCORPORATING CHANGE 1, MARCH 28, 2013, CHAPTER 5, SECTION 7, OR DODM 5200.01-VOLUME 3,
|
||||
// DOD INFORMATION SECURITY PROGRAM: PROTECTION OF CLASSIFIED INFORMATION, ENCLOSURE 3,
|
||||
// SECTION 17. FOR CONTROLLED UNCLASSIFIED INFORMATION FOLLOW THE PROCEDURES IN DODM 5200.01-VOLUME 4,
|
||||
// INFORMATION SECURITY PROGRAM: CONTROLLED UNCLASSIFIED INFORMATION.
|
||||
//
|
||||
// CONTROLLED BY: MISSILE DEFENSE AGENCY
|
||||
// CONTROLLED BY: GROUND-BASED MIDCOURSE DEFENSE PROGRAM OFFICE
|
||||
// CUI CATEGORY: CTI
|
||||
// DISTRIBUTION/DISSEMINATION CONTROL: F
|
||||
// POC: Alex Kravchenko (1118268)
|
||||
// **********************************************************************************************************
|
||||
|
||||
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 = "SwitchMultiplexerPickering60xFactory")]
|
||||
public class SwitchMultiplexerPickering60xFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
|
||||
private static string DefaultPath;
|
||||
|
||||
public SwitchMultiplexerPickering60xFactory(string defaultConfigPath = DefaultConfigPath)
|
||||
: this(null, defaultConfigPath)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SwitchMultiplexerPickering60xFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public SwitchMultiplexerPickering60xFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
|
||||
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 SwitchMultiplexerPickering60x(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public object GetInstrument(string name, bool simulateHw)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (simulateHw)
|
||||
return new SwitchSim(name, _configurationManager);
|
||||
else
|
||||
return new SwitchMultiplexerPickering60x(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets supported interfaces
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICollection<Type> GetSupportedInterfaces()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = "SwitchNiPxiFactory")]
|
||||
public class SwitchNiPxiFactory : 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 = "SwitchNiPxiFactory")]
|
||||
public class SwitchNiPxiFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public SwitchNiPxiFactory(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 SwitchNiPxiFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public SwitchNiPxiFactory(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>
|
||||
/// SwitchNiPxiFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public SwitchNiPxiFactory([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 SwitchNiPxi(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 SwitchNiPxi(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 SwitchNiPxi(name, _configurationManager, _logger);
|
||||
return new SwitchNiPxi(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,250 +15,246 @@ GOVERNMENT.
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using System;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using System;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
public class SwitchNise : ISwitch
|
||||
{
|
||||
private int _hSession = 0;
|
||||
/// <summary>
|
||||
/// NLog logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Raytheon configuration
|
||||
/// </summary>
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
public class SwitchNise : ISwitch
|
||||
{
|
||||
private int _hSession = 0;
|
||||
|
||||
/// <summary>
|
||||
/// SwitchNise factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchNise(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
_logger = logger;
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
/// <summary>
|
||||
/// SwitchNise factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchNise(string deviceName, IConfigurationManager configurationManager)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
var virtualDeviceName = _configuration.GetConfigurationValue("SwitchNise", "VirtualDeviceName", "");
|
||||
string options = _configuration.GetConfigurationValue("SwitchNise", "Options", "");
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
|
||||
try
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_OpenSession(virtualDeviceName, options, out _hSession);
|
||||
if (status != 0)
|
||||
{
|
||||
throw new InstrumentException(string.Format("Could not open NISE session '{0}', error # {1}", virtualDeviceName, status));
|
||||
}
|
||||
}
|
||||
catch (BadImageFormatException ex)
|
||||
{
|
||||
throw new InstrumentException("Possible 32/64-bit issue with NI Switch Executive, see inner exception.", ex);
|
||||
}
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
DetailedStatus = "";
|
||||
DisplayEnabled = false;
|
||||
FrontPanelEnabled = false;
|
||||
Info = new InstrumentMetadata
|
||||
{
|
||||
ModelNumber = "NISE"
|
||||
};
|
||||
Name = virtualDeviceName;
|
||||
SelfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
|
||||
Status = State.Ready;
|
||||
}
|
||||
var virtualDeviceName = _configuration.GetConfigurationValue("SwitchNise", "VirtualDeviceName", "");
|
||||
string options = _configuration.GetConfigurationValue("SwitchNise", "Options", "");
|
||||
|
||||
public SwitchNise(string virtualDeviceName)
|
||||
{
|
||||
string options = "";
|
||||
var status = -123;
|
||||
try
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_OpenSession(virtualDeviceName, options, out _hSession);
|
||||
if (status != 0)
|
||||
{
|
||||
throw new InstrumentException(string.Format("Could not open NISE session '{0}', error # {1}", virtualDeviceName, status));
|
||||
}
|
||||
}
|
||||
catch (BadImageFormatException ex)
|
||||
{
|
||||
throw new InstrumentException("Possible 32/64-bit issue with NI Switch Executive, see inner exception.", ex);
|
||||
}
|
||||
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
DetailedStatus = "";
|
||||
DisplayEnabled = false;
|
||||
FrontPanelEnabled = false;
|
||||
Info = new InstrumentMetadata
|
||||
{
|
||||
ModelNumber = "NISE"
|
||||
};
|
||||
Name = virtualDeviceName;
|
||||
SelfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
|
||||
Status = State.Ready;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
status = NiseNativeMethods.niSE_OpenSession(virtualDeviceName, options, out _hSession);
|
||||
public SwitchNise(string virtualDeviceName)
|
||||
{
|
||||
string options = "";
|
||||
var status = -123;
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
throw new InstrumentException(string.Format("Could not open NISE session '{0}', error # {1}", virtualDeviceName, status));
|
||||
}
|
||||
}
|
||||
catch (BadImageFormatException ex)
|
||||
{
|
||||
throw new InstrumentException("Possible 32/64-bit issue with NI Switch Executive, see inner exception.", ex);
|
||||
}
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {virtualDeviceName}");
|
||||
|
||||
DetailedStatus = "";
|
||||
DisplayEnabled = false;
|
||||
FrontPanelEnabled = false;
|
||||
Info = new InstrumentMetadata();
|
||||
Info.ModelNumber = "NISE";
|
||||
Name = virtualDeviceName;
|
||||
SelfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
|
||||
Status = State.Ready;
|
||||
}
|
||||
try
|
||||
{
|
||||
status = NiseNativeMethods.niSE_OpenSession(virtualDeviceName, options, out _hSession);
|
||||
|
||||
public bool ClearErrors()
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_ClearError(_hSession);
|
||||
if (status != 0)
|
||||
{
|
||||
throw new InstrumentException(string.Format("Could not open NISE session '{0}', error # {1}", virtualDeviceName, status));
|
||||
}
|
||||
}
|
||||
catch (BadImageFormatException ex)
|
||||
{
|
||||
throw new InstrumentException("Possible 32/64-bit issue with NI Switch Executive, see inner exception.", ex);
|
||||
}
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "ClearError failed";
|
||||
DetailedStatus = "";
|
||||
DisplayEnabled = false;
|
||||
FrontPanelEnabled = false;
|
||||
Info = new InstrumentMetadata();
|
||||
Info.ModelNumber = "NISE";
|
||||
Name = virtualDeviceName;
|
||||
SelfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
|
||||
Status = State.Ready;
|
||||
}
|
||||
|
||||
throw new InstrumentException("" + string.Format("Could not clear errors, error # {0}", status));
|
||||
}
|
||||
public bool ClearErrors()
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_ClearError(_hSession);
|
||||
|
||||
Status = State.Ready;
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "ClearError failed";
|
||||
|
||||
return true;
|
||||
}
|
||||
throw new InstrumentException("" + string.Format("Could not clear errors, error # {0}", status));
|
||||
}
|
||||
|
||||
public void Connect(string path)
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_Connect(_hSession, path, NiseNativeMethods.MulticonnectMode.NoMulticonnect, true);
|
||||
Status = State.Ready;
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "Connect failed";
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new InstrumentException("" + string.Format("Could not connect '{0}', NISE error # {1}", path, status));
|
||||
}
|
||||
}
|
||||
public void Connect(string path)
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_Connect(_hSession, path, NiseNativeMethods.MulticonnectMode.NoMulticonnect, true);
|
||||
|
||||
public string DetailedStatus
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "Connect failed";
|
||||
|
||||
public void Disconnect(string path)
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_Disconnect(_hSession, path);
|
||||
throw new InstrumentException("" + string.Format("Could not connect '{0}', NISE error # {1}", path, status));
|
||||
}
|
||||
}
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
throw new InstrumentException(string.Format("" + "Could not disconnect '{0}', NISE error # {1}", path, status));
|
||||
}
|
||||
}
|
||||
public string DetailedStatus
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public void DisconnectAll()
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_DisconnectAll(_hSession);
|
||||
public void Disconnect(string path)
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_Disconnect(_hSession, path);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "DisconnectAll failed";
|
||||
if (status != 0)
|
||||
{
|
||||
throw new InstrumentException(string.Format("" + "Could not disconnect '{0}', NISE error # {1}", path, status));
|
||||
}
|
||||
}
|
||||
|
||||
throw new InstrumentException(string.Format("" + "Could not disconnect all, NISE error # {0}", status));
|
||||
}
|
||||
}
|
||||
public void DisconnectAll()
|
||||
{
|
||||
int status = NiseNativeMethods.niSE_DisconnectAll(_hSession);
|
||||
|
||||
//*** consider implementing 'set' to change back to some default value
|
||||
// not available
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "DisconnectAll failed";
|
||||
|
||||
//*** consider implementing 'set' to change back to some default value
|
||||
// not available
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
throw new InstrumentException(string.Format("" + "Could not disconnect all, NISE error # {0}", status));
|
||||
}
|
||||
}
|
||||
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
//*** consider implementing 'set' to change back to some default value
|
||||
// not available
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
// do not want to allow user to open another session since they must close each one
|
||||
// they open. already opened in constructor
|
||||
//*** consider implementing 'set' to change back to some default value
|
||||
// not available
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
ClearErrors();
|
||||
}
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool IsDebounced
|
||||
{
|
||||
get
|
||||
{
|
||||
bool isDebounced;
|
||||
int status = NiseNativeMethods.niSE_IsDebounced(_hSession, out isDebounced);
|
||||
public void Initialize()
|
||||
{
|
||||
// do not want to allow user to open another session since they must close each one
|
||||
// they open. already opened in constructor
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "IsDebounced failed";
|
||||
ClearErrors();
|
||||
}
|
||||
|
||||
throw new InstrumentException("" + string.Format("Could not check debounce, error # {0}", status));
|
||||
}
|
||||
public bool IsDebounced
|
||||
{
|
||||
get
|
||||
{
|
||||
bool isDebounced;
|
||||
int status = NiseNativeMethods.niSE_IsDebounced(_hSession, out isDebounced);
|
||||
|
||||
return isDebounced;
|
||||
}
|
||||
}
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "IsDebounced failed";
|
||||
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
throw new InstrumentException("" + string.Format("Could not check debounce, error # {0}", status));
|
||||
}
|
||||
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
return SelfTestResult.Pass;
|
||||
}
|
||||
return isDebounced;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
ClearErrors();
|
||||
DisconnectAll();
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
Status = State.Ready;
|
||||
DetailedStatus = "";
|
||||
}
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
return SelfTestResult.Pass;
|
||||
}
|
||||
|
||||
// not available
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
ClearErrors();
|
||||
DisconnectAll();
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
Int32 status = NiseNativeMethods.niSE_CloseSession(_hSession);
|
||||
Status = State.Ready;
|
||||
DetailedStatus = "";
|
||||
}
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "Close failed";
|
||||
// not available
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
throw new InstrumentException("" + string.Format("Could not close NISE session, error # {0}", status));
|
||||
}
|
||||
}
|
||||
public void Shutdown()
|
||||
{
|
||||
Int32 status = NiseNativeMethods.niSE_CloseSession(_hSession);
|
||||
|
||||
public State Status
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
}
|
||||
if (status != 0)
|
||||
{
|
||||
Status = State.HardwareFailure;
|
||||
DetailedStatus = "Close failed";
|
||||
|
||||
throw new InstrumentException("" + string.Format("Could not close NISE session, error # {0}", status));
|
||||
}
|
||||
}
|
||||
|
||||
public State Status
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = "SwitchNiseFactory")]
|
||||
public class SwitchNiseFactory : 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 = "SwitchNiseFactory")]
|
||||
public class SwitchNiseFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public SwitchNiseFactory(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 SwitchNiseFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public SwitchNiseFactory(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>
|
||||
/// SwitchNiseFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public SwitchNiseFactory([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 SwitchNise(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 SwitchNise(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 SwitchNise(name, _configurationManager, _logger);
|
||||
return new SwitchNise(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,388 +22,354 @@ using SwitchMeasurementInstrumentsLib.Pickering40LxiSoap;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A Pickering implementation of the IRelaySwitch interface
|
||||
/// </summary>
|
||||
public class SwitchPickeringLxi40_531_Soap : ISwitch, IDisposable
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
/// <summary>
|
||||
/// A Pickering implementation of the IRelaySwitch interface
|
||||
/// </summary>
|
||||
public class SwitchPickeringLxi40_531_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>
|
||||
~SwitchPickeringLxi40_531_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>
|
||||
~SwitchPickeringLxi40_531_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>
|
||||
/// SwitchPickeringLxi40_531_Soap factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchPickeringLxi40_531_Soap(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
#region PublicFunctions
|
||||
|
||||
_logger = logger;
|
||||
/// <summary>
|
||||
/// SwitchPickeringLxi40_531_Soap factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchPickeringLxi40_531_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("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);
|
||||
|
||||
_card = new PiCards
|
||||
{
|
||||
Url = $"http://{address}/bin/picards"
|
||||
};
|
||||
_subUnit = _configuration.GetConfigurationValue("SwitchPickeringLxi60_522_Soap", "SubUnit", 0);
|
||||
|
||||
LocationHeader lh = new LocationHeader
|
||||
{
|
||||
Slot = deviceNumber,
|
||||
Bus = busNumber
|
||||
};
|
||||
_card = new PiCards
|
||||
{
|
||||
Url = $"http://{address}/bin/picards"
|
||||
};
|
||||
|
||||
_card.CardLocation = lh;
|
||||
LocationHeader lh = new LocationHeader
|
||||
{
|
||||
Slot = deviceNumber,
|
||||
Bus = busNumber
|
||||
};
|
||||
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
_card.CardLocation = lh;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="address"></param>
|
||||
/// <param name="deviceNumber"></param>
|
||||
/// <param name="busNumber"></param>
|
||||
/// <param name="subUnit"></param>
|
||||
public SwitchPickeringLxi40_531_Soap(string name, string address, int deviceNumber, int busNumber, int subUnit)
|
||||
{
|
||||
_name = name;
|
||||
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
_subUnit = subUnit;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="address"></param>
|
||||
/// <param name="deviceNumber"></param>
|
||||
/// <param name="busNumber"></param>
|
||||
/// <param name="subUnit"></param>
|
||||
public SwitchPickeringLxi40_531_Soap(string deviceName, string address, int deviceNumber, int busNumber, int subUnit)
|
||||
{
|
||||
_name = deviceName;
|
||||
|
||||
_card = new PiCards();
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
|
||||
string tempAddress = "http://" + address + "/bin/picards";
|
||||
_card.Url = tempAddress;
|
||||
_subUnit = subUnit;
|
||||
|
||||
LocationHeader lh = new LocationHeader();
|
||||
lh.Slot = deviceNumber;
|
||||
lh.Bus = busNumber;
|
||||
_card = new PiCards();
|
||||
|
||||
_card.CardLocation = lh;
|
||||
string tempAddress = "http://" + address + "/bin/picards";
|
||||
_card.Url = tempAddress;
|
||||
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
LocationHeader lh = new LocationHeader();
|
||||
lh.Slot = deviceNumber;
|
||||
lh.Bus = busNumber;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
_card.CardLocation = lh;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
public void Connect(string path)
|
||||
{
|
||||
RelayClose(path);
|
||||
}
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
_card.ClearAll();
|
||||
_card.Dispose();
|
||||
_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)
|
||||
{
|
||||
_card.ClearAll();
|
||||
_card.Dispose();
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = "SwitchPickeringLxi40_531_SoapFactory")]
|
||||
public class SwitchPickeringLxi40_531_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 = "SwitchPickeringLxi40_531_SoapFactory")]
|
||||
public class SwitchPickeringLxi40_531_SoapFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public SwitchPickeringLxi40_531_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 SwitchPickeringLxi40_531_SoapFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public SwitchPickeringLxi40_531_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>
|
||||
/// SwitchPickeringLxi40_531_SoapFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public SwitchPickeringLxi40_531_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 SwitchPickeringLxi40_531_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 SwitchPickeringLxi40_531_Soap(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 SwitchPickeringLxi40_531_Soap(name, _configurationManager, _logger);
|
||||
return new SwitchPickeringLxi40_531_Soap(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
Pickering Switch Relay 40-156-001
|
||||
Pickering Switch Relay 40-137-101
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,329 +22,287 @@ using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A simulated implementation of the ISwitch interface.
|
||||
/// </summary>
|
||||
public class SwitchSim : ISwitch
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
/// <summary>
|
||||
/// A simulated implementation of the ISwitch interface.
|
||||
/// </summary>
|
||||
public class SwitchSim : ISwitch
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
|
||||
private Dictionary<String, bool> _relayStates;
|
||||
private string _name;
|
||||
private State _state;
|
||||
private SelfTestResult _selfTestResult;
|
||||
private Dictionary<String, bool> _relayStates;
|
||||
private string _name;
|
||||
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>
|
||||
~SwitchSim()
|
||||
{
|
||||
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)
|
||||
{
|
||||
_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>
|
||||
~SwitchSim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close a relay (simulated).
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to close.</param>
|
||||
private void RelayClose(string relay)
|
||||
{
|
||||
_relayStates[relay] = true;
|
||||
}
|
||||
/// <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)
|
||||
{
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open a relay (simulated).
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to open.</param>
|
||||
private void RelayOpen(string relay)
|
||||
{
|
||||
_relayStates[relay] = false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Close a relay (simulated).
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to close.</param>
|
||||
private void OperateRelays(string path, bool state)
|
||||
{
|
||||
_relayStates[path] = state;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private void RelayOpenAll()
|
||||
{
|
||||
List<string> keys = new List<string>(_relayStates.Keys);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private void RelayOpenAll()
|
||||
{
|
||||
List<string> keys = new List<string>(_relayStates.Keys);
|
||||
|
||||
foreach (string key in keys)
|
||||
{
|
||||
_relayStates[key] = false;
|
||||
}
|
||||
}
|
||||
foreach (string key in keys)
|
||||
{
|
||||
_relayStates[key] = false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// SwitchSim factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchSim(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
/// <summary>
|
||||
/// SwitchSim factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchSim(string deviceName, IConfigurationManager configurationManager)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_relayStates = new Dictionary<String, bool>();
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
_relayStates = new Dictionary<String, bool>();
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for RelaySwitch card (simulated).
|
||||
/// </summary>
|
||||
public SwitchSim(string name)
|
||||
{
|
||||
_name = name;
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_relayStates = new Dictionary<String, bool>();
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructor for RelaySwitch card (simulated).
|
||||
/// </summary>
|
||||
public SwitchSim(string deviceName)
|
||||
{
|
||||
_name = deviceName;
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
_relayStates = new Dictionary<String, bool>();
|
||||
_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)
|
||||
{
|
||||
OperateRelays(path, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
public void Disconnect(string path)
|
||||
{
|
||||
RelayOpen(path);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
public void Disconnect(string path)
|
||||
{
|
||||
OperateRelays(path, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisconnectAll()
|
||||
{
|
||||
RelayOpenAll();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisconnectAll()
|
||||
{
|
||||
RelayOpenAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispose(true);
|
||||
/// <summary>
|
||||
/// Dispose of 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 Sim Switch";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Sim 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 bool IsDebounced
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool IsDebounced
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 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 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()
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
/// <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()
|
||||
{
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = "SwitchSimFactory")]
|
||||
public class SwitchSimFactory : 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 = "SwitchSimFactory")]
|
||||
public class SwitchSimFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public SwitchSimFactory(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 SwitchSimFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public SwitchSimFactory(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>
|
||||
/// SwitchSimFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public SwitchSimFactory([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 SwitchSim(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 SwitchSim(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
@@ -106,9 +99,7 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
|
||||
return new SwitchSim(name, _configurationManager, _logger);
|
||||
return new SwitchSim(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -121,17 +112,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,367 +23,334 @@
|
||||
//>>***************************************************************************
|
||||
|
||||
using System;
|
||||
using VTI.VTEXSwitch.Interop;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using VTI.VTEXSwitch.Interop;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// This is a class for controlling a VTI EX1200-3001, 5002, 4264 switch card.
|
||||
/// It only supports individual relay mode at this time.
|
||||
/// </summary>
|
||||
public class SwitchVTI : ISwitch
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
private VTEXSwitch _switch;
|
||||
private string _name;
|
||||
private readonly string _address;
|
||||
private readonly string _options;
|
||||
private State _state;
|
||||
private SelfTestResult _selfTestResult;
|
||||
/// <summary>
|
||||
/// This is a class for controlling a VTI EX1200-3001, 5002, 4264 switch card.
|
||||
/// It only supports individual relay mode at this time.
|
||||
/// </summary>
|
||||
public class SwitchVTI : ISwitch
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
private VTEXSwitch _switch;
|
||||
private string _name;
|
||||
private readonly string _address;
|
||||
private readonly string _options;
|
||||
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
|
||||
/// <summary>
|
||||
/// Finalizer.
|
||||
/// </summary>
|
||||
~SwitchVTI()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <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)
|
||||
{
|
||||
Reset();
|
||||
#region PrivateFunctions
|
||||
/// <summary>
|
||||
/// Finalizer.
|
||||
/// </summary>
|
||||
~SwitchVTI()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
_switch.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)
|
||||
{
|
||||
Reset();
|
||||
|
||||
_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
|
||||
}
|
||||
}
|
||||
}
|
||||
_switch.Close();
|
||||
|
||||
/// <summary>
|
||||
/// Perform self-test.
|
||||
/// </summary>
|
||||
private string SelfTest()
|
||||
{
|
||||
int testResult = 0;
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string selfTestMessage = "";
|
||||
/// <summary>
|
||||
/// Perform self-test.
|
||||
/// </summary>
|
||||
private string SelfTest()
|
||||
{
|
||||
int testResult = 0;
|
||||
|
||||
_switch.Utility.SelfTest(ref testResult, ref selfTestMessage);
|
||||
string selfTestMessage = "";
|
||||
|
||||
if (testResult != 0)
|
||||
{
|
||||
throw new Exception("Self test returned an error code of: " + testResult.ToString() + ", and an error string of: " + selfTestMessage);
|
||||
}
|
||||
_switch.Utility.SelfTest(ref testResult, ref selfTestMessage);
|
||||
|
||||
return selfTestMessage;
|
||||
}
|
||||
#endregion
|
||||
if (testResult != 0)
|
||||
{
|
||||
throw new Exception("Self test returned an error code of: " + testResult.ToString() + ", and an error string of: " + selfTestMessage);
|
||||
}
|
||||
|
||||
#region PublicFunctions
|
||||
return selfTestMessage;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// SwitchVTI factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchVTI(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
#region PublicFunctions
|
||||
|
||||
_logger = logger;
|
||||
/// <summary>
|
||||
/// SwitchVTI factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public SwitchVTI(string deviceName, IConfigurationManager configurationManager)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
|
||||
_address = _configuration.GetConfigurationValue("SwitchVTI", "Address", "");
|
||||
_options = _configuration.GetConfigurationValue("SwitchVTI", "Options", "");
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
_address = _configuration.GetConfigurationValue("SwitchVTI", "Address", "");
|
||||
_options = _configuration.GetConfigurationValue("SwitchVTI", "Options", "");
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for RelaySwitch card.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="address">The address of the RelaySwitch.</param>
|
||||
/// <param name="options">The options used for setting up the instrument.</param>
|
||||
public SwitchVTI(string name, string address, string options)
|
||||
{
|
||||
_name = name;
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_address = address;
|
||||
_options = options;
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
// created in initialized
|
||||
_switch = null;
|
||||
/// <summary>
|
||||
/// Constructor for RelaySwitch card.
|
||||
/// </summary>
|
||||
/// <param name="deviceName">The name.</param>
|
||||
/// <param name="address">The address of the RelaySwitch.</param>
|
||||
/// <param name="options">The options used for setting up the instrument.</param>
|
||||
public SwitchVTI(string deviceName, string address, string options)
|
||||
{
|
||||
_name = deviceName;
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
_address = address;
|
||||
_options = options;
|
||||
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
// created in initialized
|
||||
_switch = null;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
_state = State.Uninitialized;
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close a single relay.
|
||||
/// The COTS library works on string inputs:
|
||||
/// - Ex Relay: "2!K1" Means card 2 relay 1.
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to close.</param>
|
||||
public void Connect(string path)
|
||||
{
|
||||
_switch.InstrumentSpecific.CloseRelays(path);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open a single relay.
|
||||
/// The COTS library works on string inputs:
|
||||
/// - Ex Relay: "2!K1" Means card 2 relay 1.
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to open.</param>
|
||||
public void Disconnect(string path)
|
||||
{
|
||||
_switch.InstrumentSpecific.OpenRelays(path);
|
||||
}
|
||||
/// <summary>
|
||||
/// Close a single relay.
|
||||
/// The COTS library works on string inputs:
|
||||
/// - Ex Relay: "2!K1" Means card 2 relay 1.
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to close.</param>
|
||||
public void Connect(string path)
|
||||
{
|
||||
_switch.InstrumentSpecific.CloseRelays(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisconnectAll()
|
||||
{
|
||||
string relayList = _switch.InstrumentSpecific.ListOfRelays;
|
||||
/// <summary>
|
||||
/// Open a single relay.
|
||||
/// The COTS library works on string inputs:
|
||||
/// - Ex Relay: "2!K1" Means card 2 relay 1.
|
||||
/// </summary>
|
||||
/// <param name="relay">The relay to open.</param>
|
||||
public void Disconnect(string path)
|
||||
{
|
||||
_switch.InstrumentSpecific.OpenRelays(path);
|
||||
}
|
||||
|
||||
_switch.InstrumentSpecific.OpenRelays(relayList);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisconnectAll()
|
||||
{
|
||||
string relayList = _switch.InstrumentSpecific.ListOfRelays;
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispose(true);
|
||||
_switch.InstrumentSpecific.OpenRelays(relayList);
|
||||
}
|
||||
|
||||
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 resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a VTI Switch";
|
||||
}
|
||||
}
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a VTI Switch";
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool FrontPanelEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
_switch = new VTEXSwitch();
|
||||
_switch.Initialize(_address, false, true, _options);
|
||||
_state = State.Ready;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool IsDebounced
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
_switch = new VTEXSwitch();
|
||||
_switch.Initialize(_address, false, true, _options);
|
||||
_state = State.Ready;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool IsDebounced
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
int testResult = 0;
|
||||
string result = "";
|
||||
_switch.Utility.SelfTest(ref testResult, ref result);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
// Set measurement input to backplane after performing self test. Default is front panel.
|
||||
// _dmm.Measurement.In = VTEXDmmInputSelectEnum.VTEXDmmInputSelectInternal;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
int testResult = 0;
|
||||
string result = "";
|
||||
_switch.Utility.SelfTest(ref testResult, ref result);
|
||||
|
||||
if (testResult > 0)
|
||||
{
|
||||
_selfTestResult = Raytheon.Instruments.SelfTestResult.Fail;
|
||||
throw new Exception("self test failed with an Error Code: " + testResult + " and Error Message: " + result);
|
||||
}
|
||||
// Set measurement input to backplane after performing self test. Default is front panel.
|
||||
// _dmm.Measurement.In = VTEXDmmInputSelectEnum.VTEXDmmInputSelectInternal;
|
||||
|
||||
_selfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
|
||||
if (testResult > 0)
|
||||
{
|
||||
_selfTestResult = Raytheon.Instruments.SelfTestResult.Fail;
|
||||
throw new Exception("self test failed with an Error Code: " + testResult + " and Error Message: " + result);
|
||||
}
|
||||
|
||||
return _selfTestResult;
|
||||
}
|
||||
_selfTestResult = Raytheon.Instruments.SelfTestResult.Pass;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
_switch.Utility.Reset();
|
||||
}
|
||||
return _selfTestResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SelfTestResult SelfTestResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selfTestResult;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
_switch.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)
|
||||
{
|
||||
Reset();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
}
|
||||
|
||||
_switch.Close();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
Reset();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
_switch.Close();
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = "SwitchVTIFactory")]
|
||||
public class SwitchVTIFactory : 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 = "SwitchVTIFactory")]
|
||||
public class SwitchVTIFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public SwitchVTIFactory(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 SwitchVTIFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public SwitchVTIFactory(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>
|
||||
/// SwitchVTIFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public SwitchVTIFactory([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 SwitchVTI(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 SwitchVTI(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 SwitchVTI(name, _configurationManager, _logger);
|
||||
return new SwitchVTI(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user