Big changes

This commit is contained in:
Duc
2025-03-13 12:04:22 -07:00
parent c689fcb7f9
commit ffa9905494
748 changed files with 199255 additions and 3743 deletions

View File

@@ -0,0 +1,913 @@
//>>***************************************************************************
// UNCLASSIFIED
//
// COPYRIGHT 2017 RAYTHEON MISSILE SYSTEMS
// ALL RIGHTS RESERVED
// This data was developed pursuant to Contract Number HQ0147-12-C-0004/1088370
// with the US Government. The US Government's rights in and to this
// copyrighted data are as specified in DFAR 252.227-7013
// which was made part of the above contract.
//
// Distribution Statement: D -Distribution authorized to the DoD and DoD
// contractors only based on Critical Technology Requirements, May 2001.
// Other requests shall be referred to PEO THEATER AIR DEFENSE (PMS 422).
// Warning: - This document contains technical data whose export is restricted
// by the Arms Export Control Act (Title 22, U.S.C.) or Export
// Administration Act of 1979, as amended (Title 50, U.S.C.). Violations
// of these laws are subject to severe criminal penalties. Disseminate in
// accordance with provisions of DoD 5230.25.
// Destruction Notice: - For unclassified, limited distribution information,
// destroy by any method that will prevent disclosure of contents or
// reconstruction of the document. Classified information, destroy in
// 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 System.Threading;
namespace Raytheon.Instruments
{
/// <summary>
/// A class for controlling a scope via scpi commands
/// </summary>
public class ScopeKeysightScpi : IOscilloScope
{
#region PublicMembers
#endregion
#region PrivateMembers
/*private enum SourceType
{
CHANNEL,
FUNCTION
}*/
// if other commands are needed http://www.keysight.com/upload/cmc_upload/All/Infiniium_prog_guide.pdf pg 770
private const string m_SUBTRACTFUNC = ":SUBT ";
private const string m_MEASFALLCMD = ":MEAS:FALL? ";
private const string m_MEASRISCMD = ":MEAS:RISetime? ";
private const string m_MEASVTIMCMD = ":MEAS:VTIM? ";
private const string _READ_ERROR_CODE_CMD = "SYST:ERR?";
private const string m_MEASFREQCMD = ":MEAS:FREQ? ";
private const string m_SINGLECMD = ":SINGle";
private const string m_STOPCMD = ":STOP";
private const string m_RUNCMD = ":RUN";
private const string m_RESETCMD = "*RST";
//private const string m_ISOPCCMD = "*OPC? ";
private const string m_ISITCOMPLETEDCMD = ":TER? ";
private const string m_SELFTESTCMD = "*TST? ";
private const string m_COLON = ":";
private const string m_COMMA = ",";
private const string m_QUESTMARK = "?";
private const string m_SPACE = " ";
private const string m_SLASH = "\\";
private const string m_DOUBLESLASH = "\\\\";
private const string m_DOUBLEQUOTES = "\"";
// Turn Headers Off when Returning Values to Numeric Variables
private const string m_SYSHEADEROFFCMD = ":SYST:HEAD OFF";
private const string m_ANALAEDGCMD = ":ANALyze:AEDGes ";
private const string m_ANALASIGTYPECMD = ":ANALyze:SIGNal:TYPE";
private const string m_ANALASIGTYPE_OPTION = "PAM4";
private const string m_CHANCMD = "CHAN";
private const string m_FUNCCMD = "FUNC";
private const string m_CHANDISPCMD = ":DISP ";
private const string m_CHANINPUTCMD = ":INP ";
private const string m_INPUTIMPEDANCECMD = "DC";
private const string m_TIMESCALECMD = ":TIM:SCAL ";
private const string m_TIMEOFFSETCMD = ":TIM:POS ";
private const string m_TRIGSRCCMD = ":TRIG:EDGE:SOUR ";
private const string m_TRIGLEVCMD = ":TRIG:LEV ";
private const string m_RISETRIGEDGESELCMD = ":TRIG:EDGE:SLOP POS";
private const string m_FALLTRIGEDGESELCMD = ":TRIG:EDGE:SLOP NEG";
private const string m_VOLTPERDIVCMD = ":SCAL ";
private const string m_VOLTOFFSETCMD = ":OFFS ";
// The :MEASure:CLEar command clears the measurement results from the screen
// and disables all previously enabled measurements.
private const string m_MEASCLEARCMD = ":MEAS:CLE";
private const string m_MEASDELTCMD = ":MEAS:DELT";
private const string m_MEASDELTDEFCMD = ":MEAS:DELT:DEF";
private const string m_MEASSOURCMD = ":MEAS:SOUR";
// These threshold settings in voltages are used for rise/fall measurements.
private const string m_MEASTHRRFALABSCMD = ":MEAS:THR:RFAL:ABS";
private const string m_MEASTHRGENABSCMD = ":MEAS:THR:GEN:ABS";
private const string m_MEASTHRGENMETHCMD = ":MEAS:THR:GEN:METH";
private const string m_MEASTHRGENTOPBABSCMD = ":MEAS:THR:GEN:TOPB:ABS";
private const string m_MEASTHRGENTOPBABS_OPTION = "5.0,1.0";
private const string m_MEASTHRGENTOPBMETHCMD = ":MEAS:THR:GEN:TOPB:METH";
// The :MEASure:PWIDth command measures the width of the first positive pulse on the screen
// using the mid-threshold levels of the waveform(50% levels with standard measurements selected).
private const string m_MEASPWIDCMD = ":MEAS:PWID? ";
private const string m_MEASTHRMETH_OPTION = "ABS";
// Trigger sweep
private const string m_ISTRIGGEREDCMD = ":TRIG:SWE? ";
private const string m_TRIGGERCMD = ":TRIG:SWE ";
private const string m_TRIGGER_OPTION = "TRIG";
// ON or OFF
private const string m_OPTION_ON = "ON";
private const string m_OPTION_OFF = "OFF";
private const string m_IMAGE_DEST = @"\Users\Public\Documents";
private const string m_DESIRED_FOLDER = @"\Scope_Measurements";
private const string m_IMAGE_FORMAT = "GIF";
private const string m_IMAGE_SOURCE = "SCR";
private const string m_SAVEIMAGECMD = ":DISK:SAVE:IMAGe ";
// Maximum number of channels provided by scope.
private const int m_MAXNUMOFCHANN = 4;
private const int m_READ_TIMEOUT = 5000;
private readonly string _address;
private byte[] _readBuffer;
private NetworkStream _tcpStream;
private State _state;
private SelfTestResult _selfTestResult;
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>
/// The Finalizer which will release resources if required
/// </summary>
~ScopeKeysightScpi()
{
Dispose(false);
}
/// <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>
/// Dispose of this object
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
try
{
if (disposing)
{
if (_state == State.Ready)
{
Reset();
_tcpStream.Close();
_tcpStream.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>
/// Get the error code.
/// </summary>
/// <param name="errorCode">The error code.</param>
/// <returns>The error description.</returns>
private string GetErrorCode(out int errorCode)
{
// not calling IOQuery() here so IOQuery() can call GetErrorCode() after each query
string command = _READ_ERROR_CODE_CMD + "\n";
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(',');
errorCode = Util.ConvertStringToInt32(tokens[0]);
// it should always be 2
if (tokens.Length >= 2)
{
return tokens[1];
}
else
{
return "";
}
}
/// <summary>
///
/// </summary>
/// <param name="statusString"></param>
/// <param name="expectedResult"></param>
/// <returns></returns>
private bool IsOperationCompleted(string statusString, string expectedResult = "1")
{
bool completed = false;
// If Scope returns '+x' instead of 'x', where 'x' is any character, trim it.
if (statusString.IndexOf('+') == 0)
{
statusString = statusString.TrimStart('+');
}
if (statusString.Equals(expectedResult) == true)
{
completed = true;
}
return completed;
}
#endregion
#region PublicFunctions
/// <summary>
/// ScopeKeysightScpi factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public ScopeKeysightScpi(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
_logger = logger;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_address = _configuration.GetConfigurationValue("ScopeKeysightScpi", "Address", "");
int port = _configuration.GetConfigurationValue("ScopeKeysightScpi", "Port", 0);
const int READ_BUFFER_SIZE = 512;
_readBuffer = new byte[READ_BUFFER_SIZE];
TcpClient scopeSocketConn = new TcpClient(_address, port);
_tcpStream = scopeSocketConn.GetStream();
_tcpStream.ReadTimeout = m_READ_TIMEOUT;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="address"></param>
public ScopeKeysightScpi(string name, string address, int port)
{
const int READ_BUFFER_SIZE = 512;
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_address = address;
_readBuffer = new byte[READ_BUFFER_SIZE];
TcpClient scopeSocketConn = new TcpClient(_address, port);
_tcpStream = scopeSocketConn.GetStream();
_tcpStream.ReadTimeout = m_READ_TIMEOUT;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="channelNumber"></param>
/// <param name="timePerDivison"></param>
/// <param name="timeOffset"></param>
/// <param name="voltageOffset"></param>
/// <param name="voltageScale"></param>
/// <param name="inputImpedance"></param>
public void ConfigureChannel(int channelNumber, double timePerDivison, double timeOffset, double voltageOffset, double voltageScale, string inputImpedance)
{
// make sure it is stopped first
string command = m_STOPCMD + "\n";
IOWrite(command);
/*command = m_ISOPCCMD + "\n";
string rspStr = IOQuery(command);
string[] tokens = rspStr.Split('\n');
// check to see if STOP was completed.
if (IsOperationCompleted(tokens[0]) == false)
{
throw new Exception("STOP was not completed.");
}*/
// clear the measurement
command = m_MEASCLEARCMD + "\n";
IOWrite(command);
//1. time per division
command = m_TIMESCALECMD + timePerDivison.ToString() + "\n";
IOWrite(command);
//2. time offset
command = m_TIMEOFFSETCMD + timeOffset.ToString() + "\n";
IOWrite(command);
//3. Volt per division
command = m_COLON + m_CHANCMD + channelNumber.ToString() + m_VOLTPERDIVCMD + voltageScale.ToString() + "\n";
IOWrite(command);
//4. Volt offset
command = m_COLON + m_CHANCMD + channelNumber.ToString() + m_VOLTOFFSETCMD + voltageOffset.ToString() + "\n";
IOWrite(command);
// It sets input impedance to 1M ohmns.
// The value of inputImpedance is expected to be "DC", equivalent to 1M ohmn; otherwise, it outputs error.
if (inputImpedance.ToUpper().Trim() != m_INPUTIMPEDANCECMD.ToUpper())
{
throw new Exception("ScopeSetupChannel() expected inputImpedance to be DC.");
}
command = m_COLON + m_CHANCMD + channelNumber.ToString() + m_CHANINPUTCMD + inputImpedance + "\n";
IOWrite(command);
// It turns on the specified channel.
command = m_COLON + m_CHANCMD + channelNumber.ToString() + m_CHANDISPCMD + m_OPTION_ON + "\n";
IOWrite(command);
// start it back up
command = m_RUNCMD + "\n";
IOWrite(command);
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a Scpi Scope";
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
/// Dispose of this objects 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 bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool HasItTriggered()
{
// Check the Trigger Event register to see if the event has properly triggered
string command = m_ISITCOMPLETEDCMD + "\n";
//string command = m_ISTRIGGEREDCMD + "\n";
string rspStr = IOQuery(command);
bool isTriggered = false;
string[] tokens = rspStr.Split('\n');
// check to see if it is triggered.
if (IsOperationCompleted(tokens[0]) == true)
{
isTriggered = true;
}
return isTriggered;
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
// if we have not yet been initialized, go ahead and create the socket
if (_state == State.Uninitialized)
{
Reset();
// we already connected to the instrument in the constructor
_state = State.Ready;
}
else
{
throw new Exception("expected the state of System " + _name + " to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
public string IOQuery(string command)
{
// send the command
IOWrite(command, false);
// 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 = 0;
string errorMessage = GetErrorCode(out err);
if (err != 0)
{
throw new Exception("ScopeKeysightScpi:IOQuery() - Scope " + _name + " returned error code: " + err.ToString() + "," + errorMessage);
}
return rspStr;
}
/// <summary>
///
/// </summary>
/// <param name="command"></param>
public void IOWrite(string command, bool shallWeCheckForError = true)
{
// convert to a byte array
byte[] commandBuffer = Encoding.ASCII.GetBytes(command);
// send the data out
_tcpStream.Write(commandBuffer, 0, commandBuffer.Length);
// check for errors
if (shallWeCheckForError == true)
{
int err = 0;
string errorMessage = GetErrorCode(out err);
if (err != 0)
{
throw new Exception("ScopeKeysightScpi:IOWrite() - Scope " + _name + " returned error code: " + err.ToString() + "," + errorMessage);
}
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureFallTime(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="channelNumber"></param>
/// <returns></returns>
public double MeasureFrequency(int channelNumber)
{
// turn off system header
string command = m_SYSHEADEROFFCMD + "\n";
IOWrite(command);
// send the command to read the data
command = m_MEASFREQCMD + m_CHANCMD + channelNumber.ToString() + "\n";
string rspStr = IOQuery(command);
string[] tokens = rspStr.Split('\n');
double freq = Util.ConvertStringToDouble(tokens[0]);
return freq;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureMaxVoltage(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureMinVoltage(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasurePulseWidth(int channelNumber)
{
// turn off system header
string command = m_SYSHEADEROFFCMD + "\n";
IOWrite(command);
// send the command to read the data
command = m_MEASPWIDCMD + m_CHANCMD + channelNumber.ToString() + "\n";
string rspStr = IOQuery(command);
string[] tokens = rspStr.Split('\n');
double pulseWidth = Util.ConvertStringToDouble(tokens[0]);
return pulseWidth;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureRiseTime(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureVoltageLevel(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
try
{
// change the timeout to account for the long self test
_tcpStream.ReadTimeout = 90000;
// send the command and get the response
string command = m_SELFTESTCMD + "\n";
string rspStr = IOQuery(command);
// parse the response
string[] tokens = rspStr.Split('\n');
//Check if self test is completed; returns status of "0".
if (IsOperationCompleted(tokens[0], "0") == false)
{
_selfTestResult = SelfTestResult.Fail;
string errorMsg = "System " + _name + " returned an error: " + tokens[0];
throw new Exception(errorMsg);
}
else
{
_selfTestResult = SelfTestResult.Pass;
}
return _selfTestResult;
}
catch (Exception)
{
throw;
}
finally
{
// restore the timeout
_tcpStream.ReadTimeout = m_READ_TIMEOUT;
}
}
/// <summary>
///
/// </summary>
public void Reset()
{
// Resets the oscilloscope
string command = m_RESETCMD + "\n";
IOWrite(command);
// just a swag
Thread.Sleep(3000);
/*command = m_ISOPCCMD + "\n";
string rspStr = IOQuery(command);
// parse the response
string[] tokens = rspStr.Split('\n');
if (IsOperationCompleted(tokens[0]) == false)
{
throw new Exception("Reset was not completed.");
}*/
}
/// <summary>
///
/// </summary>
public void SaveImage(string fileName)
{
try
{
string timeStamp_date = DateTime.Now.ToString("yyyyMMdd");
string timeStamp_sec = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
string folderTimeStamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm");
string srcPath = $"{m_DOUBLESLASH}{_address}{m_IMAGE_DEST}{m_DESIRED_FOLDER}{m_SLASH}{timeStamp_date}{m_SLASH}{folderTimeStamp}{m_SLASH}";
bool exists = System.IO.Directory.Exists(srcPath);
if (!exists)
{
try
{
System.IO.Directory.CreateDirectory(srcPath);
//m_SrcDirectory = $"{m_DOUBLESLASH}{_address}{m_IMAGE_DEST}{m_DESIRED_FOLDER}{m_SLASH}{testUnit}";
// m_TimeStampeDate = timeStamp_date;
}
catch (Exception)
{
Reset();
throw;
}
}
string m_scopeFileName = $"{timeStamp_date}{m_SLASH}{folderTimeStamp}{m_SLASH}{fileName}_{timeStamp_sec}.{m_IMAGE_FORMAT}";
string filename = $"{srcPath}{fileName}_{timeStamp_sec}";
string command = m_SAVEIMAGECMD + m_DOUBLEQUOTES + filename + m_DOUBLEQUOTES + m_COMMA + m_IMAGE_FORMAT + m_COMMA + m_IMAGE_SOURCE + m_COMMA + m_OPTION_ON + "\n";
IOWrite(command);
}
catch (Exception)
{
Reset();
throw;
}
}
/// <summary>
///
/// </summary>
public void SetupTrigger(bool useRisingEdge, int channelNumber, double triggerLevel)
{
try
{
string command = m_STOPCMD + "\n";
IOWrite(command);
/*command = m_ISOPCCMD + "\n";
string rspStr = IOQuery(command);
string[] tokens = rspStr.Split('\n');
// check to see if STOP was completed
if (IsOperationCompleted(tokens[0]) == false)
{
throw new Exception("STOP was not completed.");
}*/
command = m_MEASCLEARCMD + "\n";
IOWrite(command);
//5. Trigger level
//*** Trigger edge source
command = m_TRIGSRCCMD + m_CHANCMD + channelNumber.ToString() + "\n";
IOWrite(command);
//*** select edge type
if (useRisingEdge)
{
command = m_RISETRIGEDGESELCMD + "\n";
}
else
{
command = m_FALLTRIGEDGESELCMD + "\n";
}
IOWrite(command);
//*** select trigger level
command = m_TRIGLEVCMD + m_CHANCMD + channelNumber.ToString() + ", " + triggerLevel.ToString() + "\n";
IOWrite(command);
/*command = m_ISOPCCMD + "\n";
rspStr = IOQuery(command);
tokens = rspStr.Split('\n');
// check to see if trigger level command was completed
if (IsOperationCompleted(tokens[0]) == false)
{
throw new Exception("Trigger level was not completed.");
}*/
// start it back up
command = m_RUNCMD + "\n";
IOWrite(command);
}
catch (Exception)
{
Reset();
throw;
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
string errorMsg = "";
if (_state == State.Ready)
{
try
{
//Reset System
Reset();
}
catch (Exception err)
{
errorMsg += err.Message + " ";
}
_state = State.Uninitialized;
}
// the stream was created in the constructor, dispose of it here
try
{
if (_tcpStream != null)
{
_tcpStream.Dispose();
_tcpStream = null;
}
}
catch (Exception err)
{
errorMsg += err.Message + " ";
}
if (errorMsg != "")
{
throw new Exception("System " + _name + " Had an error: " + errorMsg);
}
}
#endregion
}
}

View File

@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)Solution.props" />
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>Raytheon.Instruments.ScopeKeysightScpi</AssemblyName>
<Product>Scope Keysight Scpi implementation</Product>
<Description>Scope Keysight Scpi 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" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ScopeSim\ScopeSim.csproj" />
</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>

View File

@@ -0,0 +1,140 @@
// **********************************************************************************************************
// ScopeKeysightScpiFactory.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 NLog;
using Raytheon.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Reflection;
namespace Raytheon.Instruments
{
[ExportInstrumentFactory(ModelNumber = "ScopeKeysightScpiFactory")]
public class ScopeKeysightScpiFactory : 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;
public ScopeKeysightScpiFactory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
/// <summary>
/// COECommDeviceInstrumentFactory injection constructor
/// </summary>
/// <param name="configManager"></param>
/// <param name="simEngine"></param>
/// <param name="logger"></param>
[ImportingConstructor]
public ScopeKeysightScpiFactory([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(IOscilloScope));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
_logger = LogManager.GetLogger(name);
return new ScopeKeysightScpi(name, _configurationManager, _logger);
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public object GetInstrument(string name, bool simulateHw)
{
try
{
_logger = LogManager.GetLogger(name);
if (simulateHw)
return new ScopeSim(name, _configurationManager, _logger);
else
return new ScopeKeysightScpi(name, _configurationManager, _logger);
}
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);
}
}
}

View File

@@ -0,0 +1,294 @@
// 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;
namespace Raytheon.Instruments
{
/// <summary>
///
/// </summary>
public class ScopeSim : IOscilloScope
{
#region PrivateMembers
private State _state;
private string _name;
private SelfTestResult _selfTestResult;
/// <summary>
/// NLog logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Raytheon configuration
/// </summary>
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
#endregion
/// <summary>
/// ScopeSim factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public ScopeSim(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
_logger = logger;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
public ScopeSim(string name)
{
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_selfTestResult = SelfTestResult.Unknown;
_state = State.Uninitialized;
}
/// <summary>
///
/// </summary>
/// <param name="channelNumber"></param>
public void ConfigureChannel(int channelNumber, double timePerDivison, double timeOffset, double voltageOffset, double voltageScale, string inputImpedance)
{
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a Scope Sim called " + _name;
}
}
/// <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 string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
public bool ClearErrors()
{
throw new NotImplementedException();
}
public bool HasItTriggered()
{
return true;
}
public void Initialize()
{
if (_state == State.Uninitialized)
{
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString());
}
}
public string IOQuery(string command)
{
// nothing to do in sim
return "";
}
public void IOWrite(string command, bool shallWeCheckForError = true)
{
// nothing to do in sim
}
public double MeasureFallTime(int channelNumber)
{
throw new NotImplementedException();
}
public double MeasureFrequency(int channel)
{
double max = 10000;
double min = 100;
Random rnd = new Random();
double seed = rnd.NextDouble();
double dataToReturn = (seed * (max - min)) + min;
return dataToReturn;
}
public double MeasureMaxVoltage(int channelNumber)
{
throw new NotImplementedException();
}
public double MeasureMinVoltage(int channelNumber)
{
throw new NotImplementedException();
}
public double MeasurePulseWidth(int channelNumber)
{
double max = 10000;
double min = 100;
Random rnd = new Random();
double seed = rnd.NextDouble();
double dataToReturn = (seed * (max - min)) + min;
return dataToReturn;
}
public double MeasureRiseTime(int channelNumber)
{
throw new NotImplementedException();
}
public double MeasureVoltageLevel(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
_selfTestResult = SelfTestResult.Pass;
return _selfTestResult;
}
public void Reset()
{
}
public void SaveImage(string fileName)
{
}
public void SetupTrigger(bool useRisingEdge, int channelNumber, double triggerLevel)
{
}
public void Shutdown()
{
if (_state == State.Ready)
{
_state = State.Uninitialized;
}
}
}
}

View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)Solution.props" />
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>Raytheon.Instruments.ScopeSim</AssemblyName>
<Product>Scope Sim implementation</Product>
<Description>Scope Analyzer Sim 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.OscilloScope.Contracts" Version="1.3.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,137 @@
// **********************************************************************************************************
// ScopeSimFactory.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 NLog;
using Raytheon.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Reflection;
namespace Raytheon.Instruments
{
[ExportInstrumentFactory(ModelNumber = "ScopeSimFactory")]
public class ScopeSimFactory : 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;
public ScopeSimFactory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
/// <summary>
/// COECommDeviceInstrumentFactory injection constructor
/// </summary>
/// <param name="configManager"></param>
/// <param name="simEngine"></param>
/// <param name="logger"></param>
[ImportingConstructor]
public ScopeSimFactory([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(IOscilloScope));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
_logger = LogManager.GetLogger(name);
return new ScopeSim(name, _configurationManager, _logger);
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public object GetInstrument(string name, bool simulateHw)
{
try
{
_logger = LogManager.GetLogger(name);
return new ScopeSim(name, _configurationManager, _logger);
}
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);
}
}
}

View File

@@ -0,0 +1,558 @@
//>>***************************************************************************
// UNCLASSIFIED
//
// COPYRIGHT 2017 RAYTHEON MISSILE SYSTEMS
// ALL RIGHTS RESERVED
// This data was developed pursuant to Contract Number HQ0147-12-C-0004/1088370
// with the US Government. The US Government's rights in and to this
// copyrighted data are as specified in DFAR 252.227-7013
// which was made part of the above contract.
//
// Distribution Statement: D -Distribution authorized to the DoD and DoD
// contractors only based on Critical Technology Requirements, May 2001.
// Other requests shall be referred to PEO THEATER AIR DEFENSE (PMS 422).
// Warning: - This document contains technical data whose export is restricted
// by the Arms Export Control Act (Title 22, U.S.C.) or Export
// Administration Act of 1979, as amended (Title 50, U.S.C.). Violations
// of these laws are subject to severe criminal penalties. Disseminate in
// accordance with provisions of DoD 5230.25.
// Destruction Notice: - For unclassified, limited distribution information,
// destroy by any method that will prevent disclosure of contents or
// reconstruction of the document. Classified information, destroy in
// accordance with DoD-5220.22-M or OPNAVINST 5510.1h.
//>>***************************************************************************
using System;
using System.Threading;
using System.Text;
using NLog;
using Raytheon.Common;
namespace Raytheon.Instruments
{
/// <summary>
/// A class for controlling a scope via ZBind Teradyne Library
/// </summary>
public class ScopeZBind : IOscilloScope
{
#region PublicMembers
#endregion
#region PrivateMembers
// Maximum number of channels provided by scope.
private readonly string _address;
private IntPtr _handle;
private State _state;
private SelfTestResult _selfTestResult;
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>
/// The Finalizer which will release resources if required
/// </summary>
~ScopeZBind()
{
Dispose(false);
}
/// <summary>
/// Dispose of this object
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
try
{
if (disposing)
{
if (_state == State.Ready)
{
Reset();
ScopeZBindNativeMethods.zbind_remove(_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
}
}
}
#endregion
#region PublicFunctions
/// <summary>
/// ScopeZBind factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
/// <param name="logger"></param>
public ScopeZBind(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
_logger = logger;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_address = _configuration.GetConfigurationValue("ScopeZBind", "Address", "");
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="address"></param>
public ScopeZBind(string name, string address)
{
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_address = address;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="channelNumber"></param>
/// <param name="timePerDivison">Horizontal</param>
/// <param name="timeOffset"></param>
/// <param name="voltageOffset"></param>
/// <param name="voltageScale">Verticle Voltage Scale</param>
/// <param name="inputImpedance"></param>
public void ConfigureChannel(int channelNumber, double timePerDivison, double timeOffset, double voltageOffset, double voltageScale, string inputImpedance)
{
const int SWEEP_POINTS = 2000;
Reset();
IOWrite("INP1 ON");
IOWrite("INP2 ON");
IOWrite("SENSe:SWEep:POINts " + SWEEP_POINTS.ToString()); // Options defined in zScopeM
IOWrite("SENSe:SWEep:TIME " + timePerDivison.ToString()); // SWEEP_TIME.ToString()); // In seconds
IOWrite("SWE:OFFS:TIME 0.0");
IOWrite("AVER:STAT 0");
IOWrite("INIT:CONT 0");
IOWrite("SWE:MODE NORM");
IOWrite("VOLT1:RANG:OFFS " + voltageOffset.ToString());
IOWrite("VOLT1:RANG:PTP " + voltageScale.ToString()); // 10 division on screen so V/Div will be 1/10th of input
IOWrite("INP1:FILT 0");
// start wave form collection
IOWrite("INIT");
Thread.Sleep(1000);
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a Teradyne ZBind Scope";
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
/// Dispose of this objects 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 bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool HasItTriggered()
{
// Did not find support for this in the API, just return true
return true;
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
// if we have not yet been initialized, go ahead and create the socket
if (_state == State.Uninitialized)
{
int ZT_LAN = 0x0004;
int err = ScopeZBindNativeMethods.zbind_add(_address, ZT_LAN, out _handle);
// check for errors
if (err != 0)
{
throw new Exception("ScopeZBind:Initialize() - Scope " + _name + " returned error code: " + err.ToString());
}
// reset the scope
Reset();
// we already connected to the instrument in the constructor
_state = State.Ready;
}
else
{
throw new Exception("expected the state of System " + _name + " to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
public string IOQuery(string command)
{
// send the command
IOWrite(command, false);
// read from the response
StringBuilder rspStr = new StringBuilder(512);
int err = ScopeZBindNativeMethods.zbind_receive(_handle, 0, "%[ -~]", rspStr);
// check for errors
if (err != 0)
{
throw new Exception("ScopeZBind:IOQuery() - Scope " + _name + " returned error code: " + err.ToString());
}
return rspStr.ToString();
}
/// <summary>
///
/// </summary>
/// <param name="command"></param>
public void IOWrite(string command, bool shallWeCheckForError = true)
{
int err = ScopeZBindNativeMethods.zbind_send(_handle, 0, command);
// check for errors
if (shallWeCheckForError == true)
{
if (err != 0)
{
throw new Exception("ScopeZBind:IOWrite() - Scope " + _name + " returned error code: " + err.ToString());
}
}
// wait a bit for processing
Thread.Sleep(50);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureFallTime(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="channelNumber"></param>
/// <returns></returns>
public double MeasureFrequency(int channelNumber)
{
IOWrite("INIT");
IOWrite("SENSe:SWEep:MODE NORM");
string enableCommand = "SENSe:INPut" + channelNumber.ToString() + ":STATe 1";
IOWrite(enableCommand);
// stop the waveform
IOWrite("ABORt");
// wait a bit for the wave form to settle
Thread.Sleep(1000);
// The scope will respond with a string like "60.6575321, 0"
string response = IOQuery("MEASure:VOLTage:FREQuency? INPut" + channelNumber.ToString());
double result = Double.Parse(response.Split(Convert.ToChar(","))[0], System.Globalization.NumberStyles.Float);
return result;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureMaxVoltage(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureMinVoltage(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasurePulseWidth(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureRiseTime(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureVoltageLevel(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public string Name
{
get
{
return _name;
}
set { _name = value; }
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void Reset()
{
// Resets the oscilloscope
string command = "*RST";
IOWrite(command);
// just a swag
Thread.Sleep(3000);
}
/// <summary>
///
/// </summary>
public void SaveImage(string fileName)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void SetupTrigger(bool useRisingEdge, int channelNumber, double triggerLevel)
{
IOWrite("TRIG:TYPE EDGE");
IOWrite("TRIG:SOUR INP1");
IOWrite("TRIG:INP1:LEV " + triggerLevel.ToString());
if (useRisingEdge == true)
{
IOWrite("TRIG:SLOP POS");
}
else
{
IOWrite("TRIG:SLOP NEG");
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
string errorMsg = "";
if (_state == State.Ready)
{
try
{
//Reset System
Reset();
}
catch (Exception err)
{
errorMsg += err.Message + " ";
}
_state = State.Uninitialized;
}
// the stream was created in the constructor, dispose of it here
try
{
int err = ScopeZBindNativeMethods.zbind_remove(_handle);
// check for errors
if (err != 0)
{
throw new Exception("ScopeZBind:Shutdown() - Scope " + _name + " returned error code: " + err.ToString());
}
}
catch (Exception err)
{
errorMsg += err.Message + " ";
}
if (errorMsg != "")
{
throw new Exception("System " + _name + " Had an error: " + errorMsg);
}
}
#endregion
}
}

View File

@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)Solution.props" />
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>Raytheon.Instruments.ScopeZBind</AssemblyName>
<Product>Scope ZBind implementation</Product>
<Description>Scope Analyzer ZBind 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" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ScopeSim\ScopeSim.csproj" />
</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>

View File

@@ -0,0 +1,140 @@
// **********************************************************************************************************
// ScopeKeysightScpiFactory.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 NLog;
using Raytheon.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Reflection;
namespace Raytheon.Instruments
{
[ExportInstrumentFactory(ModelNumber = "ScopeZBindFactory")]
public class ScopeZBindFactory : 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;
public ScopeZBindFactory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
/// <summary>
/// COECommDeviceInstrumentFactory injection constructor
/// </summary>
/// <param name="configManager"></param>
/// <param name="simEngine"></param>
/// <param name="logger"></param>
[ImportingConstructor]
public ScopeZBindFactory([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(IOscilloScope));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
_logger = LogManager.GetLogger(name);
return new ScopeZBind(name, _configurationManager, _logger);
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public object GetInstrument(string name, bool simulateHw)
{
try
{
_logger = LogManager.GetLogger(name);
if (simulateHw)
return new ScopeSim(name, _configurationManager, _logger);
else
return new ScopeZBind(name, _configurationManager, _logger);
}
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);
}
}
}

View File

@@ -0,0 +1,46 @@
// 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.Runtime.InteropServices;
using System.Text;
using ZT_HANDLE = System.IntPtr;
namespace Raytheon.Instruments
{
/// <summary>
/// InterOp interface to ZtScope Instrument Driver
/// </summary>
public class ScopeZBindNativeMethods
{
const string DLL_LOCATION = @"C:\Program Files (x86)\ZTEC Instruments\MClass\bin\ZBind.dll";
/*****************************************************************************/
/*= Non-SCPI Function Prototypes ============================================*/
/*****************************************************************************/
[DllImport(DLL_LOCATION, CallingConvention = CallingConvention.StdCall)]
public static extern int zbind_add(string address, int lan, out ZT_HANDLE handle);
[DllImport(DLL_LOCATION, CallingConvention = CallingConvention.StdCall)]
public static extern int zbind_remove(ZT_HANDLE instr_handle);
[DllImport(DLL_LOCATION, CallingConvention = CallingConvention.StdCall)]
public static extern int zbind_send(ZT_HANDLE instr_handle, int lockCmd, string scpi);
[DllImport(DLL_LOCATION, CallingConvention = CallingConvention.StdCall)]
public static extern int zbind_receive(ZT_HANDLE instr_handle, int lockCmd, string formatter, StringBuilder rcvString);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,963 @@
// 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 Raytheon.Common;
namespace Raytheon.Instruments
{
/// <summary>
/// CDTS HAL Oscilloscope Driver for ZTEC ZT4442
/// </summary>
public class ScopeZtec : IOscilloScope
{
#region PublicMembers
#endregion
#region PrivateMembers
private enum enSCOPEInput { DC_50, DC_1M, AC_1M };
private IntPtr _handle;
private string _resourceString;
private State _state;
private SelfTestResult _selfTestResult;
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>
/// The Finalizer which will release resources if required
/// </summary>
~ScopeZtec()
{
Dispose(false);
}
/// <summary>
/// Dispose of this object
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
try
{
if (disposing)
{
if (_state == State.Ready)
{
Reset();
int ret = ScopeZtMNativeMethods.ztscopeM_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
}
}
}
/// <summary>
/// Check instrument error status. If there is a failure, get its error message and generate an exception.
/// </summary>
/// <param name="bErrorOccurred">if set to <c>true</c> if error occurred </param>
/// <param name="nErrorCode">The error code.</param>
/// <param name="strErrorMsg">The error message.</param>
/// <returns></returns>
private void CheckError(out bool bErrorOccurred, out int nErrorCode, out string strErrorMsg)
{
bErrorOccurred = false;
nErrorCode = 0;
strErrorMsg = "";
int numberOfErrors = 0;
int ztError = ScopeZtMNativeMethods.ztscopeM_error_count(_handle, out numberOfErrors);
if (numberOfErrors == 0)
{
bErrorOccurred = false;
}
else
{
bErrorOccurred = true;
int[] errors = new int[numberOfErrors];
byte[] errMsg = new byte[256];
ztError = ScopeZtMNativeMethods.ztscopeM_errors(_handle, out numberOfErrors, errors);
//this also clear the error buffer
nErrorCode = errors[numberOfErrors - 1]; //take last error
ScopeZtMNativeMethods.ztscopeM_error_description(nErrorCode, errMsg);
strErrorMsg = System.Text.Encoding.Default.GetString(errMsg);
}
}
/// <summary>
/// Discards any queued errors, clears the instrument status,
/// and resets the status and event registers.
/// </summary>
/// <returns></returns>
private void ClearError()
{
int numberOfErrors = 0;
ScopeZtMNativeMethods.ztscopeM_error_count(_handle, out numberOfErrors);
if (numberOfErrors > 0)
{
int[] errors = new int[numberOfErrors];
//this retrieve and clear the error buffer
ScopeZtMNativeMethods.ztscopeM_errors(_handle, out numberOfErrors, errors);
}
}
/// <summary>
///
/// </summary>
/// <param name="channel"></param>
private void ClearMeasurement(int channel)
{
//@@@ not sure if this is the correct command
if (0 != ScopeZtMNativeMethods.ztscopeM_calculate_measure_clear(_handle, channel))
{
RaiseExceptionAtError();
}
}
/// <summary>
///
/// </summary>
/// <param name="channel"></param>
public void Disable(int channel)
{
int ret = ScopeZtMNativeMethods.ztscopeM_channel_enable(_handle, channel, 0x00000000);
if (0 != ret)
{
RaiseExceptionAtError();
}
}
/// <summary>
///
/// </summary>
/// <param name="channel"></param>
public void Enable(int channel)
{
int ret = ScopeZtMNativeMethods.ztscopeM_channel_enable(_handle, channel, 0x00000001);
if (0 != ret)
{
RaiseExceptionAtError();
}
}
/// <summary>
/// Gets or sets Configure input termination for channel: DC_50=0, DC_1M=1, AC_1M =2
/// Use one of the three subcommands to enable the appropriate signal input termination.
/// The subcommands correspond to DC coupling with 50 ohm termination resistance,
/// DC coupling with 1 Mohm termination resistance,
/// and AC coupling with 1 Mohm termination resistance, respectively.
/// </summary>
/// <value>
/// Configure input termination for channel: DC_50=0, DC_1M=1, AC_1M =2
/// </value>
private void InputImpedance(enSCOPEInput input, int channel)
{
//only valid for input channels
if (channel >= 4)
{
throw new Exception("invalid channel number input: " + channel.ToString());
}
int V_coupling = 0;
double V_impedance = 0.0;
switch (input)
{
//#define ZTSCOPEM_COUP_AC 0x00000000
//#define ZTSCOPEM_COUP_DC 0x00000001
//#define ZTSCOPEM_COUP_ACLFR 0x00000002
//#define ZTSCOPEM_COUP_GND 0x00000003
//#define ZTSCOPEM_IMP_50 50.0
//#define ZTSCOPEM_IMP_1M 1000000.0
case enSCOPEInput.DC_50:
V_coupling = 0x00000001; //ZTSCOPEM_COUP_DC
V_impedance = 50.0; //50 Ohm - ZTSCOPEM_IMP_50
break;
case enSCOPEInput.DC_1M:
V_coupling = 0x00000001; //ZTSCOPEM_COUP_DC
V_impedance = 1000000.0; //ZTSCOPEM_IMP_1M
break;
case enSCOPEInput.AC_1M:
V_coupling = 0x00000000; //ZTSCOPEM_COUP_AC
V_impedance = 1000000.0; //ZTSCOPEM_IMP_1M
break;
default: //unknown, default to DC_1M
V_coupling = 0x00000001; //ZTSCOPEM_COUP_DC
V_impedance = 1000000.0; //ZTSCOPEM_IMP_1M
break;
}
int ret = ScopeZtMNativeMethods.ztscopeM_single_input_coupling(_handle, channel, V_coupling);
if (0 != ret)
{
RaiseExceptionAtError();
}
ret = ScopeZtMNativeMethods.ztscopeM_single_input_impedance(_handle, channel, V_impedance);
if (0 != ret)
{
RaiseExceptionAtError();
}
}
/// <summary>
/// If there is error, throw an exception with error query information.
/// </summary>
private void RaiseExceptionAtError()
{
bool bErrorOccurred = false;
int nErrorCode = 0;
string strErrorMsg = "";
CheckError(out bErrorOccurred, out nErrorCode, out strErrorMsg);
if (bErrorOccurred)
{
throw new Exception(strErrorMsg);
}
}
/// <summary>
///
/// </summary>
private void Run()
{
int ret = ScopeZtMNativeMethods.ztscopeM_initiate(_handle);
if (0 != ret)
{
RaiseExceptionAtError();
}
}
/// <summary>
/// Causes the Scope to stop acquiring data.
/// </summary>
/// <returns></returns>
private void Stop()
{
int ret = ScopeZtMNativeMethods.ztscopeM_abort(_handle);
if (0 != ret)
{
RaiseExceptionAtError();
}
}
/// <summary>
/// Gets or sets the display timescale in seconds per division. This actually set Sweep time to be 10x time scale.
/// </summary>
/// <value>
/// The display timescale in seconds per division
/// </value>
private double TimeScale
{
get
{
throw new NotImplementedException();
/*double sweepTime;
ZTScopeM.ztscopeM_single_horizontal_time_query(m_Handle, out sweepTime);
return sweepTime / 10.0;*/
}
set
{
int ret = ScopeZtMNativeMethods.ztscopeM_single_horizontal_time(_handle, value * 10);
if (0 != ret)
{
RaiseExceptionAtError();
}
}
}
/// <summary>
/// Gets or sets The display voltage scale in Volts per division
/// </summary>
/// <value>
/// The display voltage scale in Volts per division
/// </value>
private void VoltScale(int channel, double range)
{
//only valid for input channels
if (channel >= 4)
{
throw new Exception("invalid channel number input: " + channel.ToString());
}
double V_range = 400.0;
//need range check
if (range > 40)
{
V_range = 400.0; //set to the maximum range
}
else
{
V_range = range * 10;
}
int ret = ScopeZtMNativeMethods.ztscopeM_single_input_range(_handle, channel, V_range);
if (0 != ret)
{
RaiseExceptionAtError();
}
}
/// <summary>
/// Gets or sets The display offset voltage in Volts
/// A positive voltage offset shifts the displayed signal (as well as ground and trigger level indicators) downward;
/// in other words, the center of the vertical scale is set to dOffset.
/// </summary>
/// <value>
/// The display offset voltage in Volts
/// </value>
private void VoltOffset(int channel, double offset)
{
//only valid for input channels
if (channel >= 4)
{
throw new Exception("invalid channel number input: " + channel.ToString());
}
int ret = ScopeZtMNativeMethods.ztscopeM_single_input_offset(_handle, channel, offset);
if (0 != ret)
{
RaiseExceptionAtError();
}
}
#endregion
#region PublicFunctions
/// <summary>
/// ScopeZtec factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
/// <param name="logger"></param>
public ScopeZtec(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
_logger = logger;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_resourceString = _configuration.GetConfigurationValue("ScopeZtec", "ResourceString", "");
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
public ScopeZtec(string name, string resourceString)
{
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_resourceString = resourceString;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
ClearError();
return true;
}
/// <summary>
///
/// </summary>
/// <param name="channelNumber"></param>
/// <param name="timePerDivison"></param>
/// <param name="timeOffset"></param>
/// <param name="voltageOffset"></param>
/// <param name="voltageScale"></param>
/// <param name="inputImpedance"></param>
public void ConfigureChannel(int channelNumber, double timePerDivison, double timeOffset, double voltageOffset, double voltageScale, string inputImpedance)
{
// make sure it is stopped first
Stop();
// clear the measurement
ClearMeasurement(channelNumber);
//1. time per division
TimeScale = timePerDivison;
//2. time offset
int ret = ScopeZtMNativeMethods.ztscopeM_single_horizontal_offset_time(_handle, timeOffset);
if (0 != ret)
{
RaiseExceptionAtError();
}
//3. Volt per division
VoltScale(channelNumber, voltageScale);
//4. Volt offset
VoltOffset(channelNumber, voltageOffset);
// set input impedance to 1M ohmns.
enSCOPEInput imped = enSCOPEInput.DC_1M;
// The value of inputImpedance is expected to be "DC", equivalent to 1M ohmn; otherwise, it outputs error.
if (inputImpedance.ToUpper().Trim() != "DC".ToUpper())
{
throw new Exception("ScopeSetupChannel() expected Input Impedance to be DC. If others are needed, need to update sw");
}
InputImpedance(imped, channelNumber);
// It turns on the specified channel.
Enable(channelNumber);
// start it back up
Run();
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a CDTS ZTec Scope";
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
/// Dispose of this objects 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 bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool HasItTriggered()
{
int state = 0;
int ret = ScopeZtMNativeMethods.ztscopeM_trigger_event_query(_handle, out state);
if (0 != ret)
{
RaiseExceptionAtError();
}
if (state == 1)
{
return true;
}
else
{
return false;
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
// if we have not yet been initialized, go ahead and create the socket
if (_state == State.Uninitialized)
{
int ret = ScopeZtMNativeMethods.ztscopeM_initialize(_resourceString,
0, // id_query
1, // reset
out _handle);
if (ret != 0)
{
throw new Exception("call to ztscopeM_initialize returned " + ret);
}
Reset();
// we already connected to the instrument in the constructor
_state = State.Ready;
}
else
{
throw new Exception("expected the state of System " + _name + " to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
public string IOQuery(string command)
{
throw new NotImplementedException();
// send the command
/*IOWrite(command, false);
// 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 = 0;
string errorMessage = GetErrorCode(out err);
if (err != 0)
{
throw new Exception("ScopeZtec:IOQuery() - Scope " + _name + " returned error code: " + err.ToString() + "," + errorMessage);
}
return rspStr;*/
}
/// <summary>
///
/// </summary>
/// <param name="command"></param>
public void IOWrite(string command, bool shallWeCheckForError = true)
{
throw new NotImplementedException();
// convert to a byte array
/*byte[] commandBuffer = Encoding.ASCII.GetBytes(command);
// send the data out
_tcpStream.Write(commandBuffer, 0, commandBuffer.Length);
// check for errors
if (shallWeCheckForError == true)
{
int err = 0;
string errorMessage = GetErrorCode(out err);
if (err != 0)
{
throw new Exception("ScopeZtec:IOWrite() - Scope " + _name + " returned error code: " + err.ToString() + "," + errorMessage);
}
}*/
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureFallTime(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="channelNumber"></param>
/// <returns></returns>
public double MeasureFrequency(int channelNumber)
{
double freq = -1.0;
int ret = ScopeZtMNativeMethods.ztscopeM_measure_immediate(_handle, 0x0000000D, channelNumber, out freq);
if (0 != ret)
{
RaiseExceptionAtError();
}
return freq;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureMaxVoltage(int channelNumber)
{
double max = -1.0;
int ret = ScopeZtMNativeMethods.ztscopeM_measure_immediate(_handle, 0x00000012, channelNumber, out max);
if (0 != ret)
{
RaiseExceptionAtError();
}
return max;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureMinVoltage(int channelNumber)
{
double min = 999.99;
int ret = ScopeZtMNativeMethods.ztscopeM_measure_immediate(_handle, 0x00000013, channelNumber, out min);
if (0 != ret)
{
RaiseExceptionAtError();
}
return min;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasurePulseWidth(int channelNumber)
{
double pw = -1.0;
int ret = ScopeZtMNativeMethods.ztscopeM_measure_immediate(_handle, 0x0000001B, channelNumber, out pw);
if (0 != ret)
{
RaiseExceptionAtError();
}
return pw;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureRiseTime(int channelNumber)
{
double rt = -1.0;
int ret = ScopeZtMNativeMethods.ztscopeM_measure_immediate(_handle, 0x00000020, channelNumber, out rt);
if (0 != ret)
{
RaiseExceptionAtError();
}
return rt;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double MeasureVoltageLevel(int channelNumber)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public string Name
{
get
{
return _name;
}
set { _name = value; }
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
int selfTestStatus = -1;
//Returns the test status register.
//Bit 0- Baseboard Register Test Failed Bit
//Bit 1- Unused Bit 2- Baseboard ROM Test Failed Bit
//Bit 3- Unused
//Bit 4- Reference Oscillator Test Failed Bit
//Bit 5- DRAM Test Failed Bit
//Bit 6- FlashMemory Test Failed Bit
//Bit 7- Unused Bit
//Bit 8- Digitizer 1Register Test Failed Bit
//Bit 9- Digitizer 2Register Test Failed Bit
//Bit 10-15- Unused Bits
int ret = ScopeZtMNativeMethods.ztscopeM_self_test(_handle, out selfTestStatus);
if (0 != ret)
{
RaiseExceptionAtError();
}
if (selfTestStatus == 0)
{
_selfTestResult = SelfTestResult.Pass;
}
else
{
_selfTestResult = SelfTestResult.Fail;
throw new Exception("Self Test Failed with an Error Code: " + selfTestStatus.ToString());
}
return _selfTestResult;
}
/// <summary>
///
/// </summary>
public void Reset()
{
int ret = ScopeZtMNativeMethods.ztscopeM_reset(_handle);
if (0 != ret)
{
RaiseExceptionAtError();
}
}
/// <summary>
///
/// </summary>
public void SaveImage(string fileName)
{
throw new NotImplementedException();
/*try
{
string timeStamp_date = DateTime.Now.ToString("yyyyMMdd");
string timeStamp_sec = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
string folderTimeStamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm");
string srcPath = $"{m_DOUBLESLASH}{_address}{m_IMAGE_DEST}{m_DESIRED_FOLDER}{m_SLASH}{timeStamp_date}{m_SLASH}{folderTimeStamp}{m_SLASH}";
bool exists = System.IO.Directory.Exists(srcPath);
if (!exists)
{
try
{
System.IO.Directory.CreateDirectory(srcPath);
//m_SrcDirectory = $"{m_DOUBLESLASH}{_address}{m_IMAGE_DEST}{m_DESIRED_FOLDER}{m_SLASH}{testUnit}";
// m_TimeStampeDate = timeStamp_date;
}
catch (Exception)
{
Reset();
throw;
}
}
string m_scopeFileName = $"{timeStamp_date}{m_SLASH}{folderTimeStamp}{m_SLASH}{fileName}_{timeStamp_sec}.{m_IMAGE_FORMAT}";
string filename = $"{srcPath}{fileName}_{timeStamp_sec}";
string command = m_SAVEIMAGECMD + m_DOUBLEQUOTES + filename + m_DOUBLEQUOTES + m_COMMA + m_IMAGE_FORMAT + m_COMMA + m_IMAGE_SOURCE + m_COMMA + m_OPTION_ON + "\n";
IOWrite(command);
}
catch (Exception)
{
Reset();
throw;
}*/
}
/// <summary>
///
/// </summary>
public void SetupTrigger(bool useRisingEdge, int channelNumber, double triggerLevel)
{
const int RISING_TRIGGER = 0x00000000;
const int FALLING_TRIGGER = 0x00000001;
try
{
Stop();
int ret = ScopeZtMNativeMethods.ztscopeM_single_trigger_type(_handle, 0x00000000);
if (0 != ret)
{
RaiseExceptionAtError();
}
int trigSource = channelNumber + 0x0000000A;
int triggerEdge = FALLING_TRIGGER;
if (useRisingEdge == true)
{
triggerEdge = RISING_TRIGGER;
}
ret = ScopeZtMNativeMethods.ztscopeM_trigger(_handle, trigSource, triggerLevel, triggerEdge);
if (0 != ret)
{
RaiseExceptionAtError();
}
//ret = ScopeZtMNativeMethods.ztscopeM_trigger_holdoff(_handle, dHoldoffDuration, 1);
Run();
}
catch (Exception)
{
Reset();
throw;
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
string errorMsg = "";
if (_state == State.Ready)
{
try
{
Reset();
}
catch (Exception err)
{
errorMsg += err.Message + " ";
}
_state = State.Uninitialized;
}
// the stream was created in the constructor, dispose of it here
try
{
int ret = ScopeZtMNativeMethods.ztscopeM_close(_handle);
}
catch (Exception err)
{
errorMsg += err.Message + " ";
}
if (errorMsg != "")
{
throw new Exception("System " + _name + " Had an error: " + errorMsg);
}
}
#endregion
}
}

View File

@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)Solution.props" />
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>Raytheon.Instruments.ScopeZtec</AssemblyName>
<Product>Scope Ztec implementation</Product>
<Description>Scope Ztec 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" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ScopeSim\ScopeSim.csproj" />
</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>

View File

@@ -0,0 +1,140 @@
// **********************************************************************************************************
// ScopeKeysightScpiFactory.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 NLog;
using Raytheon.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Reflection;
namespace Raytheon.Instruments
{
[ExportInstrumentFactory(ModelNumber = "ScopeZtecFactory")]
public class ScopeZtecFactory : 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;
public ScopeZtecFactory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
/// <summary>
/// COECommDeviceInstrumentFactory injection constructor
/// </summary>
/// <param name="configManager"></param>
/// <param name="simEngine"></param>
/// <param name="logger"></param>
[ImportingConstructor]
public ScopeZtecFactory([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(IOscilloScope));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
_logger = LogManager.GetLogger(name);
return new ScopeZtec(name, _configurationManager, _logger);
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public object GetInstrument(string name, bool simulateHw)
{
try
{
_logger = LogManager.GetLogger(name);
if (simulateHw)
return new ScopeSim(name, _configurationManager, _logger);
else
return new ScopeZtec(name, _configurationManager, _logger);
}
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);
}
}
}