using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace CommonLib.DAQ { public class EM9118Wapper { //------------------------------------设备管理----------------------------------------- //创建设备 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_DeviceCreate(); //关闭设备 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern void EM9118_DeviceClose(Int32 pDev); //关闭命令端口 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern void EM9118_CmdClose(Int32 pDev, Int32 timeout); //关闭数据端口 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern void EM9118_DataClose(Int32 pDev, Int32 timeout); //连接命令端口(C#的string和C++的字符串首指针如何对应方法) [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_CmdConnect(Int32 pDev, [MarshalAs(UnmanagedType.LPStr)]String strIP, Int32 ipBC, Int32 port, Int32 timeout); //连接数据端口 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_DataConnect(Int32 pDev, Int32 dataPort, Int32 timeout); //---------------------------------------PWM部分-------------------------------------------- //设置PWM频率和占空比 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_PwmSetPulse(Int32 pDev, Int32 chNo, Double freq, Double duty, ref Double realFreq, ref Double realDuty, Int32 timeout); //使能或禁止PWM输出,目前只能全部使能和全部禁止 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_PwmStartOrStopAll(Int32 pDev, Byte startOrStop, Int32 timeout); //---------------------------------------编码器部分---------------------------------- //编码器清零 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_EcClear(Int32 pDev, Int32 chNo, Int32 timeout); //读回所有通道的编码器值 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_EcReadCodeAll(Int32 pDev, Int32[] encoderAB, Int16[] encoderZ, Int32 timeout); //----------------------------------------IO采集部分---------------------------------------- //设置开关量方向 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_IoSetDir(Int32 pDev, Byte[] dir, Int32 timeout); //设置所有通道开关量值,如果对应开关量方向设置为输入,则对应开关量的设置无效 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_IoSetAll(Int32 pDev, Byte[] iStatus, Int32 timeout); //得到所有通道开关量值 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_IoGetAll(Int32 pDev, Byte[] iStatus, Int32 timeout); //设置开关量值是否进入FIFO(高速IO) [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_IoInFifo(Int32 pDev, Byte isInFifo, Int32 timeout); //----------------------------------------DA输出部分---------------------------------------- //设置DA输出方式 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_DaSetOutMode(Int32 pDev, Int32 chNo, Int32 codeOrVal, Int32 rangeInx, Int32 timeout); //设置DA输出值 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_DaSet(Int32 pDev, Int32 chNo, Int16 daValue, Int32 timeout); //----------------------------------------CT计数器/测频部分---------------------------------------- //设置所有路计数器的工作方式 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_CtSetModeAll(Int32 pDev, UInt16[] ctMode, Int32 timeout); //设置指定通道的计数器测频基准脉冲周期,以毫秒为单位 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_CtSetFreqBase(Int32 pDev, Int32 chNo, Double freqBase_ms, Double real_ms, Int32 timeout); //读取所有路计数器的原码值 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_CtReadCodeAll(Int32 pDev, UInt32[] ctCode, Int32 timeout); //将计数器值根据原码值转换成对应的物理值,计数方式下则为计数值,测频方式下则为频率值 //此函数的转换结果和EM9118_CtSetModeAll有关 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_CtCodeToValue(Int32 pDev, Int32 chNo, UInt32 ctCode, ref Double ctValue); //指定通道计数器清零 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_CtClear(Int32 pDev, Int32 chNo, Int32 timeout); //----------------------------------------AD采集部分---------------------------------------- //设置AD通道范围,只有设置范围内的通道采集数据 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_AdSetChRange(Int32 pDev, Int32 beginNo, Int32 endNo, Int32 timeout); //设置AD单双端方式,注意要与设备跳线一致 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_AdSetEndMode(Int32 pDev, Int32 endMode, Int32 timeout); //设置AD采集范围,注意要与设备跳线一致 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_AdSetRange(Int32 pDev, Int32 rangeInx, Int32 timeout); //设置AD增益 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_AdSetGain(Int32 pDev, Int32 gainInx, Int32 timeout); //读取一次AD数据值 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_AdReadOnceCode(Int32 pDev, Int32 beginChNo, Int32 endChNo, UInt16[] adCode, Int32 timeout); //将AD原码值转换成物理值 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_AdGetValue(Int32 pDev, UInt16[] adCode, Int32 adCodeCount, Double[] adValue); //设置高速采集触发源 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_TriSetSrc(Int32 pDev, Int32 triSrc, Int32 timeout); //设置高速采集触发方式 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_TriSetMode(Int32 pDev, Int32 triMode, Int32 timeout); //设置通道切换频率 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_HcSetChFreq(Int32 pDev, Double chFreq, Int32 timeout); //设置组频率 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_HcSetGroupFreq(Int32 pDev, Double groupFreq, Int32 timeout); //启动硬件控制采集 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_HcStart(Int32 hDevice, Int32 clkSrc, Int32 triSrc, Int32 edgeOrLevel, Int32 upOrDown, Int32 timeOutMS); //停止硬件控制采集 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_HcStop(Int32 pDev, Int32 timeout); //在硬件控制采集启动后,使用次函数读回采集结果 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_HcReadData(Int32 pDev, Int32 byteCount, SByte[] codeBuffer, ref Int32 realByteCount, Int32 timeout); //public static extern Int32 EM9118_HcReadData(Int32 pDev, ref Int32 dataCount, ref sbyte dataBuffer, ref long realReadCount, Int32 timeout); //public static extern Int32 EM9118_HcReadData(Int32 pDev, ref Int32 dataCount, [MarshalAs(UnmanagedType.LPStr)]StringBuilder dataBuffer, ref Int32 realReadCount, Int32 timeout); //在硬件控制采集启动后,使用此函数判断下位机 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118M_HcFifoStatus(Int32 pDev, ref Int32 fifoStatus1, ref Int32 fifoStatus2, Int32 timeout); //将AD原码从原码值中提取出来,当高速缓冲区中有IO值存在时,需要调用此函数提取AD原码 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_AdGetCode(Int32 pDev, UInt16[] usCode, Int32 codeCount, UInt16[] adCode, ref Int32 adCodeCount); //AD原码从原码值中提取出来,当高速缓冲区中有IO值存在时,需要调用此函数提取AD原码 [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_IoGetCode(Int32 pDev, UInt16[] usCode, Int32 codeCount, UInt16[] ioCode, ref Int32 ioCodeCount); [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_AdChIsInFifo( Int32 pDev, Int32[] isInFifo, Int32 timeout ); [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_EcChIsInFifo(Int32 pDev, bool[] _isEcInFifo, Int32 timeout); [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_CtChIsInFifo(Int32 pDev, bool[] _isCtInFifo, Int32 timeout); [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_GetFifoGroupByteCount(Int32 pDev, ref Int32 byteCount); [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_GetFifoAdChCount(Int32 pDev); [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_GetFifoCtChCount(Int32 pDev); [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_GetFifoEcChCount(Int32 pDev); [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_CtSetModeAll(Int32 hDevice, byte[] ctMode, Int32 timeout); [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_AdChGetCode(Int32 pDev, Int32 chinx, UInt32 byteCount, SByte[] codeBuffer, Int16[] adCode, UInt32 adCodeCount); [DllImport("EM9118.dll", CharSet = CharSet.Auto)] public static extern Int32 EM9118_AdChBatchCodeToValue(Int32 hDevice, Int32 chNo, Int16[] pCode, Int32 codeCount, double[] adValue); } }