Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 36 ยท Projects and Practice

Project: A Multi-Channel Data Logger

Plan and build a multi-channel data logger in LabVIEW: requirements, architecture with producer/consumer loops, scaling, alarms, TDMS or CSV logging, plus a runnable Python model of the logic.

This project ties the chapter together. You will design a logger that reads four temperature channels, scales them, shows them live, raises alarms and writes every sample to a file. Use it as a blueprint for the real VI: the diagram is described in words, and the whole logic is modelled in Python so you can run and extend it here. LabVIEW and DAQ hardware are not available on this site; the "DAQ" below is a simulation, and nothing shown is real measurement output.

Requirements

  1. Read 4 channels at 10 samples per second per channel (voltage from thermocouple-style sensors, scaled to degrees C).
  2. Display the 4 traces on a waveform chart and the latest values numerically.
  3. Alarm when any channel exceeds a high limit (with hysteresis so the alarm does not flicker).
  4. Log every sample with a timestamp to a file; one row per scan.
  5. Stop cleanly with a button, closing the file and the task.

Architecture

Use the producer/consumer pattern with a QMH-style event loop:

flowchart LR
    UI["Event loop<br/>Start, Stop, Limits"] --> MSG[("Command queue")]
    DAQ["Acquisition loop<br/>DAQmx Read every 100 ms"] --> DATA[("Data queue")]
    DATA --> PROC["Processing loop<br/>scale, alarms, chart"]
    DATA --> LOG["Logging loop<br/>write file"]
    MSG --> DAQ

Acquisition never waits for the disk or the graph.

  • Acquisition loop: after DAQmx Create Channel (Analog Input Voltage or Thermocouple), DAQmx Timing (continuous, 10 S/s per channel, hardware clocked), and DAQmx Start, it reads 1 sample per channel per iteration and enqueues {timestamp, values[4]}.
  • Processing loop: dequeues, applies scaling, tests alarms, updates the chart. UI updates happen here, not in the acquisition loop.
  • Logging loop: its own queue (use a second queue so slow disk writes do not slow the display). Opens a TDMS (or text) file once, writes each scan, closes it on Stop.
  • Stop: the event loop enqueues a Stop element into every queue; each loop closes its resources and exits. See error handling for the error wire in each loop.

Scaling

Assume each sensor outputs 10 mV per degree C with a 0 V offset (an amplified analog sensor, not a bare thermocouple). The scaling is temp_C = volts / 0.010. With a thermocouple channel, DAQmx scales and does cold-junction compensation for you, and you skip this step.

Alarms with hysteresis

An alarm that turns on at 80 C and off at 78 C avoids rapid toggling near the limit. Each channel keeps a Boolean in a shift register: if the alarm is off and the value exceeds the high limit, set it; if on and the value falls below the high limit minus the hysteresis, clear it.

Model of the logic

Python Scale, alarm and log (Python model)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The model checks the same rules as the diagram. Change HIGH or the sensor base values and see when the alarm toggles.

File format choices

Format Good for Notes
CSV / text Small runs, easy to open in Excel Slow and large at high rates; write Format Into String lines in the consumer
TDMS Long, fast logs Binary, channel groups and properties, opens in Excel with an add-in or in DIAdem; write with TDMS Open, Write, Close
Database (SQL) Many users, queries Use the Database Connectivity Toolkit or ODBC; batch inserts

For this project use TDMS when the rate goes up, but start with text so you can check the file by eye.

Extending the project

  • Add a configuration file (ini) for channel names, limits and rate, read at start (Read Key (String)).
  • Add file rollover: start a new file every hour or every 100 MB.
  • Show a history graph with Chart History Length set to hold minutes of data.
  • Send an email or SMS on alarm via a command-line tool or .NET SmtpClient.
  • Build an executable and installer and run it for a day, watching memory (performance).

Test plan

  1. Run with a simulated DAQ device (NI MAX > Create New > Simulated NI-DAQmx Device) and check the file's rows.
  2. Feed a constant voltage and verify the scaling.
  3. Force values above the limit and verify alarm on and off.
  4. Press Stop in the middle of a run: the file closes properly and the task is cleared.
  5. Pull the cable (or stop the simulator): the error message appears and the program shuts down safely.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why use a separate queue for the logging loop?

    Separate queues isolate slow consumers from fast ones.
  2. 2. What is the purpose of hysteresis in an alarm?

    Different on and off thresholds prevent flicker.
  3. 3. A sensor gives 10 mV per degree C. What temperature is 0.55 V?

    0.55 V divided by 0.010 V per degree C is 55 C.
  4. 4. How should the logger end after Stop?

    A clean stop releases the file and the DAQ task.

Summary

  • Split acquisition, processing and logging into parallel loops joined by queues.
  • Scale in the processing loop, apply alarms with hysteresis and log with a timestamp.
  • Choose CSV for small runs, TDMS for long fast ones.
  • Test with a simulated device, forced limits and an interrupted run.

Next: Project: A PID Temperature Controller