„DAQMX kártya példaprogram” változatai közötti eltérés

A Fizipedia wikiből
(Tutorial program for DAQMX data acquisition card)
 
(3 szerkesztő 7 közbeeső változata nincs mutatva)
1. sor: 1. sor:
 
[[Category:Szerkesztő:Geresdi]]
 
[[Category:Szerkesztő:Geresdi]]
 +
[[Kategória:Szerkesztő:FulopGergo]]
 
[[Fájl:CSharp_DAQMX.png|none]]
 
[[Fájl:CSharp_DAQMX.png|none]]
  
7. sor: 8. sor:
 
* '''TextBox''' inputBox;
 
* '''TextBox''' inputBox;
  
 +
'''Megjegyzés''': a kártya azonosítója ("DevXX") a MAX listájában ellenőrizhető. Az alábbi kódban a "Dev1" stringet át kell írni a megfelelő értékre, amennyiben szükséges.
 +
 +
=Tutorial program for DAQMX data acquisition card=
 +
 +
Contents of the Form:
 +
* '''Button''' startButton;
 +
* '''Button''' readButton;
 +
* '''TextBox''' inputBox;
 +
 +
'''Note''': The identifier of the card ("DevXX") can be verified using MAX (Measurement and Automation Explorer). When using the following code, replace the "Dev1" string with the actual identifier of the connected device.
  
 
<syntaxhighlight lang=csharp>
 
<syntaxhighlight lang=csharp>
16. sor: 27. sor:
 
using System.Text;
 
using System.Text;
 
using System.Windows.Forms;
 
using System.Windows.Forms;
//a kovetkezo harom using direktivat hozza kell adni a fejlechez
+
//Add the following references manually to the header
//az NI es ZedGraph referenciat hozza kell adni a projecthez
+
using NationalInstruments.DAQmx; //Don't forget to add the references to the NI libraries in the project explorer as well
using ZedGraph;                   
+
using NationalInstruments.DAQmx;
+
 
using System.IO;
 
using System.IO;
  
26. sor: 35. sor:
 
     public partial class Form1 : Form
 
     public partial class Form1 : Form
 
     {
 
     {
         //Global valtozok
+
         //Global variables
 
         private Task OutTask;    //kimeneti Task: Dev1/ao0
 
         private Task OutTask;    //kimeneti Task: Dev1/ao0
 
         private AnalogSingleChannelWriter writer;   
 
         private AnalogSingleChannelWriter writer;   
32. sor: 41. sor:
 
         private AnalogSingleChannelReader reader;
 
         private AnalogSingleChannelReader reader;
  
 +
        double Minimumvoltage = 0;
 +
        double Maximumvoltage = 5;
 
         public Form1()
 
         public Form1()
 
         {
 
         {
39. sor: 50. sor:
 
         private void Form1_Load(object sender, EventArgs e)
 
         private void Form1_Load(object sender, EventArgs e)
 
         {
 
         {
             //a masodik gomb le van tiltva, amig nem nyomjuk meg a felsot
+
             //Read button is disabled when the program loads
 
             readButton.Enabled=false;
 
             readButton.Enabled=false;
 
         }
 
         }
  
//Inicializalas a meres megkezdese elott
+
//The measurement has to be initialized first
//peldaul gombnyomasra
+
//For example by using a button press
 
         private void startButton_Click(object sender, System.EventArgs e)
 
         private void startButton_Click(object sender, System.EventArgs e)
 
         {
 
         {
//Kimenet
+
//Output
OutTask = new Task();  //Task konstruktora
+
OutTask = new Task();  //Task constructor
//Kimeneti csatorna letrehozasa:
+
//Creating the output channel
 
OutTask.AOChannels.CreateVoltageChannel("Dev1/ao0", "",
 
OutTask.AOChannels.CreateVoltageChannel("Dev1/ao0", "",
                     MinimumValue, MaximumValue,
+
                     Minimumvoltage, Maximumvoltage,
 
                     AOVoltageUnits.Volts);
 
                     AOVoltageUnits.Volts);
 
writer = new AnalogSingleChannelWriter(OutTask.Stream);
 
writer = new AnalogSingleChannelWriter(OutTask.Stream);
//Bemenet
+
//Input
InTask = new Task();  //Task konstruktora
+
InTask = new Task();  //Task constructor
//Bemeneti csatorna letrehozasa:
+
//Creating the input channel
 
InTask.AIChannels.CreateVoltageChannel("Dev1/ai0", "",
 
InTask.AIChannels.CreateVoltageChannel("Dev1/ai0", "",
                     AITerminalConfiguration.Rse, MinimumValue, MaximumValue,
+
                     AITerminalConfiguration.Differential, Minimumvoltage, Maximumvoltage,
 
                     AIVoltageUnits.Volts);
 
                     AIVoltageUnits.Volts);
 
reader = new AnalogSingleChannelReader(InTask.Stream);
 
reader = new AnalogSingleChannelReader(InTask.Stream);
                         //miutan inicializaltuk a merest, megnyomhatjuk a masodik gombot is
+
                         //The read button is enabled after the initialization
 
                         readButton.Enabled=true;
 
                         readButton.Enabled=true;
 
}
 
}
67. sor: 78. sor:
 
         {
 
         {
 
                         Double input = 0;
 
                         Double input = 0;
                         //a feszultseg kiadasat es visszaolvasasat az alabbi fuggveny vegzi
+
                         //The below function performs the writing and reading of the voltage values
                         input=write_and_Read();
+
                         input=write_And_Read();
                         //az eredmeny kiirasa
+
                         //displaying the result
 
                         inputBox.Text=input.ToString("0.000");
 
                         inputBox.Text=input.ToString("0.000");
 
         }
 
         }
         //data nagysagu feszultseg kiadasa
+
         //writing voltage (value stored in data variable)
         //es a bemenet beolvasasa
+
         //and reading voltage on the input
 
private Double write_And_Read()
 
private Double write_And_Read()
 
{
 
{
Double data=0.2;  //mindig 0 es 5V kozott!
+
Double data=0.2;  //always between 0 and 5 V!
 
writer.WriteSingleSample(true,data);
 
writer.WriteSingleSample(true,data);
                         //a fuggveny a beolvasott ertekkel ter vissza
+
                         //the function returns the measured voltage
 
return reader.ReadSingleSample();
 
return reader.ReadSingleSample();
 
}
 
}
 
         private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 
         private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 
         {
 
         {
             destroy();
+
             //free up resources
 +
    OutTask.Dispose();
 +
    InTask.Dispose();
 
         }
 
         }
        //eroforrasok felszabaditasa
+
        //Form bezarasakor hivjuk meg!
+
private void destroy()
+
{
+
OutTask.Dispose();
+
InTask.Dispose();
+
}
+
 
     }
 
     }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

A lap jelenlegi, 2019. szeptember 6., 14:14-kori változata

CSharp DAQMX.png

A Form tartalma:

  • Button startButton;
  • Button readButton;
  • TextBox inputBox;

Megjegyzés: a kártya azonosítója ("DevXX") a MAX listájában ellenőrizhető. Az alábbi kódban a "Dev1" stringet át kell írni a megfelelő értékre, amennyiben szükséges.

Tutorial program for DAQMX data acquisition card

Contents of the Form:

  • Button startButton;
  • Button readButton;
  • TextBox inputBox;

Note: The identifier of the card ("DevXX") can be verified using MAX (Measurement and Automation Explorer). When using the following code, replace the "Dev1" string with the actual identifier of the connected device.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//Add the following references manually to the header
using NationalInstruments.DAQmx; //Don't forget to add the references to the NI libraries in the project explorer as well
using System.IO;
 
namespace DAQMX
{
    public partial class Form1 : Form
    {
        //Global variables
        private Task OutTask;    //kimeneti Task: Dev1/ao0
        private AnalogSingleChannelWriter writer;  
        private Task InTask;    //bemeneti Task: Dev1/ai0
        private AnalogSingleChannelReader reader;
 
        double Minimumvoltage = 0;
        double Maximumvoltage = 5;
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            //Read button is disabled when the program loads
            readButton.Enabled=false;
        }
 
	//The measurement has to be initialized first
	//For example by using a button press
        private void startButton_Click(object sender, System.EventArgs e)
        {
			//Output
			OutTask = new Task();  //Task constructor
			//Creating the output channel
			OutTask.AOChannels.CreateVoltageChannel("Dev1/ao0", "",
                    Minimumvoltage, Maximumvoltage,
                    AOVoltageUnits.Volts);		
			writer = new AnalogSingleChannelWriter(OutTask.Stream);
			//Input
			InTask = new Task();  //Task constructor
			//Creating the input channel
			InTask.AIChannels.CreateVoltageChannel("Dev1/ai0", "",
                    AITerminalConfiguration.Differential, Minimumvoltage, Maximumvoltage,
                    AIVoltageUnits.Volts);		
			reader = new AnalogSingleChannelReader(InTask.Stream);
                        //The read button is enabled after the initialization
                        readButton.Enabled=true;
	}
        private void readButton_Click(object sender, System.EventArgs e)
        {
                        Double input = 0;
                        //The below function performs the writing and reading of the voltage values
                        input=write_And_Read();
                        //displaying the result
                        inputBox.Text=input.ToString("0.000");
        }
        //writing voltage (value stored in data variable)
        //and reading voltage on the input
	private Double write_And_Read()
	{
			Double data=0.2;   //always between 0 and 5 V!
			writer.WriteSingleSample(true,data);
                        //the function returns the measured voltage
			return reader.ReadSingleSample();
	}
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            //free up resources 
	    OutTask.Dispose();
	    InTask.Dispose();
        }
 
     }
}