Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            ChansCount = CountChannel();
            if (ChansCount == 0)
            {
                MessageBox.Show("请先选择通道使能");
                return;
            }
            InitSeries();
            GetChannel();
            checkedListBox1.Enabled = false;
            int temp = 0;

            if (USB1000.FindUSBDAQ() == 0)
            {
                MessageBox.Show("找不到采集卡硬件,请确保已经正确连接电脑并且驱动安装正常。");
                return;
            }
            try
            {
                SampleRate = Convert.ToInt32(txRate.Text);
                temp       = USB1000.OpenDevice(0);
                temp       = USB1000.ResetDevice(0);
                temp       = USB1000.SetUSB1AiRange(0, (int)USB1000.AiRange.V10);
                temp       = USB1000.SetSampleRate(0, SampleRate);
                temp       = USB1000.SetChanMode(0, (int)USB1000.ChannelMode.NRSE);

                temp = USB1000.SetChanSel(0, selState);


                temp = USB1000.SetSoftTrig(0, 1);

                if (temp == 0)
                {
                    NumToRead = SampleRate / ChansCount / 10;//每通道0.1秒读多少个数据(采样率单位是点/秒)
                    totalTime = 0;
                    Debug.WriteLine("num to read: " + NumToRead);
                    Debug.WriteLine("开始采集");
                    running = true;

                    //recordThread = new Thread(record);
                    //recordThread.Start();

                    temp = USB1000.StartRead(0);

                    timer1.Interval = 80;//ms   Timer设置比0.1s略小,以保障数据无滞后不溢出
                    timer1.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
 private void stop()
 {
     if (running)
     {
         timer1.Stop();
         running = false;
         checkedListBox1.Enabled = true;
         USB1000.StopRead(0);                   // 关闭计算机从采集卡读数线程
         USB1000.SetSoftTrig(0, 0);             // 关闭软件触发信号
         USB1000.ClearBufs(0);                  // 清空数据缓存空间
         USB1000.CloseDevice(0);                // 关闭设备
     }
 }
Пример #3
0
        //DataPointCollection dp;

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (running)
            {
                int AiFifoFree = USB1000.GetAiChans(0, NumToRead, selState, data, 1000);
                lb_fifo.Text = AiFifoFree.ToString();
                if (AiFifoFree < 0)
                {
                    Debug.WriteLine("ErrorCode:" + AiFifoFree);
                }
                else
                {
                    //float[,] f = new float[ChansCount, NumToRead];
                    float x, y;
                    x = data[NumToRead * 0];
                    y = data[NumToRead * 1];

                    chart1.Series[0].Points.AddXY(x, y);

                    //for (int k = 0; k < ChansCount; k++)
                    //{
                    //重新采样,取一部分点进行绘图,如果把所有点都用来绘图会导致刷新速度变慢。
                    //只读取每个通道的第一个值
                    //label3.Text = data[NumToRead * k].ToString();

                    //实际上所有数据点都毫无丢失地存储了
                    //for (int i = 0; i < NumToRead; i++)
                    //{
                    //f[k, i] = data[NumToRead * k + i];
                    //}
                    //}
                    //dataQueue.Enqueue(f);
                }

                lb_queue.Text = dataQueue.Count.ToString();

                //当点数过多时,清空图表重新绘制
                if (chart1.Series[0].Points.Count > 500)
                {
                    for (int i = 0; i < chart1.Series.Count; i++)
                    {
                        chart1.Series[i].Points.Clear();
                    }
                }
            }
        }