Example Code

Vibration Continuous Acquisition with Triggering in C# .NET with NI-DAQmx

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Hardware

  • cDAQ-9174
  • NI-9234
  • NI-9344

    Software

  • Measurement Studio

    Driver

  • NI-DAQmx

    Programming Language

  • .NET
  • C Sharp

Code and Documents

Attachment

Description

This Windows Forms Application allows users to acquire and plot vibration data from a C Series Sound and Vibration Input Module, in addition to using digital edge triggering. The script utilizes NI-DAQmx, Measurement Studio, and the Math.NET Numerics toolkit.

 

The code begins by instantiating the following variables: the maximum and minimum vibration, the accelerometer sensitivity, and the current excitation value. The sample rate and number of samples per channel are instantiated through user input within the Windows Forms application. Then, the DAQ task is created. Within the task, a channel for the accelerometer is created, the timing of that task is configured, and the trigger is configured. A single channer reader is instantiated using the DAQmx “Analog Single Channel Reader” class. An array of doubles for the time data is generated using the Math.NET Numerics’ “Generate Linear Spaced method.” Data is acquired in a for loop through the “ReadMultiSample” function. This data and the time data are continuously plotted in the Measurement Studio scatter graph control during each iteration, as the graph’s “ImmediateUpdates” property is set to true. Overall, this program flow follows the same programming flow that you typically see in NI drivers: open, configure, read or write, and close.

 

If necessary, this script can be modified to accept different measurement and triggering types, longer or unlimited acquisition time, and more. For more information, read the documentation in the links provided below.

 

 

How to Use

To utilize the application:

  1. Connect your C Series module and CompactDAQ chassis to your PC.
  2. Open the solution file in Microsoft Visual Studio with the Measurement Studio extension installed.
  3. Run the project.
  4. Input the name of your physical channel in the “Physical Channel” drop down box.
  5. Input the name of your trigger channel in the “Trigger Channel” drop down box.
  6. Input your desired sample rate, in hertz, in the “Sample Rate (Hz)” text box.
  7. Input your desired samples per channel in the “Samples per Channel” text box.
  8. Input your desired iterations to acquire in the “Iterations to Acquire” text box.
  9. Click “Acquire.”

 

Additional Information

This program was built in Microsoft Visual Studio 2019 with an installation of Measurement Studio 2019 f4.

Related Links

Measurement Studio Homepage

 

Measurement Studio Help

 

Math.NET Numerics Homepage

 

Windows Forms Documentation

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors