Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 36 ยท Projects and Practice

Practice Exercises and Review

Practice LabVIEW instrument control, DAQ, design patterns, debugging and deployment with graded exercises, runnable Python checkers for the calculations, and a self-review checklist.

Reading about LabVIEW is half the job; the other half is building VIs. This lesson gives you graded exercises for chapters 5 to 8, with a way to check your answers: the numerical ones come with Python checkers that run here, and the build ones have a clear acceptance test. LabVIEW is not available on this site, so open it on your computer for the diagram tasks.

How to use this page

  1. Try each exercise on your own in LabVIEW (or on paper for the calculations).
  2. Compare with the checker or the acceptance test.
  3. If you are stuck, re-read the lesson linked in the exercise.

Warm-up: calculations you should do by hand

Python Check your sampling and resolution answers

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.

Expected reasoning: Nyquist is fs/2; a tone above it folds; an LSB is range divided by 2^bits; a 4 to 20 mA loop is linear with a live zero at 4 mA; bin width is fs/N (sampling lesson).

Exercises: instrument control

E1. Identify. Write a VI that opens a VISA resource chosen from a resource control, sends *IDN?, reads the reply (enough bytes), closes the session, and shows any error in a dialog. Accept when: it works for a real or simulated instrument, and the session is closed even when the read times out (VISA lesson).

E2. Wrapper. Create Query Number.vi with inputs session, command, error in; outputs value, error out. It must append a line feed, read, trim whitespace and convert to a double. Accept when: an empty reply produces an error, not a zero.

E3. Error queue. Add Drain Errors.vi that calls :SYST:ERR? until the code is 0 and returns all messages as a string array. Test it against the simulator.

Python Model solution of E2's parsing rules

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.

Exercises: DAQ

E4. Finite capture. Using DAQmx VIs (not the Assistant), acquire 1000 samples at 10 kS/s from one analog input and display them on a graph, then stop and clear the task. Accept when: the time axis (dt = 0.1 ms) is right and a second run works without restarting LabVIEW.

E5. Continuous with scaling. Acquire continuously at 1 kS/s, read 100 samples per iteration, scale a 4-20 mA signal to 0-10 bar, and show a chart. Accept when: it runs for 10 minutes without a buffer overflow error.

E6. Spectrum. Generate (or acquire) a 50 Hz sine plus noise, compute the power spectrum with a Hanning window, and display the peak frequency numerically. Accept when: the reading is 50 Hz within one bin.

Python Check for E5 scaling and E6 bin size

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.

Exercises: design patterns

E7. Traffic light state machine. Build a state machine with states Red, Green, Yellow, Fault. Use a typedef enum and a shift register. Each state lasts a configurable time; a front-panel Fault button forces flashing yellow; Stop ends the VI (state machines).

E8. Producer/consumer logger. Make the producer generate a random number every 50 ms and the consumer append lines to a text file with a timestamp. Stop with a sentinel element so the last values are saved (producer/consumer).

E9. QMH skeleton. Start from the QMH template and add three messages: Acquire, Save, Exit. Acquire must enqueue Save. Add a Default case that reports unknown messages (QMH).

E10. Event UI. Add a Panel Close? filter event that asks "Save before closing?" and discards the close request on Cancel (events).

Python Traffic light model for E7

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.

Exercises: debugging and testing

E11. Find the bug. Build a VI that sums an array in a While Loop with an uninitialised shift register. Run it twice with the same input and explain the different results; fix it (debugging).

E12. Error path. Write a subVI chain Open, Read, Close where Read fails. Prove with a probe that Close still runs and the original error reaches the handler (errors).

E13. Unit test. Create three test cases for a Scale subVI: lower end, upper end, degenerate range. Run them with the Unit Test Framework or JKI VI Tester (testing).

Python Expected values for E11

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.

Exercises: deployment and tuning

E14. Build. Build an EXE and installer for E8. Install it on a computer without LabVIEW and run it (build lesson).

E15. Libraries. Move your instrument subVIs into a .lvlib, make internals private, and build a packed library that another project can call (libraries lesson).

E16. Profile. Make a VI that builds a 100,000-element array with Build Array in a loop, then rewrite with preallocation. Compare with the profiler (performance).

Capstone ideas

  • Combine the data logger and the PID controller so setpoint, process variable and output are logged.
  • Run the whole application against the SCPI simulator, then switch Simulate off to use real hardware.
  • Add an automated test run and a VI Analyzer pass to your build.

Self-review checklist

  • Do all my I/O VIs have error in and error out, wired through to a handler?
  • Are all tasks, files, sessions and queues closed or released on every path?
  • Is each loop either event-driven or blocking on a queue, rather than spinning?
  • Are hardware calls behind a layer that tests can replace?
  • Can a clean computer run the installer and my application?
  • Is there at least one test for every calculation?

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A VI works the first time you run it but gives a different total the second time. Which is the most likely cause?

    Shift registers keep their value between runs unless you wire an initial value.
  2. 2. You sample at 10 kS/s. What is the highest frequency you can represent?

    Nyquist is half the sample rate.
  3. 3. Which pattern keeps the user interface responsive while slow work runs?

    Separating the event loop from the work loop keeps the UI free.
  4. 4. What is the best final check before delivering an application?

    A clean machine reveals missing drivers, files and paths.

Summary

  • Practise with exercises that you can check: calculations with the runnable checkers, builds with acceptance tests.
  • The recurring ideas of this chapter are error wires, closing resources, queues and events, simulation for testing and clean-machine deployment.
  • Combine the projects into a capstone and automate the tests.

Next: Back to the LabVIEW track page