To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This example demonstrates one method for saving a column of relative time data to your data set in a spreadsheet file.
Description
The following example demonstrates one method for saving a column of relative time data to your data set in a spreadsheet file. The example utilizes array manipulation, and Waveform data components to assemble a data set that includes a column of time data correlated with each sample. This example was configured for a multi-channel single sample acquisition; however, the methods may be adapted to many forms of data collection tasks.
Requirements
Software
Hardware
Steps to Implement or Execute Code
Additional Information or References
1. Configure your Data Acquisitions Task
(Note: This example is designed to sample 1 point, from multiple channels.)
a. Create a virtual channel for you desired acquisition type, and configure the physical channels.
b. Configure the acquisition Sample Clock for your task.
c. Send your configuration to the hardware by Starting the task.
d. Read in an array of 1D Waveforms from each channel.
e. Clear the task after the test completes.
2. Configure your spreadsheet file.
a. Use the File Dialog function to create an initial Windows prompt to select, or save to a new file.
(Note: Be sure to include the .xls extension, if using Microsoft Excel for data manipulation.)
b. Place a Write to Spreadsheet VI for your header information.
c. Create a String Array containing your desired header names, and wire it to the 1D input terminal.
3. Configure the Relative Time Stamp
a. Initialize the system by Getting the Current Date/Time in Seconds.
b. Extract the first Waveform sampled by the DAQmx Task.
c. Get the Waveform Components, and select the sample time, t0, as the output.
d. Use a Subtract function to calculate the relative elapsed time between the beginning of the task, and the current sample.
4. Extract and assemble your data samples, with the time stamp.
a. Use a For loop, and Get Waveform Components to extract the data from each channel. Use an Index Array to convert from the Array data type to a numeric.
b. Use the Insert Into Array VI, to append the Relative Time Stamp to the first column of the data set.
c. Append your time and sample data to the spreadsheet, using the Write to Spreadsheet VI.(Note: Be sure to wire a True Boolean to the Append input of the function to preserve your header style.)
**This document has been updated to meet the current required format for the NI Code Exchange.**
Patrick Corcoran
Application Engineering Specialist | Control
National Instruments
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
if you have continuous measurements of many channels (in my case, I have to record the current, voltage and 4 temperatures), how can you log the time (and date), or at least the time in which they where measured?
thanks!