MyDAQ

A Fizipedia wikiből

NI myDAQ mérőkártya kezelése C# programból. Fájl:MyDAQ prog.zip

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NationalInstruments.DAQmx;
 
namespace myDAQ
{
    public partial class Form1 : Form
    {
        private Task InTask;
        private AnalogSingleChannelReader analogReader;
        private Task OutTask;
        private AnalogSingleChannelWriter analogWriter;
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            // Set up DAQ Card Input & Output
            InTask = new Task();
            InTask.AIChannels.CreateVoltageChannel("myDAQ1/ai0", "",
                AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts);
            analogReader = new AnalogSingleChannelReader(InTask.Stream);
 
            OutTask = new Task();
            OutTask.AOChannels.CreateVoltageChannel("myDAQ1/ao0", "",
                -10, 10, AOVoltageUnits.Volts);
            analogWriter = new AnalogSingleChannelWriter(OutTask.Stream);
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            // Read from Input
            InputextBox.Text = Convert.ToString(analogReader.ReadSingleSample());
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            // Write to Output
            analogWriter.WriteSingleSample(true, Convert.ToDouble(OutputtextBox.Text));
        }
 
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            InTask.Dispose();
            OutTask.Dispose();
        }
 
    }
}
  • Intézményi gépeken, ha probléma van a különböző .NET verziókkal, akkor az app.config fájlban kell megadni az alábbi opciót:
<startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>