Big changes
This commit is contained in:
718
Source/TSRealLib/HAL/Implementations/DIO/DIOContec/CdioCs.cs
Normal file
718
Source/TSRealLib/HAL/Implementations/DIO/DIOContec/CdioCs.cs
Normal file
@@ -0,0 +1,718 @@
|
||||
//============================================================-
|
||||
// CDIOCS.CS
|
||||
// Class file for CONTEC Digital I/O device
|
||||
// CONTEC.Co.,Ltd.
|
||||
//============================================================-
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public enum CdioConst
|
||||
{
|
||||
//-------------------------------------------------
|
||||
// Type definition
|
||||
//-------------------------------------------------
|
||||
DEVICE_TYPE_ISA = 0, // ISA or C bus
|
||||
DEVICE_TYPE_PC = 1, // PCI bus
|
||||
DEVICE_TYPE_PCMCIA = 2, // PCMCIA
|
||||
DEVICE_TYPE_USB = 3, // USB
|
||||
DEVICE_TYPE_FIT = 4, // FIT
|
||||
DEVICE_TYPE_CARDBUS = 5, // CardBus
|
||||
|
||||
//-------------------------------------------------
|
||||
// Parameters
|
||||
//-------------------------------------------------
|
||||
// I/O(for Sample)
|
||||
DIO_MAX_ACCS_PORTS = 256,
|
||||
// DioNotifyInt:Logic
|
||||
DIO_INT_NONE = 0,
|
||||
DIO_INT_RISE = 1,
|
||||
DIO_INT_FALL = 2,
|
||||
// DioNotifyTrg:TrgKind
|
||||
DIO_TRG_RISE = 1,
|
||||
DIO_TRG_FALL = 2,
|
||||
// Message
|
||||
DIOM_INTERRUPT = 0x1300,
|
||||
DIOM_TRIGGER = 0x1340,
|
||||
DIO_DMM_STOP = 0x1350,
|
||||
DIO_DMM_COUNT = 0x1360,
|
||||
// Device Information
|
||||
IDIO_DEVICE_TYPE = 0, // device type. Param1:short
|
||||
IDIO_NUMBER_OF_8255 = 1, // Number of 8255 chip. Param1:int
|
||||
IDIO_IS_8255_BOARD = 2, // Is 8255 board? Param1:BOOL(True/False)
|
||||
IDIO_NUMBER_OF_DI_BIT = 3, // Number of digital input bit. Param1:int
|
||||
IDIO_NUMBER_OF_DO_BIT = 4, // Number of digital outout bit. Param1:int
|
||||
IDIO_NUMBER_OF_DI_PORT = 5, // Number of digital input port. Param1:int
|
||||
IDIO_NUMBER_OF_DO_PORT = 6, // Number of digital output port. Param1:int
|
||||
IDIO_IS_POSITIVE_LOGIC = 7, // Is positive logic? Param1:BOOL(True/False)
|
||||
IDIO_IS_ECHO_BACK = 8, // Can echo back output port? Param1:BOOL(True/False)
|
||||
IDIO_IS_DIRECTION = 9, // Can DioSetIoDirection function be used? Param1:int(1:true, 0:false)
|
||||
IDIO_IS_FILTER = 10, // Can digital filter be used? Param1:int(1:true, 0:false)
|
||||
IDIO_NUMBER_OF_INT_BIT = 11, // Number of interrupt bit. Param1:short
|
||||
|
||||
// DM
|
||||
// Direction
|
||||
PI_32 = 1,
|
||||
PO_32 = 2,
|
||||
PIO_1616 = 3,
|
||||
DIODM_DIR_IN = 0x1,
|
||||
DIODM_DIR_OUT = 0x2,
|
||||
|
||||
// Start
|
||||
DIODM_START_SOFT = 1,
|
||||
DIODM_START_EXT_RISE = 2,
|
||||
DIODM_START_EXT_FALL = 3,
|
||||
DIODM_START_PATTERN = 4,
|
||||
DIODM_START_EXTSIG_1 = 5,
|
||||
DIODM_START_EXTSIG_2 = 6,
|
||||
DIODM_START_EXTSIG_3 = 7,
|
||||
|
||||
// Clock
|
||||
DIODM_CLK_CLOCK = 1,
|
||||
DIODM_CLK_EXT_TRG = 2,
|
||||
DIODM_CLK_HANDSHAKE = 3,
|
||||
DIODM_CLK_EXTSIG_1 = 4,
|
||||
DIODM_CLK_EXTSIG_2 = 5,
|
||||
DIODM_CLK_EXTSIG_3 = 6,
|
||||
|
||||
// Internal Clock
|
||||
DIODM_TIM_UNIT_S = 1,
|
||||
DIODM_TIM_UNIT_MS = 2,
|
||||
DIODM_TIM_UNIT_US = 3,
|
||||
DIODM_TIM_UNIT_NS = 4,
|
||||
|
||||
// Stop
|
||||
DIODM_STOP_SOFT = 1,
|
||||
DIODM_STOP_EXT_RISE = 2,
|
||||
DIODM_STOP_EXT_FALL = 3,
|
||||
DIODM_STOP_NUM = 4,
|
||||
DIODM_STOP_EXTSIG_1 = 5,
|
||||
DIODM_STOP_EXTSIG_2 = 6,
|
||||
DIODM_STOP_EXTSIG_3 = 7,
|
||||
|
||||
// ExtSig
|
||||
DIODM_EXT_START_SOFT_IN = 1,
|
||||
DIODM_EXT_STOP_SOFT_IN = 2,
|
||||
DIODM_EXT_CLOCK_IN = 3,
|
||||
DIODM_EXT_EXT_TRG_IN = 4,
|
||||
DIODM_EXT_START_EXT_RISE_IN = 5,
|
||||
DIODM_EXT_START_EXT_FALL_IN = 6,
|
||||
DIODM_EXT_START_PATTERN_IN = 7,
|
||||
DIODM_EXT_STOP_EXT_RISE_IN = 8,
|
||||
DIODM_EXT_STOP_EXT_FALL_IN = 9,
|
||||
DIODM_EXT_CLOCK_ERROR_IN = 10,
|
||||
DIODM_EXT_HANDSHAKE_IN = 11,
|
||||
DIODM_EXT_TRNSNUM_IN = 12,
|
||||
|
||||
DIODM_EXT_START_SOFT_OUT = 101,
|
||||
DIODM_EXT_STOP_SOFT_OUT = 102,
|
||||
DIODM_EXT_CLOCK_OUT = 103,
|
||||
DIODM_EXT_EXT_TRG_OUT = 104,
|
||||
DIODM_EXT_START_EXT_RISE_OUT= 105,
|
||||
DIODM_EXT_START_EXT_FALL_OUT= 106,
|
||||
DIODM_EXT_STOP_EXT_RISE_OUT = 107,
|
||||
DIODM_EXT_STOP_EXT_FALL_OUT = 108,
|
||||
DIODM_EXT_CLOCK_ERROR_OUT = 109,
|
||||
DIODM_EXT_HANDSHAKE_OUT = 110,
|
||||
DIODM_EXT_TRNSNUM_OUT = 111,
|
||||
|
||||
// Status
|
||||
DIODM_STATUS_BMSTOP = 0x1,
|
||||
DIODM_STATUS_PIOSTART = 0x2,
|
||||
DIODM_STATUS_PIOSTOP = 0x4,
|
||||
DIODM_STATUS_TRGIN = 0x8,
|
||||
DIODM_STATUS_OVERRUN = 0x10,
|
||||
|
||||
// Error
|
||||
DIODM_STATUS_FIFOEMPTY = 0x1,
|
||||
DIODM_STATUS_FIFOFULL = 0x2,
|
||||
DIODM_STATUS_SGOVERIN = 0x4,
|
||||
DIODM_STATUS_TRGERR = 0x8,
|
||||
DIODM_STATUS_CLKERR = 0x10,
|
||||
DIODM_STATUS_SLAVEHALT = 0x20,
|
||||
DIODM_STATUS_MASTERHALT = 0x40,
|
||||
|
||||
// Reset
|
||||
DIODM_RESET_FIFO_IN = 0x02,
|
||||
DIODM_RESET_FIFO_OUT = 0x04,
|
||||
|
||||
// Buffer Ring
|
||||
DIODM_WRITE_ONCE = 0,
|
||||
DIODM_WRITE_RING = 1,
|
||||
|
||||
//-------------------------------------------------
|
||||
// Error codes
|
||||
//-------------------------------------------------
|
||||
// Initialize Error
|
||||
// Common
|
||||
DIO_ERR_SUCCESS = 0, // normal completed
|
||||
DIO_ERR_INI_RESOURCE = 1, // invalid resource reference specified
|
||||
DIO_ERR_INI_INTERRUPT = 2, // invalid interrupt routine registered
|
||||
DIO_ERR_INI_MEMORY = 3, // invalid memory allocationed
|
||||
DIO_ERR_INI_REGISTRY = 4, // invalid registry accesse
|
||||
|
||||
DIO_ERR_SYS_RECOVERED_FROM_STANDBY = 7, // Execute DioResetDevice function because the device has recovered from standby mode.
|
||||
DIO_ERR_INI_NOT_FOUND_SYS_FILE = 8, // Because the Cdio.sys file is not found, it is not possible to initialize it.
|
||||
DIO_ERR_INI_DLL_FILE_VERSION = 9, // Because version information on the Cdio.dll file cannot be acquired, it is not possible to initialize it.
|
||||
DIO_ERR_INI_SYS_FILE_VERSION = 10, // Because version information on the Cdio.sys file cannot be acquired, it is not possible to initialize it.
|
||||
DIO_ERR_INI_NO_MATCH_DRV_VERSION = 11, // Because version information on Cdio.dll and Cdio.sys is different, it is not possible to initialize it.
|
||||
|
||||
// DLL Error
|
||||
// Common
|
||||
DIO_ERR_DLL_DEVICE_NAME = 10000, // invalid device name specified.
|
||||
DIO_ERR_DLL_INVALID_ID = 10001, // invalid ID specified.
|
||||
DIO_ERR_DLL_CALL_DRIVER = 10002, // not call the driver.(Invalid device I/O controller)
|
||||
DIO_ERR_DLL_CREATE_FILE = 10003, // not create the file.(Invalid CreateFile)
|
||||
DIO_ERR_DLL_CLOSE_FILE = 10004, // not close the file.(Invalid CloseFile)
|
||||
DIO_ERR_DLL_CREATE_THREAD = 10005, // not create the thread.(Invalid CreateThread)
|
||||
DIO_ERR_INFO_INVALID_DEVICE = 10050, // invalid device infomation specified .Please check the spell.
|
||||
DIO_ERR_INFO_NOT_FIND_DEVICE = 10051, // not find the available device
|
||||
DIO_ERR_INFO_INVALID_INFOTYPE = 10052, // specified device infomation type beyond the limit
|
||||
|
||||
// DIO
|
||||
DIO_ERR_DLL_BUFF_ADDRESS = 10100, // invalid data buffer address
|
||||
DIO_ERR_DLL_HWND = 10200, // window handle beyond the limit
|
||||
DIO_ERR_DLL_TRG_KIND = 10300, // trigger kind beyond the limit
|
||||
|
||||
// SYS Error
|
||||
// Common
|
||||
DIO_ERR_SYS_MEMORY = 20000, // not secure memory
|
||||
DIO_ERR_SYS_NOT_SUPPORTED = 20001, // this board couldn't use this function
|
||||
DIO_ERR_SYS_BOARD_EXECUTING = 20002, // board is behaving, not execute
|
||||
DIO_ERR_SYS_USING_OTHER_PROCESS = 20003, // other process is using the device, not execute
|
||||
|
||||
STATUS_SYS_USB_CRC = 20020, // the last data packet received from end point exist CRC error
|
||||
STATUS_SYS_USB_BTSTUFF = 20021, // the last data packet received from end point exist bit stuffing offense error
|
||||
STATUS_SYS_USB_DATA_TOGGLE_MISMATCH = 20022, // the last data packet received from end point exist toggle packet mismatch error
|
||||
STATUS_SYS_USB_STALL_PID = 20023, // end point return STALL packet identifier
|
||||
STATUS_SYS_USB_DEV_NOT_RESPONDING = 20024, // device don't respond to token(IN), don't support handshake
|
||||
STATUS_SYS_USB_PID_CHECK_FAILURE = 20025,
|
||||
STATUS_SYS_USB_UNEXPECTED_PID = 20026, // invalid packet identifier received
|
||||
STATUS_SYS_USB_DATA_OVERRUN = 20027, // end point return data quantity overrun
|
||||
STATUS_SYS_USB_DATA_UNDERRUN = 20028, // end point return data quantity underrun
|
||||
STATUS_SYS_USB_BUFFER_OVERRUN = 20029, // IN transmit specified buffer overrun
|
||||
STATUS_SYS_USB_BUFFER_UNDERRUN = 20030, // OUT transmit specified buffer underrun
|
||||
STATUS_SYS_USB_ENDPOINT_HALTED = 20031, // end point status is STALL, not transmit
|
||||
STATUS_SYS_USB_NOT_FOUND_DEVINFO = 20032, // not found device infomation
|
||||
STATUS_SYS_USB_ACCESS_DENIED = 20033, // Access denied
|
||||
STATUS_SYS_USB_INVALID_HANDLE = 20034, // Invalid handle
|
||||
|
||||
// DIO
|
||||
DIO_ERR_SYS_PORT_NO = 20100, // board No. beyond the limit
|
||||
DIO_ERR_SYS_PORT_NUM = 20101, // board number beyond the limit
|
||||
DIO_ERR_SYS_BIT_NO = 20102, // bit No. beyond the limit
|
||||
DIO_ERR_SYS_BIT_NUM = 20103, // bit number beyond the limit
|
||||
DIO_ERR_SYS_BIT_DATA = 20104, // bit data beyond the limit of 0 to 1
|
||||
DIO_ERR_SYS_INT_BIT = 20200, // interrupt bit beyond the limit
|
||||
DIO_ERR_SYS_INT_LOGIC = 20201, // interrupt logic beyond the limit
|
||||
DIO_ERR_SYS_TIM = 20300, // timer value beyond the limit
|
||||
DIO_ERR_SYS_FILTER = 20400, // filter number beyond the limit
|
||||
DIO_ERR_SYS_IODIRECTION = 20500, // Direction value is out of range
|
||||
|
||||
// DM
|
||||
DIO_ERR_SYS_SIGNAL = 21000, // Usable signal is outside the setting range.
|
||||
DIO_ERR_SYS_START = 21001, // Usable start conditions are outside the setting range.
|
||||
DIO_ERR_SYS_CLOCK = 21002, // Clock conditions are outside the setting range.
|
||||
DIO_ERR_SYS_CLOCK_VAL = 21003, // Clock value is outside the setting range.
|
||||
DIO_ERR_SYS_CLOCK_UNIT = 21004, // Clock value unit is outside the setting range.
|
||||
DIO_ERR_SYS_STOP = 21005, // Stop conditions are outside the setting range.
|
||||
DIO_ERR_SYS_STOP_NUM = 21006, // Stop number is outside the setting range.
|
||||
DIO_ERR_SYS_RESET = 21007, // Contents of reset are outside the setting range.
|
||||
DIO_ERR_SYS_LEN = 21008, // Data number is outside the setting range.
|
||||
DIO_ERR_SYS_RING = 21009, // Buffer repetition use setup is outside the setting range.
|
||||
DIO_ERR_SYS_COUNT = 21010, // Data transmission number is outside the setting range.
|
||||
DIO_ERR_DM_BUFFER = 21100, // Buffer was too large and has not secured.
|
||||
DIO_ERR_DM_LOCK_MEMORY = 21101, // Memory has not been locked.
|
||||
DIO_ERR_DM_PARAM = 21102, // Parameter error
|
||||
DIO_ERR_DM_SEQUENCE = 21103 // Procedure error of execution
|
||||
}
|
||||
|
||||
namespace CdioCs
|
||||
{
|
||||
//unsafe public delegate void PINTCALLBACK(short Id, int wParam, int lParam, void *Param);
|
||||
//unsafe public delegate void PTRGCALLBACK(short Id, int wParam, int lParam, void *Param);
|
||||
//unsafe public delegate void PDMCOUNTCALLBACK(short Id, int wParam, int lParam, void *Param);
|
||||
//unsafe public delegate void PDMSTOPCALLBACK(short Id, int wParam, int lParam, void *Param);
|
||||
|
||||
public class Cdio
|
||||
{
|
||||
// Definition of common functions
|
||||
[DllImport("cdio.dll")] static extern int DioInit(string DeviceName, ref short Id);
|
||||
[DllImport("cdio.dll")] static extern int DioExit(short Id);
|
||||
[DllImport("cdio.dll")] static extern int DioResetDevice(short Id);
|
||||
[DllImport("cdio.dll")] static extern int DioGetErrorString(int ErrorCode, System.Text.StringBuilder ErrorString);
|
||||
|
||||
// Digital filter functions
|
||||
[DllImport("cdio.dll")] static extern int DioSetDigitalFilter(short Id, short FilterValue);
|
||||
[DllImport("cdio.dll")] static extern int DioGetDigitalFilter(short Id, ref short FilterValue);
|
||||
|
||||
// I/O Direction functions
|
||||
[DllImport("cdio.dll")] static extern int DioSetIoDirection(short Id, uint dwDir);
|
||||
[DllImport("cdio.dll")] static extern int DioGetIoDirection(short Id, ref uint dwDir);
|
||||
[DllImport("cdio.dll")] static extern int DioSetIoDirectionEx(short Id, uint dwDir);
|
||||
[DllImport("cdio.dll")] static extern int DioGetIoDirectionEx(short Id, ref uint dwDir);
|
||||
[DllImport("cdio.dll")] static extern int DioSet8255Mode(short Id, short ChipNo, short CtrlWord);
|
||||
[DllImport("cdio.dll")] static extern int DioGet8255Mode(short Id, short ChipNo, ref short CtrlWord);
|
||||
|
||||
// Simple I/O functions
|
||||
[DllImport("cdio.dll")] static extern int DioInpByte(short Id, short PortNo, ref byte Data);
|
||||
[DllImport("cdio.dll")] static extern int DioInpBit(short Id, short BitNo, ref byte Data);
|
||||
[DllImport("cdio.dll")] static extern int DioOutByte(short Id, short PortNo, byte Data);
|
||||
[DllImport("cdio.dll")] static extern int DioOutBit(short Id, short BitNo, byte Data);
|
||||
[DllImport("cdio.dll")] static extern int DioEchoBackByte(short Id, short PortNo, ref byte Data);
|
||||
[DllImport("cdio.dll")] static extern int DioEchoBackBit(short Id, short BitNo, ref byte Data);
|
||||
|
||||
// Multiple I/O functions
|
||||
[DllImport("cdio.dll")] static extern int DioInpMultiByte(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] PortNo, short PortNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
|
||||
[DllImport("cdio.dll")] static extern int DioInpMultiBit(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] BitNo, short BitNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
|
||||
[DllImport("cdio.dll")] static extern int DioOutMultiByte(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] PortNo, short PortNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
|
||||
[DllImport("cdio.dll")] static extern int DioOutMultiBit(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] BitNo, short BitNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
|
||||
[DllImport("cdio.dll")] static extern int DioEchoBackMultiByte(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] PortNo, short PortNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
|
||||
[DllImport("cdio.dll")] static extern int DioEchoBackMultiBit(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] BitNo, short BitNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
|
||||
|
||||
// Interrupt functions
|
||||
[DllImport("cdio.dll")] static extern int DioNotifyInterrupt(short Id, short IntBit, short Logic, int hWnd);
|
||||
//[DllImport("cdio.dll")] unsafe static extern int DioSetInterruptCallBackProc(short Id, PINTCALLBACK pIntCallBack, void *Param);
|
||||
|
||||
// Trigger functions
|
||||
[DllImport("cdio.dll")] static extern int DioNotifyTrg(short Id, short TrgBit, short TrgKind, int Tim, int hWnd);
|
||||
[DllImport("cdio.dll")] static extern int DioStopNotifyTrg(short Id, short TrgBit);
|
||||
//[DllImport("cdio.dll")] static extern int DioSetTrgCallBackProc(short Id, PTRGCALLBACK CallBackProc, ref int Param);
|
||||
|
||||
// Information functions
|
||||
[DllImport("cdio.dll")] static extern int DioGetDeviceInfo(string Device, short InfoType, ref int Param1, ref int Param2, ref int Param3);
|
||||
[DllImport("cdio.dll")] static extern int DioQueryDeviceName(short Index, System.Text.StringBuilder DeviceName, System.Text.StringBuilder Device);
|
||||
[DllImport("cdio.dll")] static extern int DioGetDeviceType(string Device, ref short DeviceType);
|
||||
[DllImport("cdio.dll")] static extern int DioGetMaxPorts(short Id, ref short InPortNum, ref short OutPortNum);
|
||||
|
||||
//dm functions
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetDirection(short Id, short Direction);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmGetDirection(short Id, ref short Direction);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetStandAlone(short Id);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetMaster(short Id, short ExtSig1, short ExtSig2, short ExtSig3, short MasterHalt, short SlaveHalt);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetSlave(short Id, short ExtSig1, short ExtSig2, short ExtSig3, short MasterHalt, short SlaveHalt);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetStartTrigger(short Id, short Direction, short Start);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetStartPattern(short Id, uint Pattern, uint Mask);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetClockTrigger(short Id, short Direction, short Clock);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetInternalClock(short Id, short Direction, uint Clock, short Unit);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetStopTrigger(short Id, short Direction, short Stop);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetStopNumber(short Id, short Direction, uint StopNumber);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmFifoReset(short Id, short Reset);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetBuffer(short Id, short Direction, IntPtr Buffer, uint Length, short IsRing);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetTransferStartWait(short Id, short Time);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmTransferStart(short Id, short Direction);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmTransferStop(short Id, short Direction);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmGetStatus(short Id, short Direction, ref uint Status, ref uint Err);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmGetCount(short Id, short Direction, ref uint Count, ref uint Carry);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmGetWritePointer(short Id, short Direction, ref uint WritePointer, ref uint Count, ref uint Carry);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetStopEvent(short Id, short Direction, int hWnd);
|
||||
//[DllImport("cdio.DLL")] unsafe static extern int DioDmSetStopCallBackProc(short Id, PDMSTOPCALLBACK CallBackProc, void *Param);
|
||||
[DllImport("cdio.DLL")] static extern int DioDmSetCountEvent(short Id, short Direction, uint Count, int hWnd);
|
||||
//[DllImport("cdio.DLL")] unsafe static extern int DioDmSetCountCallBackProc(short Id, PDMCOUNTCALLBACK CallBackProc, void *Param);
|
||||
|
||||
// Demo Device I/O functions
|
||||
[DllImport("cdio.dll")] static extern int DioSetDemoByte(short Id, short PortNo, byte Data);
|
||||
[DllImport("cdio.dll")] static extern int DioSetDemoBit(short Id, short BitNo, byte Data);
|
||||
|
||||
// Constructor
|
||||
public Cdio()
|
||||
{
|
||||
}
|
||||
|
||||
// Description of common functions
|
||||
public int Init(string DeviceName, out short Id)
|
||||
{
|
||||
Id = 0;
|
||||
int ret = DioInit(DeviceName, ref Id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int Exit(short Id)
|
||||
{
|
||||
int ret = DioExit(Id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int ResetDevice(short Id)
|
||||
{
|
||||
int ret = DioResetDevice(Id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int GetErrorString(int ErrorCode, out string ErrorString)
|
||||
{
|
||||
ErrorString = new String('0', 1);
|
||||
System.Text.StringBuilder errorstring = new System.Text.StringBuilder(256);
|
||||
int ret = DioGetErrorString(ErrorCode, errorstring);
|
||||
if(ret == 0)
|
||||
{
|
||||
ErrorString = errorstring.ToString();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Digital filter functions
|
||||
public int SetDigitalFilter(short Id, short FilterValue)
|
||||
{
|
||||
int ret = DioSetDigitalFilter(Id, FilterValue);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int GetDigitalFilter(short Id, out short FilterValue)
|
||||
{
|
||||
FilterValue = 0;
|
||||
int ret = DioGetDigitalFilter(Id, ref FilterValue);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// I/O Direction functions
|
||||
public int SetIoDirection(short Id, uint dwDir)
|
||||
{
|
||||
int ret = DioSetIoDirection(Id, dwDir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int GetIoDirection(short Id, out uint dwDir)
|
||||
{
|
||||
dwDir = 0;
|
||||
int ret = DioGetIoDirection(Id, ref dwDir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int Set8255Mode(short Id, short ChipNo, short CtrlWord)
|
||||
{
|
||||
int ret = DioSet8255Mode(Id, ChipNo, CtrlWord);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int Get8255Mode(short Id, short ChipNo, out short CtrlWord)
|
||||
{
|
||||
CtrlWord = 0;
|
||||
int ret = DioGet8255Mode(Id, ChipNo, ref CtrlWord);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int SetIoDirectionEx(short Id, uint dwDir)
|
||||
{
|
||||
int ret = DioSetIoDirectionEx(Id, dwDir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int GetIoDirectionEx(short Id, out uint dwDir)
|
||||
{
|
||||
dwDir = 0;
|
||||
int ret = DioGetIoDirectionEx(Id, ref dwDir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Simple I/O functions
|
||||
public int InpByte(short Id, short PortNo, out byte Data)
|
||||
{
|
||||
Data = 0;
|
||||
int ret = DioInpByte(Id, PortNo, ref Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int InpBit(short Id, short BitNo, out byte Data)
|
||||
{
|
||||
Data = 0;
|
||||
int ret = DioInpBit(Id, BitNo, ref Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int OutByte(short Id, short PortNo, byte Data)
|
||||
{
|
||||
int ret = DioOutByte(Id, PortNo, Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int OutBit(short Id, short BitNo, byte Data)
|
||||
{
|
||||
int ret = DioOutBit(Id, BitNo, Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int EchoBackByte(short Id, short PortNo, out byte Data)
|
||||
{
|
||||
Data = 0;
|
||||
int ret = DioEchoBackByte(Id, PortNo, ref Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int EchoBackBit(short Id, short BitNo, out byte Data)
|
||||
{
|
||||
Data = 0;
|
||||
int ret = DioEchoBackBit(Id, BitNo, ref Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Multiple I/O functions
|
||||
public int InpMultiByte(short Id, short[] PortNo, short PortNum, byte[] Data)
|
||||
{
|
||||
int ret = DioInpMultiByte(Id, PortNo, PortNum, Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int InpMultiBit(short Id, short[] BitNo, short BitNum, byte[] Data)
|
||||
{
|
||||
int ret = DioInpMultiBit(Id, BitNo, BitNum, Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int OutMultiByte(short Id, short[] PortNo, short PortNum, byte[] Data)
|
||||
{
|
||||
int ret = DioOutMultiByte(Id, PortNo, PortNum, Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int OutMultiBit(short Id, short[] BitNo, short BitNum, byte[] Data)
|
||||
{
|
||||
int ret = DioOutMultiBit(Id, BitNo, BitNum, Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int EchoBackMultiByte(short Id, short[] PortNo, short PortNum, byte[] Data)
|
||||
{
|
||||
int ret = DioEchoBackMultiByte(Id, PortNo, PortNum, Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int EchoBackMultiBit(short Id, short[] BitNo, short BitNum, byte[] Data)
|
||||
{
|
||||
int ret = DioEchoBackMultiBit(Id, BitNo, BitNum, Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Interrupt functions
|
||||
public int NotifyInterrupt(short Id, short IntBit, short Logic, int hWnd)
|
||||
{
|
||||
int ret = DioNotifyInterrupt(Id, IntBit, Logic, hWnd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//unsafe public int SetInterruptCallBackProc(short Id, PINTCALLBACK pIntCallBack, void *Param)
|
||||
//{
|
||||
// int ret = DioSetInterruptCallBackProc(Id, pIntCallBack, Param);
|
||||
// return ret;
|
||||
//}
|
||||
|
||||
// Trigger functions
|
||||
public int NotifyTrg(short Id, short TrgBit, short TrgKind, int Tim, int hWnd)
|
||||
{
|
||||
int ret = DioNotifyTrg(Id, TrgBit, TrgKind, Tim, hWnd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int StopNotifyTrg(short Id, short TrgBit)
|
||||
{
|
||||
int ret = DioStopNotifyTrg(Id, TrgBit);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//public int SetTrgCallBackProc(short Id, PTRGCALLBACK CallBackProc, out int Param)
|
||||
//{
|
||||
// Param = 0;
|
||||
// int ret = DioSetTrgCallBackProc(Id, CallBackProc, ref Param);
|
||||
// return ret;
|
||||
//}
|
||||
|
||||
// Information functions
|
||||
public int GetDeviceInfo(string Device, short InfoType, out int Param1, out int Param2, out int Param3)
|
||||
{
|
||||
Param1 = 0;
|
||||
Param2 = 0;
|
||||
Param3 = 0;
|
||||
int ret = DioGetDeviceInfo(Device, InfoType, ref Param1, ref Param2, ref Param3);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int QueryDeviceName(short Index, out string DeviceName, out string Device)
|
||||
{
|
||||
DeviceName = new String('0', 1);
|
||||
Device = new String('0', 1);
|
||||
System.Text.StringBuilder devicename = new System.Text.StringBuilder(256);
|
||||
System.Text.StringBuilder device = new System.Text.StringBuilder(256);
|
||||
int ret = DioQueryDeviceName(Index, devicename, device);
|
||||
if(ret == 0)
|
||||
{
|
||||
DeviceName = devicename.ToString();
|
||||
Device = device.ToString();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int GetDeviceType(string Device, out short DeviceType)
|
||||
{
|
||||
DeviceType = 0;
|
||||
int ret = DioGetDeviceType(Device, ref DeviceType);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int GetMaxPorts(short Id, out short InPortNum, out short OutPortNum)
|
||||
{
|
||||
InPortNum = 0;
|
||||
OutPortNum = 0;
|
||||
int ret = DioGetMaxPorts(Id, ref InPortNum, ref OutPortNum);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetDirection(short Id, short Direction)
|
||||
{
|
||||
int ret = DioDmSetDirection(Id, Direction);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmGetDirection(short Id, out short Direction)
|
||||
{
|
||||
Direction = 0;
|
||||
int ret = DioDmGetDirection(Id, ref Direction);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetStandAlone(short Id)
|
||||
{
|
||||
int ret = DioDmSetStandAlone(Id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetMaster(short Id, short ExtSig1, short ExtSig2, short ExtSig3, short MasterHalt, short SlaveHalt)
|
||||
{
|
||||
int ret = DioDmSetMaster(Id, ExtSig1, ExtSig2, ExtSig3, MasterHalt, SlaveHalt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetSlave(short Id, short ExtSig1, short ExtSig2, short ExtSig3, short MasterHalt, short SlaveHalt)
|
||||
{
|
||||
int ret = DioDmSetSlave(Id, ExtSig1, ExtSig2, ExtSig3, MasterHalt, SlaveHalt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetStartTrigger(short Id, short Direction, short Start)
|
||||
{
|
||||
int ret = DioDmSetStartTrigger(Id, Direction, Start);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetStartPattern(short Id, uint Pattern, uint Mask)
|
||||
{
|
||||
int ret = DioDmSetStartPattern(Id, Pattern, Mask);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetClockTrigger(short Id, short Direction, short Clock)
|
||||
{
|
||||
int ret = DioDmSetClockTrigger(Id, Direction, Clock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetInternalClock(short Id, short Direction, uint Clock, short Unit)
|
||||
{
|
||||
int ret = DioDmSetInternalClock(Id, Direction, Clock, Unit);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetStopTrigger(short Id, short Direction, short Stop)
|
||||
{
|
||||
int ret = DioDmSetStopTrigger(Id, Direction, Stop);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetStopNumber(short Id, short Direction, uint StopNumber)
|
||||
{
|
||||
int ret = DioDmSetStopNumber(Id, Direction, StopNumber);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmFifoReset(short Id, short Reset)
|
||||
{
|
||||
int ret = DioDmFifoReset(Id, Reset);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetBuffer(short Id, short Direction, IntPtr Buffer, uint Length, short IsRing)
|
||||
{
|
||||
int ret = DioDmSetBuffer(Id, Direction, Buffer, Length, IsRing);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetTransferStartWait(short Id, short Time)
|
||||
{
|
||||
int ret = DioDmSetTransferStartWait(Id, Time);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmTransferStart(short Id, short Direction)
|
||||
{
|
||||
int ret = DioDmTransferStart(Id, Direction);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmTransferStop(short Id, short Direction)
|
||||
{
|
||||
int ret = DioDmTransferStop(Id, Direction);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmGetStatus(short Id, short Direction, out uint Status, out uint Err)
|
||||
{
|
||||
Status = 0;
|
||||
Err = 0;
|
||||
int ret = DioDmGetStatus(Id, Direction, ref Status, ref Err);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmGetCount(short Id, short Direction, out uint Count, out uint Carry)
|
||||
{
|
||||
Count = 0;
|
||||
Carry = 0;
|
||||
int ret = DioDmGetCount(Id, Direction, ref Count, ref Carry);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmGetWritePointer(short Id, short Direction, out uint WritePointer, out uint Count, out uint Carry)
|
||||
{
|
||||
WritePointer = 0;
|
||||
Count = 0;
|
||||
Carry = 0;
|
||||
int ret = DioDmGetWritePointer(Id, Direction, ref WritePointer, ref Count, ref Carry);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int DmSetStopEvent(short Id, short Direction, int hWnd)
|
||||
{
|
||||
int ret = DioDmSetStopEvent(Id, Direction, hWnd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//unsafe public int DmSetStopCallBackProc(short Id, PDMSTOPCALLBACK CallBackProc, void *Param)
|
||||
//{
|
||||
// int ret = DioDmSetStopCallBackProc(Id, CallBackProc, Param);
|
||||
// return ret;
|
||||
//}
|
||||
|
||||
public int DmSetCountEvent(short Id, short Direction, uint Count, int hWnd)
|
||||
{
|
||||
int ret = DioDmSetCountEvent(Id, Direction, Count, hWnd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//unsafe public int DmSetCountCallBackProc(short Id, PDMCOUNTCALLBACK CallBackProc, void *Param)
|
||||
//{
|
||||
// int ret = DioDmSetCountCallBackProc(Id, CallBackProc, Param);
|
||||
// return ret;
|
||||
//}
|
||||
|
||||
public int SetDemoByte(short Id, short PortNo, byte Data)
|
||||
{
|
||||
int ret = DioSetDemoByte(Id, PortNo, Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int SetDemoBit(short Id, short BitNo, byte Data)
|
||||
{
|
||||
int ret = DioSetDemoBit(Id, BitNo, Data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
613
Source/TSRealLib/HAL/Implementations/DIO/DIOContec/DIOContec.cs
Normal file
613
Source/TSRealLib/HAL/Implementations/DIO/DIOContec/DIOContec.cs
Normal file
@@ -0,0 +1,613 @@
|
||||
// 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 CdioCs;
|
||||
using Raytheon.Instruments.GeneralIO;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using System.ComponentModel.Composition.Primitives;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that implements a Contec DIO card
|
||||
/// </summary>
|
||||
public class DIOContec : IGeneralIO, IDisposable
|
||||
{
|
||||
#region PrivateClassMembers
|
||||
private Cdio _dio;
|
||||
private short _id;
|
||||
private string _name;
|
||||
private string _address;
|
||||
private SelfTestResult _selfTestResult;
|
||||
private State _state;
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object's resources
|
||||
/// </summary>
|
||||
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
Reset();
|
||||
|
||||
_dio.Exit(_id);
|
||||
|
||||
_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>
|
||||
/// Invert Contec DIO bits.
|
||||
/// </summary>
|
||||
private byte InvertBit(byte bitValue)
|
||||
{
|
||||
if (bitValue == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (bitValue == 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unexpected input value: " + bitValue.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PublicClassFunctions
|
||||
|
||||
/// <summary>
|
||||
/// DIOContec factory constructor
|
||||
/// </summary>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="configurationManager"></param>
|
||||
public DIOContec(string deviceName, IConfigurationManager configurationManager, ILogger logger)
|
||||
{
|
||||
Name = deviceName;
|
||||
|
||||
_logger = logger;
|
||||
|
||||
_configurationManager = configurationManager;
|
||||
_configuration = _configurationManager.GetConfiguration(Name);
|
||||
|
||||
_address = _configuration.GetConfigurationValue("DIOContec", "Address", "");
|
||||
|
||||
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);
|
||||
|
||||
_address = dioModuleConfig.ReadValue(Name, ConfigIni.DIO_ADDRESS.ToString());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
|
||||
_state = State.Uninitialized;
|
||||
|
||||
// set in Initialize()
|
||||
_dio = null;
|
||||
_id = -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor which opens a handle to the DIO instrument and resets it.
|
||||
/// Note that all signals on the Contec DIO card are inverted.
|
||||
/// This class masks the inversion so that the caller does not have to deal with it.
|
||||
/// </summary>
|
||||
public DIOContec(string name, string address, List<uint> inputPins, List<uint> outputPins)
|
||||
{
|
||||
_name = name;
|
||||
|
||||
_address = address;
|
||||
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
_selfTestResult = SelfTestResult.Unknown;
|
||||
|
||||
_state = State.Uninitialized;
|
||||
|
||||
// set in Initialize()
|
||||
_dio = null;
|
||||
_id = -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The finalizer.
|
||||
/// </summary>
|
||||
~DIOContec()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool ClearErrors()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DetailedStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This is a Contec DIO Card " + _name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool DisplayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object's resources.
|
||||
/// </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 input channel number {_signalNameToChannelMap[signalName].channelNumber} specified must be >= {_channelStartIndex} and < {_numInputChannels + _channelStartIndex} on card " + _name);
|
||||
}
|
||||
|
||||
int bitIndex = (int)_signalNameToChannelMap[signalName].channelNumber - _channelStartIndex;
|
||||
|
||||
byte dioData = 0;
|
||||
|
||||
int ret = _dio.InpBit(_id, (short)bitIndex, out dioData);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
string errorString = "";
|
||||
|
||||
_dio.GetErrorString(ret, out errorString);
|
||||
|
||||
throw new Exception("call to InpBit returned error: " + ret.ToString() + ", " + errorString + " on card " + _name);
|
||||
}
|
||||
|
||||
return (IODatatypes.BitState)InvertBit(dioData);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get state of an output signal. The contec DIO states are inverted.
|
||||
/// This function masks the inversion before returning.
|
||||
/// </summary>
|
||||
/// <param name="bitno">The bit number of the signal.</param>
|
||||
/// <returns>The state of the signal. 0 for low, 1 for high.</returns>
|
||||
/*public DioMeasurementInstruments.SignalState GetOutputSignalState(uint bitno)
|
||||
{
|
||||
byte dioData = 0;
|
||||
|
||||
int ret = _dio.EchoBackBit(_id, (short)bitno, out dioData);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
string errorString = "";
|
||||
|
||||
_dio.GetErrorString(ret, out errorString);
|
||||
|
||||
throw new Exception("call to EchoBackBit returned error: " + ret.ToString() + ", " + errorString);
|
||||
}
|
||||
|
||||
dioData = InvertBit(dioData);
|
||||
|
||||
if (dioData == 0)
|
||||
{
|
||||
return DioMeasurementInstruments.SignalState.LOW;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DioMeasurementInstruments.SignalState.HIGH;
|
||||
}
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public InstrumentMetadata Info
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_state == State.Uninitialized)
|
||||
{
|
||||
_dio = new Cdio();
|
||||
|
||||
int ret = _dio.Init(_address, out _id);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
string errorString = "";
|
||||
|
||||
_dio.GetErrorString(ret, out errorString);
|
||||
|
||||
throw new Exception("call to Init returned error: " + ret.ToString() + ", " + errorString + " on card " + _name);
|
||||
}
|
||||
|
||||
Reset();
|
||||
|
||||
if (_shallWeInitializeOutput)
|
||||
{
|
||||
foreach (KeyValuePair<string, IODatatypes.DIOChannelInfo> item in _signalNameToChannelMap)
|
||||
{
|
||||
if (item.Value.initialValue != -1)
|
||||
{
|
||||
SetBit(item.Key, (IODatatypes.BitState)item.Value.initialValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_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()
|
||||
{
|
||||
// card does not support self test
|
||||
throw new NotImplementedException("card does not support self test" + " on card " + _name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
int ret = _dio.ResetDevice(_id);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
string errorString = "";
|
||||
|
||||
_dio.GetErrorString(ret, out errorString);
|
||||
|
||||
throw new Exception("call to ResetDevice returned error: " + ret.ToString() + ", " + errorString + " on card " + _name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <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;
|
||||
|
||||
int ret = _dio.OutBit(_id, (short)bitIndex, InvertBit((byte)state));
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
string errorString = "";
|
||||
|
||||
_dio.GetErrorString(ret, out errorString);
|
||||
|
||||
throw new Exception("call to OutBit returned error: " + ret.ToString() + ", " + errorString + " on card " + _name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="bit"></param>
|
||||
public void SetTristate(string signalName)
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <param name="bit"></param>
|
||||
public void StopClock(uint bit)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public State Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
{
|
||||
lock (_syncObj)
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
Reset();
|
||||
|
||||
_dio.Exit(_id);
|
||||
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="$(SolutionDir)Solution.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>Raytheon.Instruments.DIOContec</AssemblyName>
|
||||
<Product>DIO Contec implementation</Product>
|
||||
<Description>Digital IO Contec 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>
|
||||
@@ -0,0 +1,141 @@
|
||||
// **********************************************************************************************************
|
||||
// DIOContecFactory.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)
|
||||
// **********************************************************************************************************
|
||||
// Ignore Spelling: Contec
|
||||
|
||||
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 = "DIOContecFactory")]
|
||||
public class DIOContecFactory : 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 DIOContecFactory(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 DIOContecFactory([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 DIOContec(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 DIOContec(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user