Example Code

Add Relative Time Data Column to Spreadsheet File

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

  • Data Acquisition (DAQ)

    Software

  • LabVIEW

    Driver

  • NI DAQmx

Code and Documents

Attachment

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

  • LabVIEW 2012 or compatible
  • NI-DAQmx 9.5.5 or compatible

Hardware

  • NI Multifunction DAQ Device

 

Steps to Implement or Execute Code

  1. Configure the parameter for the right channel and device.
  2. Connect your hardware appropriately.
  3. Run the VI.

 

Additional Information or References

Relative_Time_Data.png

 

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.

Comments
Kanenas
Member
Member
on

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!