Exemplo n.º 1
0
        private void TimerCnt_Elapsed(object sender, ElapsedEventArgs e)
        {
            //eventCounterCtrlUsb4704.Enabled = false;
            ErrorCode err = eventCounterCtrlUsb4704.Read(out int cntData);
            //eventCounterCtrlUsb4704.Enabled = true;
            TimeSpan timeSpan = MarkTimeHelper.MarkTime(MarkTimeStatus.End, err + "计数定时器", cntData.ToString());

            MarkTimeHelper.MarkTime(MarkTimeStatus.Start, "计数定时器");
            if (!checkCnt.Checked)
            {
                eventCounterCtrlUsb4704.Enabled = false;
                eventCounterCtrlUsb4704.Enabled = true;
                cntData = Convert.ToInt32(cntData / timeSpan.TotalSeconds);
            }
            try
            {
                this.Invoke(new Action(() =>
                {
                    labelCnt.Text = cntData.ToString();
                }));
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message);
            }
        }
Exemplo n.º 2
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);
            }
        }