1. An overview of the

Ni-daqmx is the current data acquisition driver for National Instruments. Ni-daqmx integrates a new driver architecture and API for controlling National Instruments DAQ devices.

This article demonstrates how to use the API provided by ni-DAQMX to control National Instruments DAQ devices for data acquisition tasks.

For your convenience, we use a simulated Ni-DAQMX device to demonstrate. It is created using the Ni-DAQMX analog device option in the NI Measurement and Automation Explorer (MAX) and behaves like a real device. Some Ni-DAQMX devices cannot be emulated in MAX. In many cases, similar devices can be simulated in place of devices that cannot be simulated.

1.1 Installing ni-DAQMX and creating a simulation device

1) Download and install the NI-DAQMX 20.0 software from the official website of National Instruments www.ni.com; After the ni-DAqmx driver package is installed, go to C:\Users\Public\Documents\National Instruments\ ni-daq \Examples\DotNET4.5 and store the common ni-DAqmx Examples. The script for this example project is basically based on these examples.

2) Run the NI MAX device management software to create a simulation device through the device and interface node. This demonstration uses “SimDev1” simulation equipment to collect voltage data.

1.2 Collection voltage code framework

NI – DAQmx for Microsoft. NetFramework platform, provides the NationalInstruments.Com mon. DLL and NationalInstruments DAQmx. Two DLL dynamic link library, As a third party using NI-DAQMX to control the APPLICATION program interface of National Instruments DAQ devices.

The NationalInstruments.Com mon. DLL dynamic libraries located in C: \ Program Files (x86) \ National Instruments, Measurement Studio\DotNET\v4.0\AnyCPU\NationalInstruments.Com 19.0.40\NationalInstruments.Com mon mon. DLL

NationalInstruments. DAQmx. DLL dynamic libraries located in C: \ Program Files \ (x86) National Instruments \ MeasurementStudioVS2012 \ DotNET \ Assemblies (64 – bit) \ Current \ NationalInstruments DAQmx. DLL.

The code framework is a C# version.

/ / create the acquisition Task using (Task myTask = new Task ()) {/ / create a virtual channel myTask. AIChannels. CreateVoltageChannel (” SimDev1 / ai0 “, / / physical channel

“”,// The name of the physical channel (AITerminalConfiguration)(-1), // -1 means to use the default value

-10, // minimum value

10, // Max aiVolTageunits. pulse);

/ / configuration of time domain parameter myTask. Timing. ConfigureSampleClock (” “, / / external clock source line or use the “” as the internal clock

1000, // Expected rate of the external clock or actual rate of the internal clock

SampleClockActiveEdge. Rising, / / Rising or falling edge to obtain SampleQuantityMode FiniteSamples, / / continuous or limited samples

1000 // Finite number of samples to get or use for the buffer size (if contiguous)

);

Mytask.control (taskAction.verify); MyAnalogReader = new****AnalogMultiChannelReader(mytask-stream);

For (int I =0; i<1000; I++) {/ / read the data from the channel double [] data = myAnalogReader. ReadSingleSample (); // TODO: assign to the corresponding variable

}}

2. Build the collection project

The collection project development environment can be installed with VisualStudio, ni-DAqMX software, under C:\Users\Public\Documents\National Instruments\ ni-daq \Examples\DotNET4.5, An example of ni-DAqmx. This paper uses Gusi measurement and control master to build, the software can quickly build the user interface, convenient to display the data collected with charts, similar to LabView software.

The final renderings of this example are shown below.

2.1 Create a project and create variables

Master as a first step, through the measurement and control software, in new projects in the project properties dialog box reference NI – DAQmx library NationalInstruments.Com mon. DLL and NationalInstruments DAQmx. DLL.

Second, create the variable container “Voltage measurement” and set the cache Capacity property to 10000. Under which the “voltage” variable is established.

2.2 Design the user interface

This example user interface controls: LineChart (graph), TableGrid (table), ComboBox (channel list), SpinEditBox (numeric parameter setting), Button (Button).

Key configurations:

LineChart: ChartSeries attribute (format: “< series name 1>,<X variable name >,<Y variable name >; < series name 2>,<X variable name >,<Y variable name >; … “; This example is set to: Voltage curve diagram, serial number, voltage)

DataProvider property: Bind to “Voltage measurement”

TableGrid: DataSeries property (format: “< variable name 1>,< column 1 name 1>; < variable 2 names >,< column 2 names >; … “; This example is set to: Voltage, voltage)

DataSource property: Binds to the Voltage measurement variable container

2.3 Writing collection scripts

After the design of “Voltage capture screen” is completed, two new events are created, which are Loaded event of voltage capture screen and Click event of BtnStart button.

Initialize the list of channels in the Loaded event function of the capture voltage screen, and perform data collection in the Click event function of the BtnStart button.

NI script reference library namespace NationalInstruments and NationalInstruments DAQmx, can directly use dynamic class in the library.

Main interface code:

using System; using System.Linq; using System.Windows; using System.Windows.Controls; using Genesis; using Genesis.Scripting; using Genesis.Workbench; using Genesis.Workbench.Schema; using Genesis.Windows.Controls; using NationalInstruments; using NationalInstruments.DAQmx; public class Schema_FDA16E3EDD1843278B9C31574BF2A0A7 { public ProjectContext Context { get; set; } // public void BtnStart_Click(Object sender, System. Windows. RoutedEventArgs e) {try {/ / remove this variable cache. Context. Variants [r]. "voltage measurement" Purge (); this.Context.GetSchemaElement<Chart>(sender,"ChartCurve").Clear(); this.Context.GetSchemaElement<TableGrid>(sender,"TgData").Clear(); // double minValue = (double)this.Context.GetSchemaElement<SpinEditBox>(sender,"SbMinValue").Value; double maxValue = (double)this.Context.GetSchemaElement<SpinEditBox>(sender,"SbMaxValue").Value; string channel = this.Context.GetSchemaElement<ComboBox>(sender,"CmbChannels").SelectedItem.ToString(); double sampleRate = (double)this.Context.GetSchemaElement<SpinEditBox>(sender,"SbSampleRate").Value; int samplesPerChannel = (int)this.Context.GetSchemaElement<SpinEditBox>(sender,"SbSamplesPerChannel").Value; / / create the acquisition Task using (Task myTask = new Task ()) {/ / create a virtual channel myTask. AIChannels. CreateVoltageChannel (channel, "", (AITerminalConfiguration)(-1),minValue, maxValue, AIVoltageUnits.Volts); / / configuration of time domain parameter myTask. Timing. ConfigureSampleClock (" ", sampleRate SampleClockActiveEdge. Rising, SampleQuantityMode.FiniteSamples, samplesPerChannel); Mytask.control (taskAction.verify); AnalogMultiChannelReader myAnalogReader = new AnalogMultiChannelReader(myTask.Stream); For (int I =0; i<samplesPerChannel; I++) {/ / read the data from the channel double [] data = myAnalogReader. ReadSingleSample (); Variants[" Variants "].Value = data.Length > 0? data[0] : 0; } } } catch(DaqException exception) { // Display Errors SystemContext.ShowMessageBox("DAQmx",exception.Message,System.Windows.MessageBoxButton.OK,System.Windows.MessageBoxImage .Error); }} public void loaded (Object sender, RoutedEventArgs e) { ComboBox cmb = this.Context.GetSchemaElement<ComboBox>(sender,"CmbChannels"); string[] channels = DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.AI, PhysicalChannelAccess.External); cmb.ItemsSource = channels; cmb.SelectedIndex = channels.ToList().IndexOf("SimDev1/ai0"); }}Copy the code

3. Summary

Instrument manufacturers will provide dynamic link libraries for their instruments and equipment, for third-party software to control their instruments and equipment, such as NI big factory is a complete set of driver library, NI-DAQMX is NI’s new driver architecture and API, has been able to hide the complex underlying logic, Provide a set of easy to use object-oriented libraries for developers to use, so that developers can complete data collection in just a dozen lines of code.

In addition, the master gussie measurement and control software is also an open measurement and control software development platform, the software can carry on the configuration process of the test, can the custom communication protocol for communication equipment, to develop a beautiful user interface, etc., more suitable for data acquisition and monitoring, device simulation, communication protocol to monitor and analysis, the communication protocol conformance testing and other fields.