This Python script 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, NumPy, and Matplotlib.
The code begins by instantiating constants such as the sample rate, the samples to acquire, the sampling mode, and the channel and trigger names. The DAQ task is created within a “with” block, as it provides a cleaner, more readable code, in addition to ensuring a proper use of memory resources. Within the task, a channel for the accelerometer is created, the timing of that task is configured, and the trigger is configured. Data is acquired through the “task.read” function in a for loop. Time data is generated using the NumPy linspace function, and both datasets are plotted using Pyplot functions. 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 API documentation in the link provided below.
How to Use
To utilize the script:
Connect your C Series module and CompactDAQ chassis to your PC.
Open the script in a Python 3 IDE.
Modify the variable, “channel_name”, to the name of the module you are using. This name can be found in NI MAX.
If you are using a trigger, modify the variable, “trig_name”, to the name of the trigger channel you are using.
If you are not using a trigger, delete or comment the “trig_name” variable and the line that contains, “task.triggers.start_trigger.cfg_dig_edge_start_trig(trigger_source = trig_name).”
Modify the variables, “sample_rate” and “samples_to_acquire”, to the sample rate and number of samples per channel necessary for your application, respectively.
Run the script
This script was built in the Jupyter Notebook environment with a Python 3 kernel.