Exemple #1
0
        /// <summary>
        /// 启动AI采集任务
        /// </summary>
        public void TryArmTask()
        {
            if (AIState != Status.Idle)
            {
                throw new Exception("If you want to arm, the AI state must be 'Idle'!");
            }
            else
            {
                if (aiTask == null)
                {
                    try
                    {
                        hasFinishFlag = false;
                        //新建任务
                        aiTask = new NationalInstruments.DAQmx.Task();

                        //aiTask.Stream.ReadAutoStart = true;

                        //配置任务
                        NIAIConfigMapper.MapAndConfigAll(aiTask, _staticConfig);

                        //获取并设置通道数
                        _staticConfig.ChannelCount = aiTask.AIChannels.Count;

                        //使用NI Task中的EveryNSamplesRead事件读取数据
                        aiTask.EveryNSamplesReadEventInterval = _staticConfig.ClockConfig.ReadSamplePerTime;
                        aiTask.EveryNSamplesRead += AiTask_EveryNSamplesRead;

                        //计算读取次数
                        times      = 0;
                        totalTimes = _staticConfig.ClockConfig.TotalSampleLengthPerChannel / _staticConfig.ClockConfig.ReadSamplePerTime;

                        //Verify the Task
                        aiTask.Control(TaskAction.Verify);

                        //read stream
                        //使用reader读数据
                        reader = new AnalogMultiChannelReader(aiTask.Stream);

                        aiTask.SynchronizeCallbacks = true;

                        //开始任务
                        aiTask.Start();

                        //idle -> ready
                        AIState = Status.Ready;
                    }
                    catch (DaqException ex)
                    {
                        //ex.Message
                        goError();
                        throw ex;
                    }
                }
            }
        }
        /// <summary>
        /// 启动AI采集任务
        /// </summary>
        public void TryArmTask()
        {
            if (AIState != Status.Idle)
            {
                throw new Exception("If you want to arm, the AI state must be 'Idle'!");
            }
            else
            {
                if (aiTask == null)
                {
                    try
                    {
                        //新建任务
                        aiTask = new NationalInstruments.DAQmx.Task();

                        aiTask.Stream.ReadAutoStart = true;

                        //配置任务
                        NIAIConfigMapper.MapAndConfigAll(aiTask, _staticConfig.BasicAITaskConifg);

                        //获取并设置通道数
                        _staticConfig.ChannelCount = aiTask.AIChannels.Count;

                        //Verify the Task
                        aiTask.Control(TaskAction.Verify);

                        int channelCount      = _staticConfig.ChannelCount;
                        int readSamplePerTime = _staticConfig.BasicAITaskConifg.ClockConfig.ReadSamplePerTime;
                        ReadData(aiTask, channelCount, readSamplePerTime);

                        //idle -> ready
                        AIState = Status.Ready;

                        //开始任务
                        aiTask.Start();
                    }
                    catch (DaqException ex)
                    {
                        //ex.Message
                        goError();
                        throw ex;
                    }
                }
            }
        }