Major upgrade
This commit is contained in:
@@ -24,286 +24,253 @@ using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// Temperature monitor class used to interact with the M3446 temperature sensor.
|
||||
/// Parsing assumes Echo mode is turned off (front panel of instrument)
|
||||
/// </summary>
|
||||
public class TempMonitorOmegaM3446 : ITempMonitor
|
||||
{
|
||||
#region PrivateMembers
|
||||
//Commands
|
||||
private const string _CARRIAGE_RTN = "\r";
|
||||
private const string _TEMP = "*X03";
|
||||
private const string _VERSION = "*U03";
|
||||
/// <summary>
|
||||
/// Temperature monitor class used to interact with the M3446 temperature sensor.
|
||||
/// Parsing assumes Echo mode is turned off (front panel of instrument)
|
||||
/// </summary>
|
||||
public class TempMonitorOmegaM3446 : ITempMonitor
|
||||
{
|
||||
#region PrivateMembers
|
||||
//Commands
|
||||
private const string _CARRIAGE_RTN = "\r";
|
||||
private const string _TEMP = "*X03";
|
||||
private const string _VERSION = "*U03";
|
||||
|
||||
//Prevent Collisions
|
||||
private static object m_sync = new object();
|
||||
//Prevent Collisions
|
||||
private static object m_sync = new object();
|
||||
|
||||
private readonly string _ipAddr;
|
||||
private readonly int _port;
|
||||
private const int _READ_BUFFER_SIZE = 128;
|
||||
private const int _READ_TIMEOUT = 5000;
|
||||
private byte[] _readBuffer;
|
||||
private NetworkStream _tcpStream;
|
||||
/// <summary>
|
||||
/// NLog logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Raytheon configuration
|
||||
/// </summary>
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly string _ipAddr;
|
||||
private readonly int _port;
|
||||
private const int _READ_BUFFER_SIZE = 128;
|
||||
private const int _READ_TIMEOUT = 5000;
|
||||
private byte[] _readBuffer;
|
||||
private NetworkStream _tcpStream;
|
||||
|
||||
public string DetailedStatus => throw new NotImplementedException();
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public bool DisplayEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public bool FrontPanelEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public InstrumentMetadata Info => throw new NotImplementedException();
|
||||
public string DetailedStatus => throw new NotImplementedException();
|
||||
|
||||
public string Name { get; set; }
|
||||
public bool DisplayEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public bool FrontPanelEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public SelfTestResult SelfTestResult => throw new NotImplementedException();
|
||||
public InstrumentMetadata Info => throw new NotImplementedException();
|
||||
|
||||
public State Status => throw new NotImplementedException();
|
||||
public string Name { get; set; }
|
||||
|
||||
#endregion
|
||||
public SelfTestResult SelfTestResult => throw new NotImplementedException();
|
||||
|
||||
#region PrivateFunctions
|
||||
/// <summary>
|
||||
/// Destructor
|
||||
/// </summary>
|
||||
~TempMonitorOmegaM3446()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
public State Status => throw new NotImplementedException();
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object's resources
|
||||
/// </summary>
|
||||
/// <param name="disposing">Currently disposing</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
//Close Connection (if available)
|
||||
_tcpStream?.Close();
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
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>
|
||||
/// Destructor
|
||||
/// </summary>
|
||||
~TempMonitorOmegaM3446()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open socket to the temperature sensor
|
||||
/// </summary>
|
||||
private void ConnectEthernet()
|
||||
{
|
||||
//Create and open a socket to temperature sensor
|
||||
TcpClient tempSocket = new TcpClient(_ipAddr, _port);
|
||||
_tcpStream = tempSocket.GetStream();
|
||||
_tcpStream.ReadTimeout = _READ_TIMEOUT;
|
||||
}
|
||||
/// <summary>
|
||||
/// Dispose of this object's resources
|
||||
/// </summary>
|
||||
/// <param name="disposing">Currently disposing</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
//Close Connection (if available)
|
||||
_tcpStream?.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open socket to the temperature sensor
|
||||
/// </summary>
|
||||
private void ConnectEthernet()
|
||||
{
|
||||
//Create and open a socket to temperature sensor
|
||||
TcpClient tempSocket = new TcpClient(_ipAddr, _port);
|
||||
_tcpStream = tempSocket.GetStream();
|
||||
_tcpStream.ReadTimeout = _READ_TIMEOUT;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the current version of software loaded on temperature sensor
|
||||
/// </summary>
|
||||
private void GetSoftwareVersion()
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
//Request the software version
|
||||
string rsp = SendMessageGetResponse(_VERSION);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Get the current version of software loaded on temperature sensor
|
||||
/// </summary>
|
||||
private void GetSoftwareVersion()
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
//Request the software version
|
||||
string rsp = SendMessageGetResponse(_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a command to the temperature sensor and request a response
|
||||
/// </summary>
|
||||
/// <param name="cmd">Command to send.</param>
|
||||
/// <returns>Response from the temperature sensor.</returns>
|
||||
private string SendMessageGetResponse(string cmd)
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
//Format the command before sending
|
||||
string commandString = cmd + _CARRIAGE_RTN;
|
||||
/// <summary>
|
||||
/// Send a command to the temperature sensor and request a response
|
||||
/// </summary>
|
||||
/// <param name="cmd">Command to send.</param>
|
||||
/// <returns>Response from the temperature sensor.</returns>
|
||||
private string SendMessageGetResponse(string cmd)
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
//Format the command before sending
|
||||
string commandString = cmd + _CARRIAGE_RTN;
|
||||
|
||||
//convert to byte array for sending
|
||||
byte[] commandBuffer = Encoding.ASCII.GetBytes(commandString);
|
||||
//convert to byte array for sending
|
||||
byte[] commandBuffer = Encoding.ASCII.GetBytes(commandString);
|
||||
|
||||
//send the data
|
||||
_tcpStream.Write(commandBuffer, 0, commandBuffer.Length);
|
||||
//send the data
|
||||
_tcpStream.Write(commandBuffer, 0, commandBuffer.Length);
|
||||
|
||||
//clear the buffer
|
||||
Array.Clear(_readBuffer, 0, _readBuffer.Length);
|
||||
//clear the buffer
|
||||
Array.Clear(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
//read from the response buffer
|
||||
int numBytesRead = _tcpStream.Read(_readBuffer, 0, _readBuffer.Length);
|
||||
//read from the response buffer
|
||||
int numBytesRead = _tcpStream.Read(_readBuffer, 0, _readBuffer.Length);
|
||||
|
||||
//convert response to a string
|
||||
string rspStr = Encoding.ASCII.GetString(_readBuffer);
|
||||
//convert response to a string
|
||||
string rspStr = Encoding.ASCII.GetString(_readBuffer);
|
||||
|
||||
//Check Response
|
||||
if (rspStr.Contains(_CARRIAGE_RTN))
|
||||
{
|
||||
char[] delimit = { '\r' };
|
||||
string[] parsed = rspStr.Split(delimit, StringSplitOptions.RemoveEmptyEntries);
|
||||
//Check Response
|
||||
if (rspStr.Contains(_CARRIAGE_RTN))
|
||||
{
|
||||
char[] delimit = { '\r' };
|
||||
string[] parsed = rspStr.Split(delimit, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
//Return parsed message
|
||||
return parsed[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Command message not successful");
|
||||
}
|
||||
}
|
||||
}
|
||||
//Return parsed message
|
||||
return parsed[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Command message not successful");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// TempMonitorOmegaM3446 factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public TempMonitorOmegaM3446(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
/// <summary>
|
||||
/// TempMonitorOmegaM3446 factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public TempMonitorOmegaM3446(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);
|
||||
|
||||
|
||||
_ipAddr = _configuration.GetConfigurationValue("TempMonitorOmegaM3446", "IpAddr", "");
|
||||
_port = _configuration.GetConfigurationValue("TempMonitorOmegaM3446", "Port", 0);
|
||||
_ipAddr = _configuration.GetConfigurationValue("TempMonitorOmegaM3446", "IpAddr", "");
|
||||
_port = _configuration.GetConfigurationValue("TempMonitorOmegaM3446", "Port", 0);
|
||||
|
||||
_readBuffer = new byte[_READ_BUFFER_SIZE];
|
||||
_readBuffer = new byte[_READ_BUFFER_SIZE];
|
||||
|
||||
//Connect to device
|
||||
ConnectEthernet();
|
||||
}
|
||||
//Connect to device
|
||||
ConnectEthernet();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the temperature sensor
|
||||
/// </summary>
|
||||
/// <param name="name">the name</param>
|
||||
/// <param name="ipAddress">IP Address of the equipment</param>
|
||||
/// <param name="port">Port of the equipment</param>
|
||||
public TempMonitorOmegaM3446(string name, string ipAddress, int port)
|
||||
{
|
||||
Name = name;
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_ipAddr = ipAddress;
|
||||
_port = port;
|
||||
/// <summary>
|
||||
/// Constructor for the temperature sensor
|
||||
/// </summary>
|
||||
/// <param name="deviceName">the name</param>
|
||||
/// <param name="ipAddress">IP Address of the equipment</param>
|
||||
/// <param name="port">Port of the equipment</param>
|
||||
public TempMonitorOmegaM3446(string deviceName, string ipAddress, int port)
|
||||
{
|
||||
Name = deviceName;
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
_ipAddr = ipAddress;
|
||||
_port = port;
|
||||
|
||||
//Initialize read buffer
|
||||
_readBuffer = new byte[_READ_BUFFER_SIZE];
|
||||
//Initialize read buffer
|
||||
_readBuffer = new byte[_READ_BUFFER_SIZE];
|
||||
|
||||
ConnectEthernet();
|
||||
}
|
||||
ConnectEthernet();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="comPortName"></param>
|
||||
/// <param name="delayBeforeReadMs"></param>
|
||||
/// <param name="baudRate"></param>
|
||||
/// <param name="parity"></param>
|
||||
/// <param name="dataBits"></param>
|
||||
/// <param name="stopBits"></param>
|
||||
public TempMonitorOmegaM3446(string name, string comPortName, uint delayBeforeReadMs, int baudRate = 115200, Parity parity = Parity.None, int dataBits = 8, StopBits stopBits = StopBits.One)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="comPortName"></param>
|
||||
/// <param name="delayBeforeReadMs"></param>
|
||||
/// <param name="baudRate"></param>
|
||||
/// <param name="parity"></param>
|
||||
/// <param name="dataBits"></param>
|
||||
/// <param name="stopBits"></param>
|
||||
public TempMonitorOmegaM3446(string name, string comPortName, uint delayBeforeReadMs, int baudRate = 115200, Parity parity = Parity.None, int dataBits = 8, StopBits stopBits = StopBits.One)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
// This code added to correctly implement the disposable pattern.
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
Dispose(true);
|
||||
// This code added to correctly implement the disposable pattern.
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
|
||||
public void Dispose()
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
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>
|
||||
/// Returns the current temperature read by temperature sensor
|
||||
/// </summary>
|
||||
/// <returns>The current Temperature reading</returns>
|
||||
public double ReadTemperature()
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
//Request current temp reading
|
||||
string rsp = SendMessageGetResponse(_TEMP);
|
||||
/// <summary>
|
||||
/// Returns the current temperature read by temperature sensor
|
||||
/// </summary>
|
||||
/// <returns>The current Temperature reading</returns>
|
||||
public double ReadTemperature()
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
//Request current temp reading
|
||||
string rsp = SendMessageGetResponse(_TEMP);
|
||||
|
||||
return double.Parse(rsp);
|
||||
}
|
||||
}
|
||||
return double.Parse(rsp);
|
||||
}
|
||||
}
|
||||
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void Initialize()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void Shutdown()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,71 +30,64 @@
|
||||
// DISTRIBUTION/DISSEMINATION CONTROL: F
|
||||
// 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 = "TempMonitorOmegaM3446Factory")]
|
||||
public class TempMonitorOmegaM3446Factory : 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 = "TempMonitorOmegaM3446Factory")]
|
||||
public class TempMonitorOmegaM3446Factory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public TempMonitorOmegaM3446Factory(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 TempMonitorOmegaM3446Factory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public TempMonitorOmegaM3446Factory(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>
|
||||
/// TempMonitorOmegaM3446Factory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public TempMonitorOmegaM3446Factory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
|
||||
_configurationManager = configManager ?? GetConfigurationManager();
|
||||
_supportedInterfaces.Add(typeof(ITempMonitor));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new TempMonitorOmegaM3446(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(ITempMonitor));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new TempMonitorOmegaM3446(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
@@ -105,12 +98,10 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
|
||||
if (simulateHw)
|
||||
return new TempMonitorSim(name, _configurationManager, _logger);
|
||||
return new TempMonitorSim(name, _configurationManager);
|
||||
else
|
||||
return new TempMonitorOmegaM3446(name, _configurationManager, _logger);
|
||||
return new TempMonitorOmegaM3446(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -123,17 +114,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,182 +22,145 @@ using Raytheon.Common;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// Temperature monitor class used to interact with the temperature sensor.
|
||||
/// </summary>
|
||||
public class TempMonitorSim : ITempMonitor
|
||||
{
|
||||
#region PrivateMembers
|
||||
/// <summary>
|
||||
/// Temperature monitor class used to interact with the temperature sensor.
|
||||
/// </summary>
|
||||
public class TempMonitorSim : ITempMonitor
|
||||
{
|
||||
#region PrivateMembers
|
||||
|
||||
private static object m_sync = new object();
|
||||
private object m_sync = new object();
|
||||
|
||||
/// <summary>
|
||||
/// NLog logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Raytheon configuration
|
||||
/// </summary>
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public string DetailedStatus => throw new NotImplementedException();
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public bool DisplayEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public bool FrontPanelEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public string DetailedStatus => throw new NotImplementedException();
|
||||
|
||||
public InstrumentMetadata Info => throw new NotImplementedException();
|
||||
public bool DisplayEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public bool FrontPanelEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public string Name { get; set; }
|
||||
public InstrumentMetadata Info => throw new NotImplementedException();
|
||||
|
||||
public SelfTestResult SelfTestResult => throw new NotImplementedException();
|
||||
public string Name { get; set; }
|
||||
|
||||
public State Status => throw new NotImplementedException();
|
||||
public SelfTestResult SelfTestResult => throw new NotImplementedException();
|
||||
|
||||
#endregion
|
||||
public State Status => throw new NotImplementedException();
|
||||
|
||||
#region PrivateFunctions
|
||||
/// <summary>
|
||||
/// Destructor
|
||||
/// </summary>
|
||||
~TempMonitorSim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object's resources
|
||||
/// </summary>
|
||||
/// <param name="disposing">Currently disposing</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
#region PrivateFunctions
|
||||
/// <summary>
|
||||
/// Destructor
|
||||
/// </summary>
|
||||
~TempMonitorSim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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's resources
|
||||
/// </summary>
|
||||
/// <param name="disposing">Currently disposing</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// TempMonitorSim factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public TempMonitorSim(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
/// <summary>
|
||||
/// TempMonitorSim factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public TempMonitorSim(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the temperature sensor
|
||||
/// </summary>
|
||||
/// <param name="name">the name</param>
|
||||
/// <param name="ipAddress">IP Address of the equipment</param>
|
||||
/// <param name="port">Port of the equipment</param>
|
||||
public TempMonitorSim(string name)
|
||||
{
|
||||
Name = name;
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructor for the temperature sensor
|
||||
/// </summary>
|
||||
/// <param name="deviceName">the name</param>
|
||||
/// <param name="ipAddress">IP Address of the equipment</param>
|
||||
/// <param name="port">Port of the equipment</param>
|
||||
public TempMonitorSim(string deviceName)
|
||||
{
|
||||
Name = deviceName;
|
||||
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
|
||||
}
|
||||
|
||||
|
||||
// This code added to correctly implement the disposable pattern.
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
Dispose(true);
|
||||
// This code added to correctly implement the disposable pattern.
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
|
||||
public void Dispose()
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
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>
|
||||
/// Returns the current temperature read by temperature sensor
|
||||
/// </summary>
|
||||
/// <returns>The current Temperature reading</returns>
|
||||
public double ReadTemperature()
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
double max = 20.0;
|
||||
/// <summary>
|
||||
/// Returns the current temperature read by temperature sensor
|
||||
/// </summary>
|
||||
/// <returns>The current Temperature reading</returns>
|
||||
public double ReadTemperature()
|
||||
{
|
||||
lock (m_sync)
|
||||
{
|
||||
double max = 20.0;
|
||||
|
||||
double min = 30.0;
|
||||
double min = 30.0;
|
||||
|
||||
Random rnd = new Random();
|
||||
Random rnd = new Random();
|
||||
|
||||
double seed = rnd.NextDouble();
|
||||
double seed = rnd.NextDouble();
|
||||
|
||||
double dataToReturn = (seed * (max - min)) + min;
|
||||
double dataToReturn = (seed * (max - min)) + min;
|
||||
|
||||
Thread.Sleep(100);
|
||||
Thread.Sleep(100);
|
||||
|
||||
return dataToReturn;
|
||||
}
|
||||
}
|
||||
return dataToReturn;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void Initialize()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public SelfTestResult PerformSelfTest()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void Shutdown()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,71 +30,64 @@
|
||||
// DISTRIBUTION/DISSEMINATION CONTROL: F
|
||||
// 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 = "TempMonitorSimFactory")]
|
||||
public class TempMonitorSimFactory : 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 = "TempMonitorSimFactory")]
|
||||
public class TempMonitorSimFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public TempMonitorSimFactory(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 TempMonitorSimFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public TempMonitorSimFactory(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>
|
||||
/// TempMonitorSimFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public TempMonitorSimFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
|
||||
_configurationManager = configManager ?? GetConfigurationManager();
|
||||
_supportedInterfaces.Add(typeof(ITempMonitor));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new TempMonitorSim(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(ITempMonitor));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new TempMonitorSim(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
@@ -105,9 +98,7 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
|
||||
return new TempMonitorSim(name, _configurationManager, _logger);
|
||||
return new TempMonitorSim(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -120,17 +111,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