diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..1ff0c42
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,63 @@
+###############################################################################
+# Set default behavior to automatically normalize line endings.
+###############################################################################
+* text=auto
+
+###############################################################################
+# Set default behavior for command prompt diff.
+#
+# This is need for earlier builds of msysgit that does not have it on by
+# default for csharp files.
+# Note: This is only used by command line
+###############################################################################
+#*.cs diff=csharp
+
+###############################################################################
+# Set the merge driver for project and solution files
+#
+# Merging from the command prompt will add diff markers to the files if there
+# are conflicts (Merging from VS is not affected by the settings below, in VS
+# the diff markers are never inserted). Diff markers may cause the following
+# file extensions to fail to load in VS. An alternative would be to treat
+# these files as binary and thus will always conflict and require user
+# intervention with every merge. To do so, just uncomment the entries below
+###############################################################################
+#*.sln merge=binary
+#*.csproj merge=binary
+#*.vbproj merge=binary
+#*.vcxproj merge=binary
+#*.vcproj merge=binary
+#*.dbproj merge=binary
+#*.fsproj merge=binary
+#*.lsproj merge=binary
+#*.wixproj merge=binary
+#*.modelproj merge=binary
+#*.sqlproj merge=binary
+#*.wwaproj merge=binary
+
+###############################################################################
+# behavior for image files
+#
+# image files are treated as binary by default.
+###############################################################################
+#*.jpg binary
+#*.png binary
+#*.gif binary
+
+###############################################################################
+# diff behavior for common document formats
+#
+# Convert binary document formats to text before diffing them. This feature
+# is only available from the command line. Turn it on by uncommenting the
+# entries below.
+###############################################################################
+#*.doc diff=astextplain
+#*.DOC diff=astextplain
+#*.docx diff=astextplain
+#*.DOCX diff=astextplain
+#*.dot diff=astextplain
+#*.DOT diff=astextplain
+#*.pdf diff=astextplain
+#*.PDF diff=astextplain
+#*.rtf diff=astextplain
+#*.RTF diff=astextplain
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bf72415
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,369 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+Source/TestStand/Reports
+Source/Nuget/cache/
+Source/Nuget/SolutionPackages
+
+Thumbs.db
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Oo]ut/
+[Ll]og/
+[Ll]ogs/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+#*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
\ No newline at end of file
diff --git a/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClient.cs b/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClient.cs
new file mode 100644
index 0000000..e8f6fbf
--- /dev/null
+++ b/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClient.cs
@@ -0,0 +1,299 @@
+/*-------------------------------------------------------------------------
+// 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 NLog;
+using Raytheon.Common;
+using System;
+using System.Net;
+using System.Net.NetworkInformation;
+using System.Net.Sockets;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Raytheon.Instruments.EthernetSockets
+{
+ ///
+ /// Class for controlling a TCP client communication device
+ ///
+ public class TcpClient : ICommDevice
+ {
+ #region PrivateClassMembers
+
+ private Socket _sock;
+ private string _remoteAddress;
+ private int _remotePort;
+ private IPEndPoint _remoteEP = null;
+ private IPAddress _ipAddress = null;
+ private object _syncObj = new object();
+
+ private readonly string _name;
+ private State _state;
+
+ ///
+ /// NLog logger
+ ///
+ private static ILogger _logger;
+ ///
+ /// Raytheon configuration
+ ///
+ private readonly IConfigurationManager _configurationManager;
+ private readonly IConfiguration _configuration;
+
+ #endregion
+
+ public bool ClearErrors() => false;
+ public bool FrontPanelEnabled { get => false; set => throw new NotImplementedException(); }
+ public bool DisplayEnabled { get => false; set => throw new NotImplementedException(); }
+ public string DetailedStatus => $"This is a TCP/IP Device called {_name}";
+ public InstrumentMetadata Info => throw new NotImplementedException();
+ public State Status => _state;
+ public string Name => _name;
+ public SelfTestResult PerformSelfTest() => SelfTestResult;
+ public SelfTestResult SelfTestResult => SelfTestResult.Unknown;
+ public void Open() => Initialize();
+ public void Close() => Disconnect();
+ public void Shutdown() => Disconnect();
+ public void Reset()
+ {
+ Close();
+ Open();
+ }
+
+ #region Public Functions
+
+ ///
+ /// CommDevice factory constructor
+ ///
+ ///
+ ///
+ public TcpClient(string deviceInstanceName, IConfigurationManager configurationManager, ILogger logger, string remoteAddress = "", int remotePort = 0)
+ {
+ _name = deviceInstanceName;
+
+ _state = State.Uninitialized;
+
+ _logger = logger;
+
+ _configurationManager = configurationManager;
+
+ // configuration obtained from [deviceInstanceName].xml file
+ _configuration = _configurationManager.GetConfiguration(Name);
+
+ if (string.IsNullOrEmpty(remoteAddress))
+ {
+ _remoteAddress = _configuration.GetConfigurationValue(deviceInstanceName, TcpClientConfigXml.REMOTE_ADDRESS.ToString(), "127.0.0.1");
+ }
+ else
+ {
+ _remoteAddress = remoteAddress;
+ }
+
+ if (remotePort == 0)
+ {
+ _remotePort = _configuration.GetConfigurationValue(deviceInstanceName, TcpClientConfigXml.REMOTE_PORT.ToString(), 0);
+ }
+ else
+ {
+ _remotePort = remotePort;
+ }
+ }
+
+ ///
+ /// Constructor
+ ///
+ ///
+ ///
+ public TcpClient(string remoteAddress, int remotePort)
+ {
+ _remoteAddress = remoteAddress;
+ _remotePort = remotePort;
+ }
+
+ ///
+ /// initialize instrument
+ ///
+ public void Initialize()
+ {
+ // if remoteAddress is a hostname
+ if (!IPAddress.TryParse(_remoteAddress, out _ipAddress))
+ {
+ string preferredSubnet = "";
+
+ IPHostEntry host = Dns.GetHostEntry(_remoteAddress);
+ foreach (IPAddress ip in host.AddressList)
+ {
+ AddressFamily af = ip.AddressFamily;
+ if (af == AddressFamily.InterNetwork)
+ {
+ if (preferredSubnet != String.Empty)
+ {
+ if (Regex.IsMatch(ip.ToString(), preferredSubnet, RegexOptions.IgnoreCase))
+ _ipAddress = ip;
+ }
+ else
+ _ipAddress = ip;
+
+ if (_ipAddress != null)
+ break;
+ }
+ }
+ }
+
+ if (_ipAddress != null)
+ {
+ if (_remoteEP == null)
+ _remoteEP = new IPEndPoint(_ipAddress, _remotePort);
+ }
+ else
+ throw new Exception($"Unable to create IPEndPoint to {_remoteAddress}, port {_remotePort}");
+
+ if (_sock == null)
+ _sock = new Socket(_ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+ }
+
+ ///
+ /// Connect to remote host
+ ///
+ ///
+ public void Connect()
+ {
+ lock (_syncObj)
+ {
+ try
+ {
+ if (!_sock.Connected && IsRemoteHostAlive())
+ _sock.Connect(_remoteEP);
+ }
+ catch (ObjectDisposedException)
+ {
+ _sock = new Socket(_ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+ if (IsRemoteHostAlive())
+ _sock.Connect(_remoteEP);
+ }
+ catch (Exception) { throw; }
+ }
+ }
+
+ ///
+ /// Disconnect from remote host
+ ///
+ ///
+ public void Disconnect()
+ {
+ lock (_syncObj)
+ {
+ if (_sock.Connected)
+ {
+ _sock.Shutdown(SocketShutdown.Both);
+ _sock.Disconnect(true);
+ _sock.Close();
+ }
+ }
+ }
+
+ ///
+ /// Ping if remote host is alive
+ ///
+ /// true/false
+ bool IsRemoteHostAlive()
+ {
+ bool isRemoteHostAlive = true;
+
+ //Do a ping test to see if the server is reachable
+ try
+ {
+ Ping pingTest = new Ping();
+ PingReply reply = pingTest.Send(_ipAddress);
+ if (reply.Status != IPStatus.Success)
+ isRemoteHostAlive = false;
+ }
+ catch (PingException)
+ {
+ isRemoteHostAlive = false;
+ }
+
+ //See if the tcp state is ok
+ if (_sock.Poll(5000, SelectMode.SelectRead) && (_sock.Available == 0))
+ {
+ isRemoteHostAlive = false;
+ }
+
+ return isRemoteHostAlive;
+ }
+
+ ///
+ /// Read data from the device.
+ ///
+ ///
+ ///
+ /// The number of bytes read
+ public uint Read(ref byte[] dataBuf)
+ {
+ int bytesRec = 0;
+ lock (_syncObj)
+ {
+ try
+ {
+ bytesRec = _sock.Receive(dataBuf);
+ }
+ catch (SocketException)
+ {
+ bytesRec = 0;
+ }
+ }
+
+ return (uint)bytesRec;
+ }
+
+ ///
+ /// Sets the read timeout
+ ///
+ ///
+ public void SetReadTimeout(uint timeoutMs)
+ {
+ _sock.ReceiveTimeout = (int)timeoutMs;
+ }
+
+ ///
+ /// Write data to device.
+ ///
+ ///
+ /// The number of bytes written
+ public uint Write(byte[] dataBuf, uint numBytesToWrite)
+ {
+ int bytesWritten = 0;
+ lock (_syncObj)
+ {
+ try
+ {
+ bytesWritten = _sock.Send(dataBuf, (int)numBytesToWrite, SocketFlags.None);
+ }
+ catch (SocketException)
+ {
+ bytesWritten = 0;
+ }
+ }
+
+ return (uint)bytesWritten;
+ }
+
+ #endregion
+ }
+}
diff --git a/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClient.csproj b/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClient.csproj
new file mode 100644
index 0000000..fb157c4
--- /dev/null
+++ b/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClient.csproj
@@ -0,0 +1,33 @@
+
+
+
+
+ net472
+ Library
+ Raytheon.Instruments.EthernetSockets.TcpClient
+ Raytheon.Instruments
+ CommDevice TCP implementation
+ CommDevice TCP implementation
+ true
+ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
+ Raytheon Technologies
+ TEEC
+ Copyright © Raytheon Technologies $([System.DateTime]::get_now().ToString("yyyy"))
+
+
+
+
+
+ 1.0.0
+ Debug;Release;Deploy
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClientConfigXml.cs b/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClientConfigXml.cs
new file mode 100644
index 0000000..a7f3f0d
--- /dev/null
+++ b/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClientConfigXml.cs
@@ -0,0 +1,32 @@
+/*-------------------------------------------------------------------------
+// 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 System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Raytheon.Instruments.EthernetSockets
+{
+ public enum TcpClientConfigXml
+ {
+ // List all the keys here
+ REMOTE_ADDRESS,
+ REMOTE_PORT
+ }
+}
diff --git a/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClientFactory.cs b/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClientFactory.cs
new file mode 100644
index 0000000..74411ff
--- /dev/null
+++ b/Source/Instruments/EthernetSockets/CommDeviceTcpClient/TcpClientFactory.cs
@@ -0,0 +1,122 @@
+/*-------------------------------------------------------------------------
+// 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 NLog;
+using Raytheon.Common;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.IO;
+using System.Reflection;
+
+namespace Raytheon.Instruments.EthernetSockets
+{
+ [ExportInstrumentFactory(ModelNumber = "EthernetSocketsTcpClientFactory")]
+ public class TcpClientFactory : IInstrumentFactory
+ {
+ ///
+ /// The supported interfaces
+ ///
+ private readonly List _supportedInterfaces = new List();
+ private static ILogger _logger;
+ private readonly IConfigurationManager _configurationManager;
+ private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
+ private static string DefaultPath;
+
+ public TcpClientFactory(string defaultConfigPath = DefaultConfigPath)
+ : this(null, defaultConfigPath)
+ {
+ }
+
+ ///
+ /// COECommDeviceInstrumentFactory injection constructor
+ ///
+ ///
+ ///
+ ///
+ [ImportingConstructor]
+ public TcpClientFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
+ [Import(AllowDefault = true)] string defaultConfigPath = null)
+ {
+ DefaultPath = defaultConfigPath;
+ _logger = LogManager.GetCurrentClassLogger();
+
+ if (NLog.LogManager.Configuration == null)
+ {
+ var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+ NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
+ }
+
+ _configurationManager = configManager ?? GetConfigurationManager();
+ _supportedInterfaces.Add(typeof(ICommDevice));
+ }
+
+ ///
+ /// Gets the instrument
+ ///
+ ///
+ ///
+ public IInstrument GetInstrument(string name)
+ {
+ try
+ {
+ return new TcpClient(name, _configurationManager, _logger);
+ }
+ catch (Exception ex)
+ {
+ _logger.Error(ex, $"Unable to construct {name} instrument instance");
+ return null;
+ }
+ }
+
+ ///
+ /// Gets the instrument
+ ///
+ ///
+ ///
+ public object GetInstrument(string name, bool simulateHw)
+ {
+ try
+ {
+ return new TcpClient(name, _configurationManager, _logger);
+ }
+ catch (Exception ex)
+ {
+ _logger.Error(ex, $"Unable to construct {name} instrument instance");
+ return null;
+ }
+ }
+
+ ///
+ /// Gets supported interfaces
+ ///
+ ///
+ public ICollection GetSupportedInterfaces()
+ {
+ return _supportedInterfaces.ToArray();
+ }
+
+ ///
+ /// returns confiuration based on the predefined path or default path c:/ProgramData/Raytheon/InstrumentManagerService
+ ///
+ ///
+ private static IConfigurationManager GetConfigurationManager()
+ {
+ return string.IsNullOrEmpty(DefaultPath) ? new RaytheonConfigurationManager() : new RaytheonConfigurationManager(DefaultPath);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Source/Instruments/GeneralIntsrumentManager/GeneralInstrumentManager.cs b/Source/Instruments/GeneralIntsrumentManager/GeneralInstrumentManager.cs
new file mode 100644
index 0000000..bba565b
--- /dev/null
+++ b/Source/Instruments/GeneralIntsrumentManager/GeneralInstrumentManager.cs
@@ -0,0 +1,878 @@
+/*-------------------------------------------------------------------------
+// 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 System.Collections.Generic;
+using System.ComponentModel.Composition;
+using Raytheon.Communication;
+using Raytheon.Communication.Rpc;
+using Raytheon.Logging;
+using Raytheon.Composition;
+using Raytheon.Common;
+using System.Xml.Linq;
+using Microsoft.Win32;
+using System.IO;
+using System.ServiceProcess;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Collections.ObjectModel;
+using System.Reflection;
+using System.IO.Ports;
+
+namespace Raytheon.Instruments
+{
+ public enum Mode
+ {
+ ///
+ /// instruments must be managed by the service (like RINSS)
+ ///
+ Service,
+ ///
+ /// ignore the service and initialize instruments directly
+ ///
+ StandAlone,
+ ///
+ /// dynamically identify if instrument service is running
+ ///
+ Auto
+ }
+
+ ///
+ /// hybrid implementation of the instrument manager interface
+ /// will check if
+ ///
+ public class GeneralInstrumentManager : IInstrumentManager, IPartImportsSatisfiedNotification
+ {
+ #region Private Fields
+
+ private readonly bool _haveService;
+
+ private IUms _umsHost;
+ private IUmsClient _instrumentManager;
+ private IUmsClient _rpcInstrumentManagerHost;
+
+ private bool _partsLoaded { get; set; }
+
+ ///
+ /// PartsLocation - where the instrument manager should get it's MEF components
+ ///
+ public string _partsLocation { get; set; }
+ ///
+ /// ConfigLocation - where the configuration manager stores config files
+ /// specifically Instruments.xml
+ ///
+ public string _configLocation { get; set; }
+
+ private List _availableInstruments = new List();
+ private readonly Dictionary _factoryMap = new Dictionary();
+
+ private readonly Dictionary _instruments = new Dictionary();
+ private readonly HashSet _instrumentTypes = new HashSet();
+
+ // simulation
+ private readonly bool _isThereHardware;
+
+ #endregion
+
+ #region Constants
+
+ private const string NO_SERVER = "Client for communication to the server has not been setup";
+ private const string SECTION = "RpcClient";
+
+ private const string RegistryValue = @"ConsumerInstrumentManagerPartsDirectory";
+
+ private const string RegistryValueNoRINSS = @"InstrumentManagerPartsDirectory";
+
+ private const string RegistryKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Raytheon";
+
+ private const string DefaultName = "Default";
+ private const string DefaultIP = "127.0.0.1";
+ private const string DefaultPort = "8006";
+ private const string DefaultMedia = "Tcp";
+ private const string DefaultSerializer = "Fusion";
+
+ #endregion
+
+ #region Imports
+
+ [ImportMany(typeof(IInstrumentFactory))]
+ private Lazy[] InstrumentFactories { get; set; }
+
+ [Import(typeof(IUmsFactory))]
+ private Lazy LazyUmsFactory { get; set; }
+ private IUmsFactory UmsFactory { get { return LazyUmsFactory?.Value; } }
+
+ [Import(typeof(IConfigurationManager))]
+ private Lazy LazyConfigManager { get; set; }
+ private IConfigurationManager ConfigManager { get { return LazyConfigManager?.Value; } }
+
+ [Import(typeof(IUmsClientFactory))]
+ private Lazy LazyUmsClientFactory { get; set; }
+ private IUmsClientFactory UmsClientFactory { get { return LazyUmsClientFactory?.Value; } }
+
+ [Import(typeof(ILogFactory), AllowDefault = true)]
+ private Lazy LazyLogFactory { get; set; }
+ private ILogFactory LogFactory { get { return LazyLogFactory?.Value; } }
+
+
+ [ImportMany(typeof(IInstrumentProxyFactory))]
+ private Lazy[] ProxyFactories { get; set; }
+
+ #endregion
+
+ #region Logging
+ private static ILogger _logger;
+
+ private static ILogger GetLogger()
+ {
+ FusionLogManager.Changed += l => _logger = l.GetLogger();
+ return _logger;
+ }
+ #endregion
+
+ ///
+ /// default constructor
+ /// in Auto mode the Instrument Manager will use RINSS based on the service running status
+ /// in Service mode the Instrument Manager must have the RINSS Service running
+ /// in StandAlone mode the Instrument Manager will ignore RINSS
+ ///
+ public GeneralInstrumentManager(Mode mode = Mode.Auto)
+ {
+ _haveService = CheckServiceRunningStatus("RINSS");
+ if (mode == Mode.Service && !_haveService)
+ {
+ throw new Exception("RINSS Service is not running for Service mode");
+ }
+
+ if (mode == Mode.StandAlone)
+ {
+ _haveService = false;
+ }
+
+ _logger = GetLogger();
+ }
+
+ ///
+ /// constructor to be used when no RINSS available to set parts location
+ ///
+ ///
+ public GeneralInstrumentManager(string partsLocation, Mode mode = Mode.Auto)
+ : this(mode)
+ {
+ _partsLocation = partsLocation;
+ }
+
+ ///
+ /// constructor to be used when no RINSS available to set parts location and configuration location
+ ///
+ ///
+ ///
+ ///
+ public GeneralInstrumentManager(string partsLocation, string configLocation, bool isThereHardware = true, Mode mode = Mode.Auto)
+ : this(partsLocation, mode)
+ {
+ _configLocation= configLocation;
+ _isThereHardware = isThereHardware;
+
+ }
+
+ ///
+ /// Initializes this instance.
+ ///
+ public void Initialize()
+ {
+ try
+ {
+ //Setup the instrument part path
+ if (!string.IsNullOrWhiteSpace(_partsLocation) && !Directory.Exists(_partsLocation))
+ {
+ _logger.Error($"Unable to id parts in this location: {_partsLocation}");
+ _partsLocation = string.Empty;
+ }
+
+ SetupPath();
+
+ //load the instruments
+ if (!_partsLoaded)
+ {
+ LoadParts();
+ }
+
+ if(_haveService)
+ {
+ // 1. Create the Ums Client
+ CreateUmsClient();
+ _logger.Debug("created client");
+
+ // 2. Find out what instruments are available
+ _availableInstruments = new List(_rpcInstrumentManagerHost.Contract.EnumRpcInstruments());
+ _logger.Debug("geting list of availible instruments");
+
+ // 3. Find all the instrument interfaces supported by proxy factories
+ InitializeFactories();
+ _logger.Debug("initialized all the factories");
+ }
+ else
+ {
+ //configure all the instruments found
+ ConfigureInstruments();
+ }
+ }
+ catch (CompositionException ex)
+ {
+ _logger.ErrorException(ex, "Error in composition during Consumer Instrument Manager initialization");
+ throw;
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException(ex, "Error initializing the instrument manager");
+ throw;
+ }
+ }
+
+ ///
+ /// InitializeInstruments - init all the instruments
+ ///
+ public void InitializeInstruments()
+ {
+ _logger.Info("Instrument initialization complete");
+ }
+
+ ///
+ /// InitializeInstrument - inits a specific instrument
+ ///
+ /// instrument's unique name
+ public void InitializeInstrument(string instName)
+ {
+ }
+
+ ///
+ /// implementation for IPartImportsSatisfiedNotification interface
+ ///
+ public void OnImportsSatisfied()
+ {
+ if (LogFactory != null && LogFactory != null)
+ {
+ FusionLogManager.Current = LogFactory;
+ }
+ }
+
+ ///
+ /// Gets the generic instrument.
+ ///
+ /// The name.
+ ///
+ public IInstrument GetGenericInstrument(string name)
+ {
+ _logger.Trace("In ConsumerInstrumentManager in method GetGenericInstrument with name: {0} ", name);
+ return GetInstrument(name);
+ }
+
+ ///
+ /// gets a specific instrument by name
+ /// the name should match one of the names in Instruments.xml file
+ ///
+ ///
+ ///
+ ///
+ public T GetInstrument(string name) where T : class
+ {
+ _logger.Trace($"Starting GetInstrument with name: {name}");
+
+ object inst = null;
+ if (_haveService)
+ {
+ try
+ {
+ string interfaceName = typeof(T).FullName;
+ if (typeof(IInstrument).FullName == interfaceName)
+ {
+ _logger.Trace($"GetInstrument with typeof(IInstrument).FullName == interfaceName: {interfaceName}");
+
+ //get the real interface behind the scenes
+ //first find the appropriate factory
+ RpcInstrumentDescriptor correctDesc = _availableInstruments.FirstOrDefault((desc) => 0 == string.Compare(name, desc.InstrumentName, true));
+ if (null != correctDesc)
+ {
+ _logger.Trace($"GetInstrument with correctDesc.name: {correctDesc.InstrumentName}");
+
+ string temp = correctDesc.InstrumentInterfaces.FirstOrDefault();
+ if (!string.IsNullOrWhiteSpace(temp))
+ {
+ interfaceName = temp;
+ }
+ }
+
+ _logger.Debug("Requested generic instrument, found {0} to be the correct interface", interfaceName);
+ }
+
+ if (InstrumentIsAvailable(name) && FactoryIsAvailable(interfaceName))
+ {
+ _logger.Trace($"GetInstrument with InstrumentIsAvailable(name) && FactoryIsAvailable(interfaceName) name: {name}, interfaceName: {interfaceName}");
+
+ IInstrumentProxyFactory factory = _factoryMap.Where((t) => 0 == string.Compare(t.Key, interfaceName, true))
+ .Select(t => t.Value)
+ .FirstOrDefault();
+
+ if (null != factory)
+ {
+ inst = factory.GetInstrument(name);
+ _logger.Trace($"GetInstrument got an instrument (name: {name}) from factory: {factory}, interfaceName: {interfaceName}");
+ }
+ else
+ {
+ _logger.Warn($"Could not find factory for interface: {interfaceName}, instrument: {name}");
+ }
+ }
+ }
+ catch (InstrumentException ex)
+ {
+ _logger.WarnException(ex, ex.Message);
+ }
+ }
+ else
+ {
+ _instruments.TryGetValue(name.ToLower(), out inst);
+ }
+
+ _logger.Trace($"GetInstrument returning with inst: {inst}");
+
+ return inst as T;
+ }
+
+ ///
+ /// returns a collection of instrument names
+ ///
+ ///
+ public ICollection GetInstrumentNames()
+ {
+ _logger.Trace("Returning instrument list");
+
+ if (_haveService)
+ {
+ return _instrumentManager.Contract.GetInstrumentNames();
+ }
+ else
+ {
+ return new ReadOnlyCollection(_instruments.Keys.ToList());
+ }
+ }
+
+ public string[] GetInstrumentNamesArray()
+ {
+ _logger.Debug("Getting Instrument Names Array");
+ return GetInstrumentNames().ToArray();
+ }
+
+ ///
+ /// Gets instruments collection
+ ///
+ ///
+ public ICollection