Conditional Logging in LabVIEW with your NI USB-TC01

Updated Nov 16, 2023



  • USB-TC


  • LabVIEW

LabVIEW provides an easy-to-use application development environment designed specifically for the needs of engineers and scientists. Without any prior programming experience, you can use LabVIEW to take measurements from your USB-TC01 and create custom software functionality.

Typical data-logging software normally requires the manual starting and stopping of logging. Using LabVIEW, you can define software functionality to programmatically start or stop logging data under certain conditions. In some cases, it may be useful to log data during only certain dates and times, when a measurement is outside of a threshold, or if some event has occured.

Conditional Logging with LabVIEW

Follow these eight steps to build a LabVIEW application that logs data during only a specified start and stop time.

  1. Start with a basic measurement and data logging VI, similar to the one created in the Data Logging in LabVIEW tutorial.

Figure 1. LabVIEW applications consist of a Front Panel (left) and Block Diagram (right). In each iteration of the while loop, the DAQ Assistant acquires one data point and passes it to the Write to Measurement File Express VI.

  1. Right-click on the Block Diagram, select Exec Control » Case Structure, and drag the Case Structure around the Write to Measurement File function.

Figure 2. The code in the Case Structure executes only if the boolean condition at the Case Selector terminal is true.

  1. To check the current time, you need functions outside of the basic Express palette. Right-click on the Block Diagram, click the arrows at the bottom to expand the palette, navigate to the Programming palette and pin it to the screen.

Figure 3. Expand the Block Diagram palette to see more functions outside of the basic Express palette.

  1. Select Comparison » In Range and Coerce, place it on the Block Diagram, and wire the In Range? boolean output to the Case Selector terminal of the Case Structure.

Figure 4. The In Range and Coerce function checks if a certain value is within the range of two other values.

  1. Go back to the Programming palette, select Timing » Get Date/Time in Seconds, place it on the Block Diagram, and wire it to the middle terminal of the In Range and Coerce function.

Figure 5. The Get Date/Time function returns the current date and time in each iteration of the loop.

  1. Right-click on the upper limit terminal of the In Range and Coerce function, select Create » Control, and name it Stop Time. Do the same for the lower limit terminal and name it Start Time. Also, create an indicator for the output of the In Range and Coerce function called Logging?

Figure 6. The In Range and Coerce function checks if the current time is between the Start Time and Stop Time, and outputs the result to the Case Structure. The Logging? indictor displays if the current time is within range.

  1. On the Front Panel, configure the Start Time and Stop Time controls.

Figure 7. Set the time and date to start and stop logging.

  1. Press the run button in the top left corner to start your application.

Figure 8. The run button starts your LabVIEW application.

Download the attached LabVIEW Code:


Next Steps