Exemplo n.º 1
0
        private void waveformAiCtrlUsb4704_DataReady(object sender, Automation.BDaq.BfdAiEventArgs e)
        {
            MarkTimeHelper.MarkTime(MarkTimeStatus.End, "采样");
            MarkTimeHelper.MarkTime(MarkTimeStatus.Start, "采样");
            try
            {
                if (waveformAiCtrlUsb4704.State == ControlState.Idle)
                {
                    return;
                }
                Console.WriteLine("接收数据:" + e.Count.ToString());
                if (m_dataScaled.Length < e.Count)
                {
                    m_dataScaled = new double[e.Count];
                    //Console.WriteLine("接收数据:" + e.Count.ToString());
                }

                int       chanCount     = waveformAiCtrlUsb4704.Conversion.ChannelCount;
                int       sectionLength = waveformAiCtrlUsb4704.Record.SectionLength;
                ErrorCode err           = waveformAiCtrlUsb4704.GetData(e.Count, m_dataScaled);
                if (err != ErrorCode.Success && err != ErrorCode.WarningRecordEnd)
                {
                    Console.WriteLine("错误:" + err);
                    return;
                }

                this.Invoke(new Action(() =>
                {
                    double[] arrSumData = new double[chanCount];
                    listViewAi.BeginUpdate();
                    for (int i = 0; i < sectionLength; i++)
                    {
                        string[] arrData = new string[chanCount];
                        for (int j = 0; j < chanCount; j++)
                        {
                            int cnt        = i * chanCount + j;
                            arrData[j]     = m_dataScaled[cnt].ToString("f4");
                            arrSumData[j] += m_dataScaled[cnt];
                        }
                        addListViewItems(listViewAi, arrData);
                    }
                    string[] arrAvgData = new string[arrSumData.Length];
                    for (int i = 0; i < arrSumData.Length; i++)
                    {
                        arrAvgData[i] = (arrSumData[i] / sectionLength).ToString("f4");
                    }
                    editListViewItems(listViewAi, 0, arrAvgData);
                    listViewAi.EndUpdate();
                }));
            }
            catch (Exception error)
            {
                Console.WriteLine("DataReady错误:" + error.Message);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 模拟数据接收处理函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void waveformAiCtrlUsb4704_DataReady(object sender, Automation.BDaq.BfdAiEventArgs e)
        {
            Console.WriteLine(MarkTimeAi.MarkName + " = " + MarkTimeAi.StrMarkTime());
            try
            {
                if (waveformAiCtrlUsb4704.State == ControlState.Idle)
                {
                    return;
                }
                //Console.WriteLine("接收数据:" + e.Count.ToString());
                if (m_dataScaled.Length < e.Count)
                {
                    m_dataScaled = new double[e.Count];
                    //Console.WriteLine("接收数据:" + e.Count.ToString());
                }

                int       chanCount     = waveformAiCtrlUsb4704.Conversion.ChannelCount;
                int       sectionLength = e.Count / chanCount; //sectionLength = waveformAiCtrlUsb4704.Record.SectionLength;
                ErrorCode err           = waveformAiCtrlUsb4704.GetData(e.Count, m_dataScaled);
                if (err != ErrorCode.Success && err != ErrorCode.WarningRecordEnd)
                {
                    Console.WriteLine("错误:" + err);
                    return;
                }

                Console.WriteLine("接收数据:" + e.Count.ToString() + " chanCount:" + chanCount.ToString() + " sectionLength" + sectionLength.ToString());

                //刷新列表显示
                this.Invoke(new Action(() =>
                {
                    double[] arrSumData = new double[chanCount];
                    string[] outputData = new string[sectionLength];
                    listViewAi.BeginUpdate();
                    for (int i = 0; i < sectionLength; i++)
                    {
                        string[] arrData = new string[chanCount];
                        for (int j = 0; j < chanCount; j++)
                        {
                            int cnt        = i * chanCount + j;
                            double value   = AiDataMathProcess(j, m_dataScaled[cnt]);
                            arrData[j]     = value.ToString("f4");
                            arrSumData[j] += value;
                        }
                        addListViewItems(listViewAi, arrData);
                        outputData[i] = string.Join(",", arrData);
                    }
                    OutputFileAi.AddWriteLine(outputData);
                    string[] arrAvgData = new string[arrSumData.Length];
                    for (int i = 0; i < arrSumData.Length; i++)
                    {
                        arrAvgData[i] = (arrSumData[i] / sectionLength).ToString("f4");
                    }
                    setListViewItem0("实时", listViewAi, arrAvgData);
                    listViewAi.EndUpdate();
                }));
            }
            catch (Exception error)
            {
                Console.WriteLine("DataReady错误:" + error.Message);
            }
        }