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,927 @@
// 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 Raytheon.Instruments.GeneralIO;
using System.Collections.Generic;
using SIUSBXP_DLL;
using System.Collections.Specialized;
using NLog;
using Raytheon.Common;
using System.IO;
using System.Reflection;
namespace Raytheon.Instruments
{
/// <summary>
/// Class for controlling a Silicon Labs CP2108 UART GPIO device
/// </summary>
public class DIOSiUSBXp : IGeneralIO, IDisposable
{
#region PublicClassMembers
#endregion
#region PrivateClassMembers
private IntPtr _handle;
private uint _deviceNum;
private State _state;
private string _name;
private SelfTestResult _selfTestResult;
private object _syncObj = new Object();
private int _numChannelPerPort = 8;
private int _channelStartIndex = 0;
private int _numInputChannels;
private int _numOutputChannels;
private bool _shallWeInitializeOutput = false;
private Dictionary<string, IODatatypes.DIOChannelInfo> _signalNameToChannelMap = new Dictionary<string, IODatatypes.DIOChannelInfo>();
/// <summary>
/// NLog logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Raytheon configuration
/// </summary>
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
#endregion
#region PrivateClassFunctions
~DIOSiUSBXp()
{
Dispose(false);
}
/// <summary>
///
/// </summary>
private void CancelIo()
{
int ret = SIUSBXP.SI_CancelIo(_handle);
if (ret != 0)
{
throw new Exception("call to cancel IO returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
private void CancelIoEx()
{
int ret = SIUSBXP.SI_CancelIoEx(_handle, IntPtr.Zero);
if (ret != 0)
{
throw new Exception("call to cancel IO EX returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="numBytesInQueue"></param>
/// <param name="queueStatus"></param>
private void CheckRXQueue(ref uint numBytesInQueue, ref uint queueStatus)
{
int ret = SIUSBXP.SI_CheckRXQueue(_handle, ref numBytesInQueue, ref queueStatus);
if (ret != 0)
{
throw new Exception("call to check Rx Queue returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
private void Close()
{
int ret = SIUSBXP.SI_Close(_handle);
if (ret != 0)
{
throw new Exception("call to close returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="ioControlCode"></param>
/// <param name="inBuffer"></param>
/// <param name="bytesToRead"></param>
/// <param name="outBuffer"></param>
/// <param name="bytesToWrite"></param>
/// <param name="bytesSucceeded"></param>
/// <returns></returns>
private void DeviceIOControl(uint ioControlCode, ref byte[] inBuffer, uint bytesToRead, ref byte[] outBuffer, uint bytesToWrite, ref uint bytesSucceeded)
{
int ret = SIUSBXP.SI_DeviceIOControl(_handle, ioControlCode, inBuffer, bytesToRead, outBuffer, bytesToWrite, ref bytesSucceeded);
if (ret != 0)
{
throw new Exception("call to SI_DeviceIOControl returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
/// Dispose the object's resources
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
try
{
if (disposing)
{
if (_state == State.Ready)
{
Close();
_state = State.Uninitialized;
}
}
}
catch (Exception)
{
try
{
//ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
}
catch (Exception)
{
//Do not rethrow. Exception from error logger that has already been garbage collected.
}
}
}
/// <summary>
///
/// </summary>
private void FlushBuffers()
{
int ret = SIUSBXP.SI_FlushBuffers(_handle, 1, 1);
if (ret != 0)
{
throw new Exception("call to flush returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="product"></param>
/// <param name="length"></param>
/// <param name="convertToAscii"></param>
private void GetDeviceProductString(ref byte[] product, ref byte length, bool convertToAscii)
{
int ret = SIUSBXP.SI_GetDeviceProductString(_handle, product, ref length, convertToAscii);
if (ret != 0)
{
throw new Exception("call returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="highVersion"></param>
/// <param name="lowVersion"></param>
private void GetDLLVersion(ref uint highVersion, ref uint lowVersion)
{
int ret = SIUSBXP.SI_GetDLLVersion(ref highVersion, ref lowVersion);
if (ret != 0)
{
throw new Exception("call returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="highVersion"></param>
/// <param name="lowVersion"></param>
private void GetDriverVersion(ref uint highVersion, ref uint lowVersion)
{
int ret = SIUSBXP.SI_GetDriverVersion(ref highVersion, ref lowVersion);
if (ret != 0)
{
throw new Exception("call returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="LibVersion"></param>
private void GetInterfaceNumber(ref byte LibVersion)
{
int ret = SIUSBXP.SI_GetInterfaceNumber(_handle, ref LibVersion);
if (ret != 0)
{
throw new Exception("call returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="modemStatus"></param>
private void GetModemStatus(ref byte modemStatus)
{
int ret = SIUSBXP.SI_GetModemStatus(_handle, ref modemStatus);
if (ret != 0)
{
throw new Exception("call returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
private void GetNumDevices()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="libVersion"></param>
private void GetPartLibraryVersion(ref int libVersion)
{
int ret = SIUSBXP.SI_GetPartLibraryVersion(_handle, ref libVersion);
if (ret != 0)
{
throw new Exception("call returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="partNumber"></param>
private void GetPartNumber(ref byte partNumber)
{
int ret = SIUSBXP.SI_GetPartNumber(_handle, ref partNumber);
if (ret != 0)
{
throw new Exception("call returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
/// Can use as self-test
/// </summary>
/// <returns></returns>
private void GetProductString()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="readTimeoutMs"></param>
/// <param name="writeTimeoutMs"></param>
private void GetTimeouts(ref uint readTimeoutMs, ref uint writeTimeoutMs)
{
int ret = SIUSBXP.SI_GetTimeouts(ref readTimeoutMs, ref writeTimeoutMs);
if (ret != 0)
{
throw new Exception("call returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
private void Open()
{
int ret = SIUSBXP.SI_Open(_deviceNum, ref _handle);
if (ret != 0)
{
throw new Exception("call to open returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="buff"></param>
/// <param name="numBytesToRead"></param>
/// <returns></returns>
private uint Read(ref byte[] buff, uint numBytesToRead)
{
uint bytesRead = 0;
//uint bytesToReadUint = Convert.ToUInt32(bytesToRead);
int ret = SIUSBXP.SI_Read(_handle, buff, numBytesToRead, ref bytesRead, IntPtr.Zero);
if (ret != 0)
{
throw new Exception("call to read latch returned error: " + ret.ToString() + " on card: " + _name);
}
if (numBytesToRead != bytesRead)
{
throw new Exception("Commanded " + numBytesToRead + " bytes, received " + bytesRead + " bytes on card: " + _name);
}
return bytesRead;
}
/// <summary>
///
/// </summary>
/// <param name="latch"></param>
/// <returns></returns>
private void ReadLatch(ref byte latch)
{
int ret = SIUSBXP.SI_ReadLatch(_handle, ref latch);
if (ret != 0)
{
throw new Exception("call to read latch returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="baudDivisor"></param>
/// <returns></returns>
private void SetBaudDivisor(ushort baudDivisor)
{
int ret = SIUSBXP.SI_SetBaudDivisor(_handle, baudDivisor);
if (ret != 0)
{
throw new Exception("call to returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="baudRate"></param>
private void SetBaudRate(uint baudRate)
{
int ret = SIUSBXP.SI_SetBaudRate(_handle, baudRate);
if (ret != 0)
{
throw new Exception("call to returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
/// 0 or 1
/// </summary>
/// <param name="breakState"></param>
/// <returns></returns>
private void SetBreak(ushort breakState)
{
int ret = SIUSBXP.SI_SetBreak(_handle, breakState);
if (ret != 0)
{
throw new Exception("call to returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// CTS
/// SI_STATUS_INPUT = 0x00;
/// SI_HANDSHAKE_LINE = 0x01;
/// RTS
/// SI_HELD_INACTIVE = 0x00;
/// SI_HELD_ACTIVE = 0x01;
/// SI_FIRMWARE_CONTROLLED = 0x02;
/// SI_TRANSMIT_ACTIVE_SIGNAL = 0x03;
/// DTR
/// SI_HELD_INACTIVE = 0x00;
/// SI_HELD_ACTIVE = 0x01;
/// SI_FIRMWARE_CONTROLLED = 0x02;
/// DSR
/// SI_STATUS_INPUT = 0x00;
/// SI_HANDSHAKE_LINE = 0x01;
/// DCD
/// SI_STATUS_INPUT = 0x00;
/// SI_HANDSHAKE_LINE = 0x01;
/// FlowXonXoff
/// 0 or 1
/// </summary>
/// <returns></returns>
private void SetFlowControl(byte cts, byte rts, byte dtr, byte dsr, byte dcd, bool flowXOnOff)
{
int ret = SIUSBXP.SI_SetFlowControl(_handle, cts, rts, dtr, dsr, dcd, flowXOnOff);
if (ret != 0)
{
throw new Exception("call to returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
/// Set the line control
/// Bits 0-3: Number of stop bits
/// 0: 1 stop bit
/// 1: 1.5 stop bits
/// 2: 2 stop bits
/// Bits 4-7: Parity
/// 0: none
/// 1: Odd
/// 2: Even
/// 3: Mark
/// 4: Space
/// Bits 8-15: Number of bits per word
/// 5, 6, 7, or 8
/// </summary>
/// <returns></returns>
private void SetLineControl(ushort lineControl)
{
int ret = SIUSBXP.SI_SetLineControl(_handle, lineControl);
if (ret != 0)
{
throw new Exception("call to returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="readTimeoutMs"></param>
/// <param name="writeTimeoutMs"></param>
private void SetTimeout(uint readTimeoutMs, uint writeTimeoutMs)
{
int ret = SIUSBXP.SI_SetTimeouts(readTimeoutMs, writeTimeoutMs);
if (ret != 0)
{
throw new Exception("call to returned error: " + ret.ToString() + " on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="writeBuff"></param>
/// <param name="numBytesToWrite"></param>
private void Write(ref byte[] writeBuff, uint numBytesToWrite)
{
uint bytesWritten = 0;
//uint bytesToWriteUint = Convert.ToUInt32(numBytesToWrite);
int ret = SIUSBXP.SI_Write(_handle, writeBuff, numBytesToWrite, ref bytesWritten, IntPtr.Zero);
if (ret != 0)
{
throw new Exception("call to write latch returned error: " + ret.ToString() + " on card: " + _name);
}
if (numBytesToWrite != bytesWritten)
{
throw new Exception("Commanded " + numBytesToWrite + " bytes, wrote " + bytesWritten + " bytes on card: " + _name);
}
}
/// <summary>
///
/// </summary>
/// <param name="mask"></param>
/// <param name="latch"></param>
/// <returns></returns>
private void WriteLatch(byte mask, byte latch)
{
int ret = SIUSBXP.SI_WriteLatch(_handle, mask, latch);
if (ret != 0)
{
throw new Exception("call to write latch returned error: " + ret.ToString() + " on card: " + _name);
}
}
#endregion
#region PublicClassFunctions
/// <summary>
/// DIOSiUSBXp factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public DIOSiUSBXp(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
_logger = logger;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string dioModuleDefPath = _configuration.GetConfigurationValue(deviceName, ConfigXml.DIO_MODULE_DEF_FILEPATH.ToString());
if (!Path.IsPathRooted(dioModuleDefPath))
dioModuleDefPath = Path.GetFullPath(Path.Combine(assemblyFolder, dioModuleDefPath));
IConfigurationFile dioModuleConfig = new ConfigurationFile(dioModuleDefPath);
Boolean.TryParse(dioModuleConfig.ReadValue(Name, ConfigIni.SHALL_WE_DRIVE_OUTPUT_UPON_INITIALIZATION.ToString()), out _shallWeInitializeOutput);
UInt32.TryParse(dioModuleConfig.ReadValue(Name, ConfigIni.DEVICE_NUMBER.ToString()), out _deviceNum);
Int32.TryParse(dioModuleConfig.ReadValue(Name, ConfigIni.NUM_INPUT_CHANNELS.ToString()), out _numInputChannels);
Int32.TryParse(dioModuleConfig.ReadValue(Name, ConfigIni.NUM_OUTPUT_CHANNELS.ToString()), out _numOutputChannels);
Int32.TryParse(dioModuleConfig.ReadValue(Name, ConfigIni.NUM_CHANNELS_PER_PORT.ToString()), out _numChannelPerPort);
Int32.TryParse(dioModuleConfig.ReadValue(Name, ConfigIni.CHANNEL_START_INDEX.ToString()), out _channelStartIndex);
if (!(_channelStartIndex == 0 || _channelStartIndex == 1))
{
throw new Exception($"The value for key {ConfigIni.CHANNEL_START_INDEX.ToString()} in section {Name} must be 0 or 1 in {dioModuleDefPath}");
}
List<string> outputSignalNames = dioModuleConfig.ReadAllKeys($"{Name}.{ConfigIni.OUTPUT_SIGNALS}");
List<string> intputSignalNames = dioModuleConfig.ReadAllKeys($"{Name}.{ConfigIni.INPUT_SIGNALS}");
IODatatypes.DIOChannelInfo info;
foreach (string signalName in outputSignalNames)
{
if (_signalNameToChannelMap.ContainsKey(signalName))
throw new Exception($"Key {signalName} in section {Name}.{ConfigIni.OUTPUT_SIGNALS} conflicts with the same key defined in another section.");
string iniLine = dioModuleConfig.ReadValue($"{Name}.{ConfigIni.OUTPUT_SIGNALS}", signalName);
string[] infoTokens = iniLine.Split('|');
if (infoTokens.Length != 2)
{
throw new Exception($"Key {signalName} in section {Name}.{ConfigIni.OUTPUT_SIGNALS} does not contain 2 tokens");
}
info.channelNumber = Convert.ToUInt32(infoTokens[0]);
info.initialValue = Convert.ToInt32(infoTokens[1]);
_signalNameToChannelMap[signalName] = info;
}
foreach (string signalName in intputSignalNames)
{
if (_signalNameToChannelMap.ContainsKey(signalName))
throw new Exception($"Key {signalName} in section {Name}.{ConfigIni.INPUT_SIGNALS} conflicts with the same key defined in another section.");
string iniLine = dioModuleConfig.ReadValue($"{Name}.{ConfigIni.INPUT_SIGNALS}", signalName);
info.channelNumber = Convert.ToUInt32(iniLine);
info.initialValue = -1;
_signalNameToChannelMap[signalName] = info;
}
_handle = IntPtr.Zero;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
}
/// <summary>
///
/// </summary>
/// <param name="deviceName"></param>
/// <param name="deviceNum"></param>
/// <param name="inputPins"></param>
/// <param name="outputPins"></param>
public DIOSiUSBXp(string deviceName, uint deviceNum)
{
_deviceNum = deviceNum;
_name = deviceName;
_handle = IntPtr.Zero;
_state = State.Uninitialized;
_selfTestResult = SelfTestResult.Unknown;
_logger = LogManager.GetCurrentClassLogger();
//@@@ Do we need to pass in more args to configure the DIO (Baud?)
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
//could use this to cancel IO and flush the buffers
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
byte arrSize = 255;
byte[] deviceStringArray = new byte[arrSize];
GetDeviceProductString(ref deviceStringArray, ref arrSize, true);
return "This is a Silicon Labs CP2108 device: " + deviceStringArray.ToString();
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
/// Dispose of this object.
/// </summary>
public void Dispose()
{
lock (_syncObj)
{
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>
/// <param name="signalName"></param>
/// <returns></returns>
public IODatatypes.BitState GetBitState(string signalName)
{
lock (_syncObj)
{
if (!_signalNameToChannelMap.ContainsKey(signalName))
throw new Exception($"Signal name {signalName} doesn't exist for card: " + _name);
if (_signalNameToChannelMap[signalName].channelNumber >= _numInputChannels || _signalNameToChannelMap[signalName].channelNumber < _channelStartIndex)
{
throw new Exception($"The output channel number {_signalNameToChannelMap[signalName].channelNumber} specified must be >= {_channelStartIndex} and < {_numInputChannels + _channelStartIndex} on card " + _name);
}
int bitIndex = (int)_signalNameToChannelMap[signalName].channelNumber - _channelStartIndex;
byte latchValue = 0;
ReadLatch(ref latchValue);
BitVector32 bits = new BitVector32(latchValue);
return (IODatatypes.BitState)(bits[bitIndex] ? 1 : 0);
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
lock (_syncObj)
{
if (_state == State.Uninitialized)
{
//@@@ call the other setup functions..Baud? Flow? Timeout? Others?
Open();
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString() + " on card " + _name);
}
}
}
/// <summary>
/// Return list of signal names
/// </summary>
public List<string> GetSignalNames()
{
return new List<string>(_signalNameToChannelMap.Keys);
}
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
///
/// </summary>
public uint NumberOfInputBits
{
get
{
return (uint)_numInputChannels;
}
}
/// <summary>
///
/// </summary>
public uint NumberOfOutputBits
{
get
{
return (uint)_numOutputChannels;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
lock (_syncObj)
{
// card does not support self test
//throw new NotImplementedException("card does not support self test" + " on card " + _name);
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Reset()
{
lock (_syncObj)
{
Close();
Open();
}
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
/// <param name="signalName"></param>
/// <param name="state"> high(open) or low(closed) </param>
///
public void SetBit(string signalName, IODatatypes.BitState state)
{
lock (_syncObj)
{
if (!_signalNameToChannelMap.ContainsKey(signalName))
throw new Exception($"Signal name {signalName} doesn't exist for card: " + _name);
if (_signalNameToChannelMap[signalName].channelNumber >= _numOutputChannels || _signalNameToChannelMap[signalName].channelNumber < _channelStartIndex)
{
throw new Exception($"The output channel number {_signalNameToChannelMap[signalName].channelNumber} specified must be >= {_channelStartIndex} and < {_numOutputChannels + _channelStartIndex} on card " + _name);
}
int bitIndex = (int)_signalNameToChannelMap[signalName].channelNumber - _channelStartIndex;
byte mask = (byte)bitIndex;
if (state == IODatatypes.BitState.High)
{
WriteLatch(mask, 1);
}
else
{
WriteLatch(mask, 0);
}
}
}
/// <summary>
///
/// </summary>
/// <param name="bit"></param>
public void SetTristate(string signalName)
{
lock (_syncObj)
{
//@@@@ Is there a way to do this?
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
lock (_syncObj)
{
if (_state == State.Ready)
{
Close();
_state = State.Uninitialized;
}
}
}
/// <summary>
///
/// </summary>
/// <param name="bit"></param>
/// <param name="frequencyInHz"></param>
/// <param name="dutyCylePercentage"></param>
public void StartClock(uint bit, double frequencyInHz, double dutyCylePercentage)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public void StopClock(uint bit)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
#endregion
}
}

View File

@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)Solution.props" />
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>Raytheon.Instruments.DIOSiUSBXp</AssemblyName>
<RootNamespace>Raytheon.Instruments</RootNamespace>
<Product> implementation</Product>
<Description> 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.GeneralIO.Contracts" Version="1.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DIOSim\DIOSim.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,139 @@
// **********************************************************************************************************
// DIOSiUSBXpFactory.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 = "DIOSiUSBXpFactory")]
public class DIOSiUSBXpFactory : 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 DIOSiUSBXpFactory(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 DIOSiUSBXpFactory([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(IGeneralIO));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
_logger = LogManager.GetLogger(name);
return new DIOSiUSBXp(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 DIOSim(name, _configurationManager, _logger);
else
return new DIOSiUSBXp(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,274 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace SIUSBXP_DLL
{
public class SIUSBXP
{
static IntPtr zero = IntPtr.Zero;
// Return codes
public const byte SI_SUCCESS = 0x00;
public const byte SI_DEVICE_NOT_FOUND = 0xFF;
public const byte SI_INVALID_HANDLE = 0x01;
public const byte SI_READ_ERROR = 0x02;
public const byte SI_RX_QUEUE_NOT_READY = 0x03;
public const byte SI_WRITE_ERROR = 0x04;
public const byte SI_RESET_ERROR = 0x05;
public const byte SI_INVALID_PARAMETER = 0x06;
public const byte SI_INVALID_REQUEST_LENGTH = 0x07;
public const byte SI_DEVICE_IO_FAILED = 0x08;
public const byte SI_INVALID_BAUDRATE = 0x09;
public const byte SI_FUNCTION_NOT_SUPPORTED = 0x0a;
public const byte SI_GLOBAL_DATA_ERROR = 0x0b;
public const byte SI_SYSTEM_ERROR_CODE = 0x0c;
public const byte SI_READ_TIMED_OUT = 0x0d;
public const byte SI_WRITE_TIMED_OUT = 0x0e;
public const byte SI_IO_PENDING = 0x0f;
public const byte SI_NOTHING_TO_CANCEL = 0xa0;
// GetProductString() function flags
public const byte SI_RETURN_SERIAL_NUMBER = 0x00;
public const byte SI_RETURN_DESCRIPTION = 0x01;
public const byte SI_RETURN_LINK_NAME = 0x02;
public const byte SI_RETURN_VID = 0x03;
public const byte SI_RETURN_PID = 0x04;
// RX Queue status flags
public const byte SI_RX_NO_OVERRUN = 0x00;
public const byte SI_RX_EMPTY = 0x00;
public const byte SI_RX_OVERRUN = 0x01;
public const byte SI_RX_READY = 0x02;
// Buffer size limits
public const int SI_MAX_DEVICE_STRLEN = 256;
public const int SI_MAX_READ_SIZE = 4096 * 16;
public const int SI_MAX_WRITE_SIZE = 4096;
// Input and Output pin Characteristics
public const byte SI_HELD_INACTIVE = 0x00;
public const byte SI_HELD_ACTIVE = 0x01;
public const byte SI_FIRMWARE_CONTROLLED = 0x02;
public const byte SI_RECEIVE_FLOW_CONTROL = 0x02;
public const byte SI_TRANSMIT_ACTIVE_SIGNAL = 0x03;
public const byte SI_STATUS_INPUT = 0x00;
public const byte SI_HANDSHAKE_LINE = 0x01;
// Mask and Latch value bit definitions
public const int SI_GPIO_0 = 0x01;
public const int SI_GPIO_1 = 0x02;
public const int SI_GPIO_2 = 0x04;
public const int SI_GPIO_3 = 0x08;
public const int SI_GPIO_4 = 0x0010;
public const int SI_GPIO_5 = 0x0020;
public const int SI_GPIO_6 = 0x0040;
public const int SI_GPIO_7 = 0x0080;
public const int SI_GPIO_8 = 0x0100;
public const int SI_GPIO_9 = 0x0200;
public const int SI_GPIO_10 = 0x0400;
public const int SI_GPIO_11 = 0x0800;
public const int SI_GPIO_12 = 0x1000;
public const int SI_GPIO_13 = 0x2000;
public const int SI_GPIO_14 = 0x4000;
public const int SI_GPIO_15 = 0x8000;
// GetDeviceVersion() return codes
public const byte SI_USBXPRESS_EFM8 = 0x80;
public const byte SI_USBXPRESS_EFM32 = 0x81;
public const byte SI_CP2101_VERSION = 0x01;
public const byte SI_CP2102_VERSION = 0x02;
public const byte SI_CP2103_VERSION = 0x03;
public const byte SI_CP2104_VERSION = 0x04;
public const byte SI_CP2105_VERSION = 0x05;
public const byte SI_CP2108_VERSION = 0x08;
public const byte SI_CP2109_VERSION = 0x09;
public const byte SI_CP2102N_QFN28_VERSION = 0x20;
public const byte SI_CP2102N_QFN24_VERSION = 0x21;
public const byte SI_CP2102N_QFN20_VERSION = 0x22;
[DllImport("SiUSBXp.dll")]
public static extern int SI_GetNumDevices(
ref uint lpdwNumDevices
);
// Caller must set StringBuilder capacity to max possible
// returned string size before calling this function
[DllImport("SiUSBXp.dll")]
public static extern int SI_GetProductString(
uint dwDeviceNum,
StringBuilder lpvDeviceString,
uint dwFlags
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_Open(
uint dwDevice,
ref IntPtr cyHandle
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_Close(
IntPtr cyHandle
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_Read(
IntPtr cyHandle,
[Out] byte[] lpBuffer,
uint dwBytesToRead,
ref uint lpdwBytesReturned,
IntPtr o
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_Write(
IntPtr cyHandle,
[In] byte[] lpBuffer,
uint dwBytesToWrite,
ref uint lpdwBytesWritten,
IntPtr o
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_FlushBuffers(
IntPtr cyHandle,
byte FlushTransmit,
byte FlushReceive
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_SetTimeouts(
uint dwReadTimeoutInMs,
uint dwWriteTimeoutInMs
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_GetTimeouts(
ref uint lpdwReadTimeout,
ref uint lpdwWriteTimeout
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_CheckRXQueue(
IntPtr cyHandle,
ref uint lpdwNumBytesInQueue,
ref uint lpdwQueueStatus
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_SetBaudRate(
IntPtr cyHandle,
uint dwBaudRate
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_SetBaudDivisor(
IntPtr cyHandle,
ushort wBaudDivisor
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_SetLineControl(
IntPtr cyHandle,
ushort wLineControl
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_SetFlowControl(
IntPtr cyHandle,
byte bCTS_MaskCode,
byte bRTS_MaskCode,
byte bDTR_MaskCode,
byte bDSR_MaskCode,
byte bDCD_MaskCode,
bool bFlowXonXoff
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_GetModemStatus(
IntPtr cyHandle,
ref byte ModemStatus
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_SetBreak(
IntPtr cyHandle,
ushort wBreakState
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_ReadLatch(
IntPtr cyHandle,
ref byte lpbLatch
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_WriteLatch(
IntPtr cyHandle,
byte bMask,
byte bLatch
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_GetPartNumber(
IntPtr cyHandle,
ref byte lpbPartNum
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_DeviceIOControl(
IntPtr cyHandle,
uint dwIoControlCode,
[In] byte[] lpInBuffer,
uint dwBytesToRead,
[Out] byte[] lpOutBuffer,
uint dwBytesToWrite,
ref uint lpdwBytesSucceeded
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_GetPartLibraryVersion(
IntPtr cyHandle,
ref int pLibVersion
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_GetInterfaceNumber(
IntPtr cyHandle,
ref byte pLibVersion
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_GetDeviceProductString(
IntPtr cyHandle,
[Out] byte[] lpProduct,
ref byte lpbLength,
bool bConvertToASCII
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_GetDLLVersion(
ref uint HighVersion,
ref uint LowVersion
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_GetDriverVersion(
ref uint HighVersion,
ref uint LowVersion
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_CancelIo(
IntPtr cyHandle
);
[DllImport("SiUSBXp.dll")]
public static extern int SI_CancelIoEx(
IntPtr cyHandle,
IntPtr o
);
}
}