Related Content

Contact Information

Viewpoint Systems, Inc.
800 West Metro Park
Rochester, NY 14623
Phone: 585.475.9555
Fax: 585.475.9645

Viewpoint Data Management, LLC.
800 West Metro Park
Rochester, NY 14623
Phone: 585.475.9555
Fax: 585.475.9645

round top

bulletViewpoint News, Winter 2008


Tips and Techniques: Flexible Data for Queues

In the last issue, we presented some tips for enhancing mouse actions in LabVIEW via the Ctrl key. In this issue, we will follow along with the theme in the main article and provide a flexible way to pass data between the Consumer and Producer loops that will work for any application, thus making the Consumer \ Producer template produced by LabVIEW even more useful.

In the Producer \ Consumer framework template, the Producer loop passes data to the Consumer loop. (See the main article for details on this template.) As illustrated in the main article example, knowing the source of the data assists application development. In that example, a string “name” indicated the data source and the data was an array of doubles.

Download the demo VIs from this article:

 

Source Naming
Bug-free use of a string for the source name requires proper typing: the text in the Producer loop must match the case in the Consumer loop. A better method uses an enum, and a typedef enum at that. It’s not possible to mistype an enum (although you can still select the wrong value), reducing bugs in the Consumer case and preventing debugging frustration while you search for typos. Making the enum a typedef simplifies adding, changing, deleting, enum values: the case structure, enum constants, controls, and indicators all just follows along as desired to any enum changes.


Note how the block diagram above of a simple VI, which uses a state machine, grays out the enum constants while the enum is being edited. After editing, the new enum labels appear without needing to edit the diagram.

 

General Data Typing
Next, we’d like a way to push data between the Producer and Consumer loops in a generic way. The template utilizes a queue to move data between the loops, but the queue definition needs a data type at compile time. To keep the data type general purpose, we need a general purpose data type. A variant supplies this feature, as does a flatten to string, but the former is usually preferred.

Converting data into a variant is simple: use the To Variant tool under the Functions>>Communications>>DataSocket>>Variant or Advanced>>Data Manipulation>>Variant palettes. Note the basic tools are also under the Functions>>Communications>>ActiveX palette.

In the example above, the ‘To Variant’ VI converts the Waveform into a variant, and the ‘Variant To Data’ VI converts it back.

 

Queue Creation and Usage
To create a cluster (typedef, of course) with the appropriate enum and a variant and wire an instance of this typedef cluster into the queue.

To push an element into the queue, create the cluster by combining the enum and a variant created by passing your data into ‘To Variant’ and push the cluster into the queue. To retrieve the data, extract the element from the queue, unbundle, and use ‘Variant To Data’ to convert the variant to your original data. At this point, you will need to use the enum value to assist you in understanding which type of data the variant holds.