Beispiel #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);
            }
        }
Beispiel #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);                // 关闭设备
     }
 }