using System; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Text; namespace pac8014WNet { public enum ErrorCode { NoError = (Int16)0, ID_ERROR = (Int16)(-1), SLOT_ERROR = (Int16)(-2), CHANNEL_ERROR = (Int16)(-3), GAIN_ERROR = (Int16)(-4), FIFO_EMPTY = (Int16)(-5), FIFO_LATCHED = (Int16)(-6), FIFO_OVERFLOW = (Int16)(-7), TX_NOTREADY = (Int16)(-8), MAX_FIFO = (Int16)4096 } public class pac8014W { public delegate void IsrFunction(int slot); private class ICPDAS { [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_Init")] public static extern Int16 pac_i8014W_Init(Int16 slot); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_GetLibVersion")] public static extern Int16 pac_i8014W_GetLibVersion(); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_GetLibDate")] public static extern void pac_i8014W_GetLibDate(byte[] libDate); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_GetFirmwareVer_L1")] public static extern Int16 pac_i8014W_GetFirmwareVer_L1(Int16 slot); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_GetFirmwareVer_L2")] public static extern Int16 pac_i8014W_GetFirmwareVer_L2(Int16 slot); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_GetSingleEndJumper")] public static extern Int16 pac_i8014W_GetSingleEndJumper(Int16 slot); //[DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_SelectedImpedency")] //public static extern void pac_i8014W_SelectedImpedency(Int16 slot,Int16 resistorType); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_ReadGainOffset")] public static extern void pac_i8014W_ReadGainOffset(Int16 slot,Int16 gain, ref UInt16 gainValue,ref Int16 offsetValue); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_ReadAIHex")] public static extern Int16 pac_i8014W_ReadAIHex(Int16 slot,Int16 ch,Int16 gain, ref Int16 hVal); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_ReadAI")] public static extern Int16 pac_i8014W_ReadAI(Int16 slot,Int16 ch,Int16 gain, ref float fVal); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_ClearFIFO")] public static extern void pac_i8014W_ClearFIFO(Int16 slot); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_UnLockFIFO")] public static extern void pac_i8014W_UnLockFIFO(Int16 slot); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_ConfigMagicScan")] public static extern void pac_i8014W_ConfigMagicScan(Int16 slot,Int16[] chArr,Int16[] gainArr,Int16 scanChCount,float sampleRate,Int16 scanMode,Int16 triggerSource,Int16 triggerState,ref float realSampleRate); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_StartMagicScan")] public static extern Int16 pac_i8014W_StartMagicScan(Int16 slot); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_StopMagicScan")] public static extern Int16 pac_i8014W_StopMagicScan(Int16 slot); //short i8014W_ReadFIFO_BlockMode(int slot, short hexData[], long readCount ,long* dataCountFromFIFO)// <=== get data from FIFO ,long* dataCnt [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_ReadFIFO_BlockMode")] public static extern Int16 pac_i8014W_ReadFIFO_BlockMode(Int16 slot, Int16[] hexData, Int32 readCount, ref Int32 dataCountFromFIFO);// <=== get data from FIFO ,long* dataCnt [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_ReadFIFO")] public static extern Int16 pac_i8014W_ReadFIFO(Int16 slot, Int16[] hexData, Int16 readCount, ref Int16 dataCountFromFIFO);// <=== get data from FIFO ,long* dataCnt [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_ReadFIFO_InISR")] public static extern Int16 pac_i8014W_ReadFIFO_InISR(Int16 slot, Int16[] hexData, Int16 readCount, ref Int16 dataCountFromFIFO); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_CalibrateDataHex")] public static extern void pac_i8014W_CalibrateDataHex(Int16 slot, Int16 iGain,Int16 dataFromFIFO,ref Int16 calibratedAI); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_CalibrateData")] public static extern void pac_i8014W_CalibrateData(Int16 slot, Int16 iGain,Int16 dataFromFIFO,ref float calibratedAI); // public delegate void IsrFunction(int slot); [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_InstallMagicScanISR")] public static extern Int16 pac_i8014W_InstallMagicScanISR(Int16 slot, IsrFunction isr, Int16 triggerLevel); //<=== give a callback function for interrupt [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_UnInstallMagicScanISR")] public static extern Int16 pac_i8014W_UnInstallMagicScanISR(Int16 slot); //<=== give a callback function for interrupt [DllImport("pac_i8014W.dll", EntryPoint = "pac_i8014W_ClearInt")] public static extern void pac_i8014W_ClearInt(Int16 slot); } // for I/O version management public static Int16 LibVersion() { return ICPDAS.pac_i8014W_GetLibVersion(); } // for I/O version management public static string LibDate() { byte[] libDate = new byte[32]; ICPDAS.pac_i8014W_GetLibDate(libDate); return AscArr2Str(libDate); } public static Int16 Init(Int16 slot) { return ICPDAS.pac_i8014W_Init(slot); } public static Int16 FirmwareVer_L1(Int16 slot) { return ICPDAS.pac_i8014W_GetFirmwareVer_L1(slot); } public static Int16 FirmwareVer_L2(Int16 slot) { return ICPDAS.pac_i8014W_GetFirmwareVer_L2(slot); } public static Int16 SingleEndJumper(Int16 slot) { return ICPDAS.pac_i8014W_GetSingleEndJumper(slot); } public static void ReadGainOffset(Int16 slot, Int16 gain, ref UInt16 gainValue, ref Int16 offsetValue) { ICPDAS.pac_i8014W_ReadGainOffset( slot, gain, ref gainValue, ref offsetValue); } public static Int16 ReadAIHex(Int16 slot, Int16 ch, Int16 gain, ref Int16 hVal) { return ICPDAS.pac_i8014W_ReadAIHex(slot, ch, gain, ref hVal); } public static Int16 ReadAI(Int16 slot, Int16 ch, Int16 gain, ref float fVal) { return ICPDAS.pac_i8014W_ReadAI(slot, ch, gain, ref fVal); } public static void ClearFIFO(Int16 slot) { ICPDAS.pac_i8014W_ClearFIFO( slot); } public static void UnLockFIFO(Int16 slot) { ICPDAS.pac_i8014W_UnLockFIFO(slot); } public static void ConfigMagicScan(Int16 slot, Int16[] chArr, Int16[] gainArr, Int16 scanChCount, float sampleRate, Int16 scanMode, Int16 triggerSource, Int16 triggerState, ref float realSampleRate) { ICPDAS.pac_i8014W_ConfigMagicScan(slot, chArr, gainArr, scanChCount, sampleRate, scanMode, triggerSource, triggerState, ref realSampleRate); } public static Int16 StartMagicScan(Int16 slot) { return ICPDAS.pac_i8014W_StartMagicScan(slot); } public static Int16 StopMagicScan(Int16 slot) { return ICPDAS.pac_i8014W_StopMagicScan(slot); } public static Int16 ReadFIFO(Int16 slot, Int16[] hexData, Int16 readCount, ref Int16 dataCountFromFIFO)// <=== get data from FIFO ,long* dataCnt { return ICPDAS.pac_i8014W_ReadFIFO(slot, hexData, readCount,ref dataCountFromFIFO); } public static Int16 ReadFIFOInISR(Int16 slot, Int16[] hexData, Int16 readCount, ref Int16 dataCountFromFIFO)// <=== get data from FIFO ,long* dataCnt { return ICPDAS.pac_i8014W_ReadFIFO_InISR(slot, hexData, readCount, ref dataCountFromFIFO); } public static Int16 ReadFIFO_BlockMode(Int16 slot, Int16[] hexData, Int32 readCount, ref Int32 dataCountFromFIFO)// <=== get data from FIFO ,long* dataCnt { return ICPDAS.pac_i8014W_ReadFIFO_BlockMode(slot, hexData, readCount,ref dataCountFromFIFO); } public static void CalibrateDataHex(Int16 slot, Int16 iGain, Int16 dataFromFIFO, ref Int16 calibratedAI) { ICPDAS.pac_i8014W_CalibrateDataHex(slot, iGain, dataFromFIFO, ref calibratedAI); } public static void CalibrateData(Int16 slot, Int16 iGain, Int16 dataFromFIFO, ref float calibratedAI) { ICPDAS.pac_i8014W_CalibrateData(slot, iGain, dataFromFIFO, ref calibratedAI); } public static Int16 InstallMagicScanISR(Int16 slot, IsrFunction isr, Int16 triggerLevel) { return ICPDAS.pac_i8014W_InstallMagicScanISR(slot, isr, triggerLevel); } public static Int16 UnInstallMagicScanISR(Int16 slot) { return ICPDAS.pac_i8014W_UnInstallMagicScanISR(slot); } public static void ClearInt(Int16 slot) { ICPDAS.pac_i8014W_ClearInt(slot); } private static string AscArr2Str(byte[] b) { return System.Text.UnicodeEncoding.Unicode.GetString( System.Text.ASCIIEncoding.Convert(System.Text.Encoding.ASCII, System.Text.Encoding.Unicode, b), 0, b.Length); } public static string Arr2Str(byte[] buffer) { return (new UnicodeEncoding()).GetString(buffer, 0, buffer.Length); } } }