Example Code

Using of a Multifunction RIO device as alternative to multiple digital devices

Code and Documents

Attachment

Overview

The availability of multifunctional devices on the market, such as "Multifunction RIO", offers the possibility to update existing test benches advantageously replacing a series of devices such as: Digital Pulse Generator Digital I / O, RS232/485 serial card, etc...


The proposed demo solution shows that, in an object-oriented application developed in LabVIEW according to a device-oriented architecture (i.e. structured in classes for each device), you can reuse all the software already written modifying only the part relating to the resources allocation and, of course, a minimal hardware interface that is not the subject of this article.


In other cases, a Multifunction RIO device can replace any previously existing digital devices.

Furthermore this approach, in addition to offering a tool to solve problems related to the replacement of devices with other multi-function, allows designing software architectures with a greater level of flexibility and abstraction.


The attached file contains the files of the example shown.


The MultiDevices_demo_app.vi is related to the initial project to control three digital pulse generators and a digital I/O card.


The MultiFunctionRIO_demo_app.vi is that changed to control the single board RIO.

Description

The example, representative of a real application, shows the modifications needed to adapt already developed software to handle the initially used devices (three Digital Pulse Generator and a Digital I/O card) to the new hardware configuration that consists in a single Multifunction RIO board.


Starting from a LabVIEW object-oriented application software based on classes written for the management of three Digital Pulse Generators and one Digital card the following figures show the differences with the upgraded code that manages only the Multifunction RIO.


This example highlights that the refactoring is achieved by changing only the resources allocation area that typically represents a tiny portion of the software application, reusing the functional code entirely.


The process to achieve this result is composed by the following steps:

  • For each device to be emulated, develop of a new class (wrapper class) that shall be derived from the class of the device to be replaced (Digital Pulse Generator and Digital I/O).

Immagine 1.JPG

  • Develop of a new class (RIO) that handles the Multifunction RIO

Immagine 2.JPG

  • Define in the RIO private cluster the classes of the devices that should be emulated (three DPG and one DigIO).

Immagine 4.JPG

  • Allocate in the Open method of the RIO class one derived device class for each device to be emulated (three DPG and one DigIO).

Immagine 5.JPG

  • Develop all methods of the RIO class needed to implement the equivalent methods of the derived class.
    The following figure shows the methods needed to implement DPG and DigIO functions.

  Immagine 6.JPG
 

  • Develop all methods of the derived device classes (DGP and DigIO) to invoke methods of the RIO class.
    The following figure shows the methods of the DPG and DigIO classes.

 
Immagine 7.JPG

This procedure will ensure the override of all methods and the linking of the new methods of the Multifunction RIO class.

 
Immagine 3.JPG 

  • Finally, change the existing software only in the resources allocation code without modifying the functional code

Immagine 8.JPG

to obtain...

Immagine 9.JPG

At this point, run the programs and a series of messages will inform you about the executed method.

Requirements

Software: LabVIEW 2011

Hardware: None


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

Contributors