„DAQMX kártya példaprogram” változatai közötti eltérés
A Fizipedia wikiből
a |
|||
1. sor: | 1. sor: | ||
+ | [[Fájl:CSharp_DAQMX.png|none]] | ||
+ | |||
+ | A Form tartalma: | ||
+ | * '''Button''' startButton; | ||
+ | * '''Button''' readButton; | ||
+ | * '''TextBox''' inputBox; | ||
+ | |||
+ | |||
<syntaxhighlight lang=csharp> | <syntaxhighlight lang=csharp> | ||
using System; | using System; | ||
15. sor: | 23. sor: | ||
namespace DAQMX | namespace DAQMX | ||
{ | { | ||
− | public class Form1 : Form | + | public partial class Form1 : Form |
{ | { | ||
//Global valtozok | //Global valtozok | ||
23. sor: | 31. sor: | ||
private AnalogSingleChannelReader reader; | private AnalogSingleChannelReader reader; | ||
− | + | public Form1() | |
− | + | { | |
− | + | InitializeComponent(); | |
+ | } | ||
+ | |||
+ | private void Form1_Load(object sender, EventArgs e) | ||
+ | { | ||
+ | //a masodik gomb le van tiltva, amig nem nyomjuk meg a felsot | ||
+ | readButton.Enabled=false; | ||
+ | } | ||
+ | |||
+ | //Inicializalas a meres megkezdese elott | ||
+ | //peldaul gombnyomasra | ||
+ | private void startButton_Click(object sender, System.EventArgs e) | ||
{ | { | ||
//Kimenet | //Kimenet | ||
41. sor: | 60. sor: | ||
AIVoltageUnits.Volts); | AIVoltageUnits.Volts); | ||
reader = new AnalogSingleChannelReader(InTask.Stream); | reader = new AnalogSingleChannelReader(InTask.Stream); | ||
− | + | //miutan inicializaltuk a merest, megnyomhatjuk a masodik gombot is | |
− | + | readButton.Enabled=true; | |
− | + | } | |
− | + | private void readButton_Click(object sender, System.EventArgs e) | |
− | + | { | |
− | Double data=0.2; | + | Double input = 0; |
+ | //a feszultseg kiadasat es visszaolvasasat az alabbi fuggveny vegzi | ||
+ | input=write_and_Read(); | ||
+ | //az eredmeny kiirasa | ||
+ | inputBox.Text=input.ToString("0.000"); | ||
+ | } | ||
+ | //data nagysagu feszultseg kiadasa | ||
+ | //es a bemenet beolvasasa | ||
+ | private Double write_And_Read() | ||
+ | { | ||
+ | Double data=0.2; //mindig 0 es 5V kozott! | ||
writer.WriteSingleSample(true,data); | writer.WriteSingleSample(true,data); | ||
− | + | //a fuggveny a beolvasott ertekkel ter vissza | |
− | + | return reader.ReadSingleSample(); | |
− | + | } | |
− | + | private void Form1_FormClosed(object sender, FormClosedEventArgs e) | |
− | + | { | |
− | + | destroy(); | |
+ | } | ||
+ | //eroforrasok felszabaditasa | ||
+ | //Form bezarasakor hivjuk meg! | ||
+ | private void destroy() | ||
+ | { | ||
OutTask.Dispose(); | OutTask.Dispose(); | ||
InTask.Dispose(); | InTask.Dispose(); | ||
− | + | } | |
− | + | } | |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
A lap 2011. március 20., 17:55-kori változata
A Form tartalma:
- Button startButton;
- Button readButton;
- TextBox inputBox;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; //a kovetkezo harom using direktivat hozza kell adni a fejlechez //az NI es ZedGraph referenciat hozza kell adni a projecthez using ZedGraph; using NationalInstruments.DAQmx; using System.IO; namespace DAQMX { public partial class Form1 : Form { //Global valtozok private Task OutTask; //kimeneti Task: Dev1/ao0 private AnalogSingleChannelWriter writer; private Task InTask; //bemeneti Task: Dev1/ai0 private AnalogSingleChannelReader reader; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //a masodik gomb le van tiltva, amig nem nyomjuk meg a felsot readButton.Enabled=false; } //Inicializalas a meres megkezdese elott //peldaul gombnyomasra private void startButton_Click(object sender, System.EventArgs e) { //Kimenet OutTask = new Task(); //Task konstruktora //Kimeneti csatorna letrehozasa: OutTask.AOChannels.CreateVoltageChannel("Dev1/ao0", "", MinimumValue, MaximumValue, AOVoltageUnits.Volts); writer = new AnalogSingleChannelWriter(OutTask.Stream); //Bemenet InTask = new Task(); //Task konstruktora //Bemeneti csatorna letrehozasa: InTask.AIChannels.CreateVoltageChannel("Dev1/ai0", "", AITerminalConfiguration.Rse, MinimumValue, MaximumValue, AIVoltageUnits.Volts); reader = new AnalogSingleChannelReader(InTask.Stream); //miutan inicializaltuk a merest, megnyomhatjuk a masodik gombot is readButton.Enabled=true; } private void readButton_Click(object sender, System.EventArgs e) { Double input = 0; //a feszultseg kiadasat es visszaolvasasat az alabbi fuggveny vegzi input=write_and_Read(); //az eredmeny kiirasa inputBox.Text=input.ToString("0.000"); } //data nagysagu feszultseg kiadasa //es a bemenet beolvasasa private Double write_And_Read() { Double data=0.2; //mindig 0 es 5V kozott! writer.WriteSingleSample(true,data); //a fuggveny a beolvasott ertekkel ter vissza return reader.ReadSingleSample(); } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { destroy(); } //eroforrasok felszabaditasa //Form bezarasakor hivjuk meg! private void destroy() { OutTask.Dispose(); InTask.Dispose(); } } }