Example Code

DAQmx C# Example: Synchronize Two Boards' Digital Outputs and Analog Outputs

Code and Documents

Attachment

Introduction:

Jon Newman from Georgia Tech has created the following example with DAQmx in C# dealing with synchronizing the Digital Outputs and Analog Outputs of our multifunction DAQ boards. This program demonstrates multi-device synchronization for both analog and digital outputs. Using the hardware menu, the user selects the master device, the sampling rate, the signal frequency, the analog voltage and the analog duty cycle. When start is pressed on the main form, AO.0 on all NI M-Series cards will produce square waves with the characteristics in the hardware menu. A single sample digital waveform is produced on all terminals of port 0 on all cards. If neither of the checkboxes on the mainform are checked, then DO will not be synchronized to the start of AO  on a single board and the sample clocks of AO across boards will not be syncronized, resulting in sliding phases between DAQ outputs. If the users starts the program with "Sync devices" checked, then all outputs will be synchronized to the sample clock of the master device, and the sliding phases will disappear. If the user checks "sync analog/digital stats" then the digital output's start will be sychronized to that of the analog outputs, and each digital pulse will mark the start of the analog output's wavelength.

Steps of Example:

1.) Removes any existing tasks

2.) Creates the Tasks

3.) Creates the Virtual Channels for the tasks

4.) Verifies the setting for the tasks

5.) Assigns the Master for the tasks

6.) Synchronizes the clocks and start trigger

7.) Makes a collection of the Writers

8.) Writes the samples to the Buffers

9.) Verifies the synchronize and timing is correct

10.) Starts the Output

11.) Clears Tasks and disposes references.


Jim St
National Instruments
RF Product Support Engineer

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

Contributors