研华PCI1716L的C#编程

新建windows窗体项目;
添加引用研华的库文件
研华PCI1716L的C#编程_第1张图片
将库添加using
在这里插入图片描述
整个代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Automation.BDaq;
using System.IO;
namespace 研华1716L
{
    public partial class Form1 : Form
    {
        WaveformAiCtrl waveformAiCtrl = new WaveformAiCtrl();
        int getDataCount = 12000;
        short[] sectionBuffer=new short[12000];
        void waveformAiCtrl_DataReady(object sender, BfdAiEventArgs e)
        {
            waveformAiCtrl.GetData(getDataCount, sectionBuffer);
            StreamWriter sw = new StreamWriter("1.txt", true, Encoding.Default);
            for (int j = 0; j < 12000; j++)
            {
                sw.WriteLine(sectionBuffer[j]);
            }
            sw.Close();

        }
        public Form1()
        {
            InitializeComponent(); 
            string deviceDescription = "DemoDevice,BID#0";//根据设备改
            waveformAiCtrl.SelectedDevice = new DeviceInformation(deviceDescription);
            waveformAiCtrl.Prepare();
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            waveformAiCtrl.DataReady += new EventHandler(waveformAiCtrl_DataReady);
            waveformAiCtrl.Start();
        }

      
    }
}

实现简单功能点击按钮,将读的文件向TXT中写。原理性的就这些,整体的程序,放在代码仓库吧。

你可能感兴趣的:(c#)