Example Code

Object Oriented Function Generator Hardware Abstraction

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.


  • Modular Instrumentation


  • LabVIEW FPGA Module
  • LabVIEW


  • NI RIO

Code and Documents


This application is designed to abstract the function generator hardware so that it can accept any type of function generator used.

This application is designed to abstract the function generator hardware so that it can accept any type of function generator used. Object Oriented Programming architecture is used to allow for simple class implementation which allows anyone to add a new class which covers their function generator used without having to reprogram the overall application. The front panel design for the Application Specific Layer is like in the following picture. Bear in mind that this is the part of the application that requires no programming when a new function generator is added all you simply have to do is create a new class and wire this in to the block diagram.

FGEN front panel.png





  1. LabVIEW 2012 (or compatible)

Steps to Implement or Execute Code

As had been mentioned above the implementation of a new class is fairly simple. When you open the “Project.lvproj” project explorer you will be greeted by the “FGEN Application Specific Layer.vi” and 3 auto populating folders named “FGEN”, “NI-FGEN” and “AUX-FGEN”. The “FGEN Application Specific Layer.vi” is where you will find the front panel as shown above. This is where the class and its methods are placed on the block diagram to perform the different functions that you would expect from a function generator.


project fgen.png


If you open the “FGEN” auto populating folder you will find the generic FGEN class which should contain all the methods that are performed by any function generator. The descriptions of these methods can be found below. If you open the “NI-FGEN” auto populating folder you will find the NI-FGEN class which contains these methods as they have inherited the generic classes methods and then have extra coding to perform National Instruments function generator specific functions (not covered in the generic class). As can be seen in the below diagram we can simply take the FGEN class and methods and wire them together on the block diagram creating our Application Specific Layer (first diagram). Note that all the methods are coloured with a dark blue band, similar to the class.


fgen class asl.png


If you wanted to change the hardware from the generic type to the national instruments type all you would now have to do is wire in a new class. Through dynamic dispatch the methods will change to fit the new class as can be seen on the following diagram. Note that the methods have changed colour to fit the new class.


nifgen class asl.png


This shows the true power of Object Oriented Programming when abstracting the hardware as the front panel and methods did not need recoding when a different type of function generator hardware was required. A simple drag and drop of the class is all the user needs to do (or use a case structure).



Class Method Descriptions:


Initialise – Initialises the Function Generator providing the resource of the hardware used.

Calibrate – Calibrates the Function Generator if the hardware has the ability to do so, otherwise this VI does nothing.

Configure – Configures the Function Generator, setting the output mode, waveform type, channels, frequency, amplitude, DC offset and start phase.

Start Generation – Starts the generation of the Function Generator.

Done – Checks whether the settings have been confirmed by the hardware.

Stop Generation – Stops the generation of the Function Generator.

Release – Closes the instrument I/O session and de-allocates any memory used by the Function Generator.



Project that it is used in:


An interesting project this application and other OOP applications is an automated test equipment project for the testing of semiconductor chips. A video about this project can be found here.


Additional Information or References
VI Snippet


 **This document has been updated to meet the current required format for the NI Code Exchange.**

Larry Colvin
Associate Principal Engineer
Dyson Technology Ltd.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.