Beispiel #1
0
        public void waveformAiCtrl_DataReady(object sender, BfdAiEventArgs e)
        {
            Console.WriteLine(" Streaming AI data ready:count = {0},offset = {1} ", e.Count, e.Offset);
            Int32          returnedCount   = 0;
            WaveformAiCtrl waveformAiCtrl  = (WaveformAiCtrl)sender;
            Conversion     conversion      = waveformAiCtrl.Conversion;
            Record         record          = waveformAiCtrl.Record;
            int            channelCountMax = waveformAiCtrl.Features.ChannelCountMax;
            int            startChan       = conversion.ChannelStart;
            int            channelCount    = conversion.ChannelCount;
            int            sectionLengt    = record.SectionLength;
            int            getDataCount    = sectionLengt * channelCount;

            // buffer section length, when 'DataReady' event been signaled, driver renew data count is e.count.
            if (e.Count > channelCount)
            {
                double[] sectionBuffers = new double[getDataCount];
                getDataCount = Math.Min(getDataCount, e.Count);
                waveformAiCtrl.GetData(getDataCount, sectionBuffers, 0, out returnedCount);
                Console.Write("Streaming AI get data count is {0}", returnedCount);
                Console.WriteLine(" The first sample for each channel are:");
                DoChart1update(sectionBuffers);
                DoChart2update(sectionBuffers);
                DoChart3update(sectionBuffers);
                // for (int j = 0; j < channelCount; ++j)
                //{
                //   Console.WriteLine("  channel {0}: {1}", (j % channelCount + startChan) % channelCountMax, sectionBuffer[j]);
                //}
                //Console.WriteLine();
                //foreach (var sectionBuffer in sectionBuffers)
                //{
                //    Console.WriteLine("  channel {0}: {1}", (0 % channelCount + startChan) % channelCountMax, sectionBuffer);
                //}
            }
        }
Beispiel #2
0
        /// <summary>
        /// 模拟输入接收事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void waveformAiCtrlUsb4704_DataReady(object sender, Automation.BDaq.BfdAiEventArgs e)
        {
            try
            {
                if (waveformAiCtrlUsb4704.State == ControlState.Idle)
                {
                    return;
                }

                if (arrAiData.Length < e.Count)
                {
                    arrAiData = new double[e.Count];
                }

                int       chanCount     = waveformAiCtrlUsb4704.Conversion.ChannelCount;
                int       sectionLength = e.Count / chanCount;
                ErrorCode err           = waveformAiCtrlUsb4704.GetData(e.Count, arrAiData);
                if (err == ErrorCode.WarningFuncStopped || err == ErrorCode.WarningFuncTimeout)
                {
                    Console.WriteLine("发生1次" + err + "警告");
                    return;
                }
                if (err != ErrorCode.Success && err != ErrorCode.WarningRecordEnd)
                {
                    ActiveEventError("模拟输入接收失败:" + err.ToString());
                    return;
                }

                for (int i = 0; i < sectionLength; i++)
                {
                    double[] arrData = new double[chanCount];
                    for (int j = 0; j < chanCount; j++)
                    {
                        int cnt = i * chanCount + j;
                        arrData[j] = arrAiData[cnt];
                    }
                    queueAiData.Enqueue(arrData);
                }
            }
            catch (Exception error)
            {
                ActiveEventError("模拟输入中断异常:" + error.Message);
            }
        }
Beispiel #3
0
        public void waveformAiCtrl_DataReady(object sender, BfdAiEventArgs e)
        {
            try
            {
                Int32          returnedCount   = 0;
                WaveformAiCtrl waveformAiCtrl  = (WaveformAiCtrl)sender;
                Conversion     conversion      = waveformAiCtrl.Conversion;
                Record         record          = waveformAiCtrl.Record;
                int            channelCountMax = waveformAiCtrl.Features.ChannelCountMax;
                int            startChan       = conversion.ChannelStart;
                int            channelCount    = conversion.ChannelCount;
                int            sectionLengt    = record.SectionLength;
                int            getDataCount    = sectionLengt * channelCount;

                // buffer section length, when 'DataReady' event been signaled, driver renew data count is e.count.
                if (e.Count > channelCount)
                {
                    double[] sectionBuffers = new double[getDataCount];
                    getDataCount = Math.Min(getDataCount, e.Count);
                    waveformAiCtrl.GetData(getDataCount, sectionBuffers, 0, out returnedCount);

                    /* Filter
                     * //sectionBuffers = SF.Bandpassfilter(sectionBuffers, convertClkRate, lowcutoff, highcutoff);
                     * //sectionBuffers = SF.Butterworth(sectionBuffers, convertClkRate, 100);
                     */
                    DoTimeChartupdate(sectionBuffers);
                    DoFFTChartupdate(sectionBuffers);
                    DoMaxChartupdate(sectionBuffers);
                }
            }
            catch (Exception err)
            {
                _log.Error("Failed to Data Collection---" + err.Message);
                MessageBox.Show(err.Message);;
            }
        }