„MyDAQ” változatai közötti eltérés
A Fizipedia wikiből
Fuge (vitalap | szerkesztései) |
|||
(2 szerkesztő 3 közbeeső változata nincs mutatva) | |||
1. sor: | 1. sor: | ||
− | NI myDAQ | + | Example: programming the NI myDAQ data acquisition card using C# language. |
+ | |||
+ | [[:Fájl:myDAQ_prog.zip | Download: myDAQ_prog.zip]] | ||
<syntaxhighlight lang=csharp> | <syntaxhighlight lang=csharp> | ||
16. sor: | 18. sor: | ||
public partial class Form1 : Form | public partial class Form1 : Form | ||
{ | { | ||
− | private Task InTask; | + | private NationalInstruments.DAQmx.Task InTask; |
private AnalogSingleChannelReader analogReader; | private AnalogSingleChannelReader analogReader; | ||
− | private Task OutTask; | + | |
+ | private NationalInstruments.DAQmx.Task OutTask; | ||
private AnalogSingleChannelWriter analogWriter; | private AnalogSingleChannelWriter analogWriter; | ||
29. sor: | 32. sor: | ||
{ | { | ||
// Set up DAQ Card Input & Output | // Set up DAQ Card Input & Output | ||
− | InTask = new Task(); | + | InTask = new NationalInstruments.DAQmx.Task(); |
InTask.AIChannels.CreateVoltageChannel("myDAQ1/ai0", "", | InTask.AIChannels.CreateVoltageChannel("myDAQ1/ai0", "", | ||
AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts); | AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts); | ||
analogReader = new AnalogSingleChannelReader(InTask.Stream); | analogReader = new AnalogSingleChannelReader(InTask.Stream); | ||
− | OutTask = new Task(); | + | OutTask = new NationalInstruments.DAQmx.Task(); |
OutTask.AOChannels.CreateVoltageChannel("myDAQ1/ao0", "", | OutTask.AOChannels.CreateVoltageChannel("myDAQ1/ao0", "", | ||
-10, 10, AOVoltageUnits.Volts); | -10, 10, AOVoltageUnits.Volts); | ||
62. sor: | 65. sor: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | * | + | * Try this fix, when there is a problem with the different versions of .NET: Paste the following lines into the app.config file: |
<syntaxhighlight lang=csharp> | <syntaxhighlight lang=csharp> | ||
<startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> | <startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> | ||
</syntaxhighlight> | </syntaxhighlight> |
A lap jelenlegi, 2021. szeptember 17., 09:50-kori változata
Example: programming the NI myDAQ data acquisition card using C# language.
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 NationalInstruments.DAQmx.Task InTask; private AnalogSingleChannelReader analogReader; private NationalInstruments.DAQmx.Task OutTask; private AnalogSingleChannelWriter analogWriter; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Set up DAQ Card Input & Output InTask = new NationalInstruments.DAQmx.Task(); InTask.AIChannels.CreateVoltageChannel("myDAQ1/ai0", "", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts); analogReader = new AnalogSingleChannelReader(InTask.Stream); OutTask = new NationalInstruments.DAQmx.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(); } } }
- Try this fix, when there is a problem with the different versions of .NET: Paste the following lines into the app.config file:
<startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>