using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace CommonLib.DAQ
{
public class MCM204Wrapper
{
// 定义常量
public const int MAX_CH_NUM = 4; // 通道数
//采集卡
public const int DATA_COUNT_PERCH = 32768; // 每通道采样点数
public const int SAMPLING_RATE = 32000; // 每通道采样率为128KS/s
///
/// DLL加载路径
///
private const string DLLName = "MCM6204ACQDLL.dll";
///
/// 扫描设备数量
///
/// 设备数量
/// 成功:0,失败:-1
[DllImport(DLLName, EntryPoint = "ScanListDevice", CallingConvention = CallingConvention.Cdecl)]
private static extern int ScanListDevice(StringBuilder HostNames ,ref int devCount);
public static int ScanListDevice(ref string[] HostNames, ref int devCount)
{
StringBuilder buf = new StringBuilder();
buf.Length = 10000;
int errorcode = ScanListDevice(buf, ref devCount);
HostNames = buf.ToString().Split(new char[]
{
';'
},StringSplitOptions.RemoveEmptyEntries);
return errorcode;
}
///
/// 打开添加的设备
///
/// 板卡号数组
/// 待打开的板卡数量
/// 返回结果 成功:0,失败:-1
//[DllImport(DLLName, EntryPoint = "OpenDevices", CallingConvention = CallingConvention.Cdecl)]
//public static extern int OpenDevices(int[] boardIDs, int devCount);
[DllImport(DLLName, EntryPoint = "OpenDevice", CallingConvention = CallingConvention.Cdecl)]
public static extern int OpenDevice(string HostName);
///
/// 配置打开板卡的参数
///
/// 板卡参数,通道数、采样率、采样点数
/// 打开的设备数量
/// 返回结果 成功:0,失败:-1
//[DllImport(DLLName, EntryPoint = "ConfigAIParams", CallingConvention = CallingConvention.Cdecl)]
//public static extern int ConfigAIParams(AIConfigParam[] devAiConfigParamArray, int devCount);
[DllImport(DLLName, EntryPoint = "ConfigAIParam", CallingConvention = CallingConvention.Cdecl)]
public static extern int ConfigAIParam(string HostName,ref AIConfigParam devAiConfigParamArray);
///
/// 启动添加的板卡,开始采集数据
///
/// 返回结果 成功:0,失败:-1
//[DllImport(DLLName, EntryPoint = "StartDevices", CallingConvention = CallingConvention.Cdecl)]
//public static extern int StartDevices();
[DllImport(DLLName, EntryPoint = "StartDevice", CallingConvention = CallingConvention.Cdecl)]
public static extern int StartDevice(string HostName);
///
/// 获取板卡数据
///
/// 二维数组的值
/// 返回结果 成功:0,失败:-1
[DllImport(DLLName, EntryPoint = "GetDataDevice", CallingConvention = CallingConvention.Cdecl)]
public static extern int GetDataDevice(string HostName,double[,] dataBuf);
///
/// 使添加的设备停止采集
///
/// 返回结果 成功:0,失败:-1
[DllImport(DLLName, EntryPoint = "StopDevice", CallingConvention = CallingConvention.Cdecl)]
public static extern int StopDevice(string HostName);
///
/// 关闭添加的设备
///
/// 返回执行的结果
[DllImport(DLLName, EntryPoint = "CloseDevice", CallingConvention = CallingConvention.Cdecl)]
public static extern int CloseDevice(string HostName);
}
///
/// AI配置参数
///
public struct AIConfigParam
{
public int chnsCount; // 通道数,通道从0添加至chnsCount-1
public double sampleRate; // 每通道采样率
public uint sampleToAcquire; // 每通道采样点数
}
}