LabVIEW provides channel templates that you can use to build applications. Each template expresses a different communications protocol. If you are writing a Real-Time or FPGA program, the Streams available will vary slightly (see Channel Wires in LabVIEW Help for specific templates available for RT or FPGA programs.)
A Stream channel operates like a queue: a lossless buffered Stream of values. A Stream only allows for one writer and one reader– the wire is not allowed to fork. The data in this buffer is transferred using a “first-in, first-out” (FIFO) data structure in which elements are held in the buffer and read from the buffer in the same order that they are received. An example of a Stream channel is displayed in Figure 1 below.
Figure 1: Stream Channel
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
A Messenger channel is a buffered channel that allows for “many-to-many” communication in which sending “command-like” messages is needed. Messenger channels can have multiple writers and readers which allow for the interleaving of messages in a significant way for the reader endpoint to interpret. Figure 3 displays a Messenger channel where multiple writers interleave messages that a reader receives.
Figure 2: Messenger Channel
A Tag channel operates like a variable: a single value that code may read or write. Stated formally, a Tag incorporates a one-element, lossy buffer that allows for multiple writers and readers to access the data value most recently written to the buffer.
Tag channels can be used when your application requires that only the most recent value of data is available to waiting parallel loops, (i.e., it does not matter if previous data values are lost). An example of a Tag channel is shown in Figure 3 below.
Figure 3: Tag Channel
Tag channels do not remove all of the programming dangers inherent in variable programming. You can still create “read-modify-write” race conditions using Tags. To avoid this, try to always use the Tag channels to transfer data from one loop to another loop – never have the same loop both read and write the value. Although that kind of variable-like programming seems easy, it is frequently full of hard-to-test situations that will make your program randomly go awry.
Other Channel Templates
Stream, Messenger and Tag cover most data transfer needs, but LabVIEW supplies several specialized channels:
- Accumulator Tag: A variable that tracks the sum of written values from multiple writers to be sent to multiple readers.
- High Speed Stream: A Stream channel that supports higher throughput, but lacks some of the functionality available with normal Stream channels.
- Lossy Stream: A Stream channel that allows for data loss if the buffer is full.
- One Element Stream: A Stream channel optimized for a buffer size of 1; the write endpoint waits if the buffer is full.
- Event Messenger: A channel to transfer messages from multiple writers, each write triggering an event
Based on the needs of your application, you can determine which kind of data transfer protocol is the most appropriate. For more information, refer to the examples for each channel template located at labview\examples\Channels.