cancel
Showing results for 
Search instead for 
Did you mean: 
Knowledge Base

Reference Design Content

Top Contributors
Sort by:
In distributed applications using the Current Value Table (CVT) there is a fundamental need to pass CVT data between targets. This document describes one method of communication between CVT instances on different targets using a TCP/IP client/server protocol.   Description   The primary function of the client communication interface is to share information between CVT instances on the server and the client.  This is done by mirroring portions of the CVT from one side to the other and vice versa.  Generally speaking, there will be certain tags on the server that the client has an interest in.  By the same token, there will be information on the client that needs to be passed down to the server.  For example, if we want to control temperature, then the client needs to send setpoints to the server and then monitor the temperature readings returned by the server. In applications involving hundreds or perhaps thousands of tags, the importance of efficient communication becomes obvious.  TCP/IP is a standard protocol that is relatively simple yet it offers high throughput and scales well for high-channel-count systems.   Additional Documentation   CVT Client Communication (CCC) Reference Library   Compatibility and Requirements   LabVIEW 2010 or later   Dependencies   NI Current Value Table >= 3.3.0.13 NI Simple Messaging (STM) Library >= 3.0.0.4   Source Code and Issue Tracker:   https://github.com/NISystemsEngineering/CVTClientCommunication/ https://github.com/NISystemsEngineering/CVTClientCommunication/issues   Download   CVT Client Communication (CCC) Reference Library on LV Tools Network   Version 3 of CCC requires version 3 or later of CVT and STM.   Support and Feedback   Feedback and discussion on the CVT-based reference designs can be found here: https://decibel.ni.com/content/projects/cvt-based-reference-designs-for-machine-control
View full article
The Syslog protocol is a simple UDP communication standard for sending messages from distributed systems and processes to a central collector for logging and later analysis. It can be used for debugging embedded and distributed applications by sending simple messages from the embedded code to a separate system running the syslog collector, also called the syslog server or daemon.   Download: Syslog on VIPM Reference: http://www.ni.com/example/30980/en/  Discussion and Support: https://forums.ni.com/t5/Components/Syslog-Component/m-p/746501  or below
View full article
The CompactRIO Waveform Reference Library contains host VIs, FPGA templates, and example  projects for performing waveform data acquisition on NI RIO hardware.  The configuration and acquisition VIs incorporate optimizations and best  practices for the RIO platform, and you can easily modify the examples  to jump-start your application development.   Code and Documentation: https://www.ni.com/en/support/documentation/supplemental/09/ni-compactrio-waveform-reference-library.html Discussion Forum: https://forums.ni.com/t5/Components/CompactRIO-Waveform-Library/m-p/950976    
View full article
The Dictionary Library enables developers to dynamically define global key-value pairs and access them by name anywhere in their LabVIEW application. The library uses variants when returning values and requires knowledge of casting variants to different data types and handling errors.
View full article
The Messenger Library is available on the LabVIEW Tools Network and on LAVA, contains the architecture that I use for applications.  It includes templates for "actors" (note: NOT Actor Framework actors) and I have posted several videos on YouTube as introduction/instruction.   Description   The Messenger Library is an extensive library for passing messages between parallel processes. It generalizes the communication method, allowing the message sender to use the method provided by the receiver. Supported communication methods include wrappings of simple queues, user events, and notifiers, as well a more complex channels such as a TCP server and client. In addition, one can configure simple forwarding addresses ("Observers"), which can send messages to multiple destinations, optionally with modifications such as adding a prefix to the message label, relabeling, or substituting a different message.   Communication patterns supported include request-reply (asynchronous or synchronous), where the reply is sent to a <reply address> attached to the request, and register-notify, where one process sends a registration message to another in order to subscribe to a series of updates.  It also supports scatter-gather, the gathering of replies from multiple senders into an array of messages.   A framework for dynamically-launched VI "actors" is also provided, including example templates, which can be accessed via the Tools menu (from an open Project, select Tools>>Messenger Library>>Create Actor from Template).  An "Actor Manager" debug tool is also installed under the Tools menu.  Please note that this package is not related to the NI Actor Framework, other than that both packages are influenced by the Actor Model.   Tutorials   The first video:   Additional Videos
View full article
STM is an application-layer communication protocol, built on top of a transport-layer protocol (e.g. TCP), to simplify the process of sending and receiving messages and data packets between different systems in an application. The list of messages and data items used in a communication link are defined as part of the application and exchanged between the two end points of the communication link when the connection is established.
View full article
NI SmartBalloon's ultimate goal is to offer a valuable alternative to the use of modal dialog boxes in LabVIEW. Native LabVIEW dialog boxes are modal and their look cannot be tuned. These are two big drawbacks that NI SmartBalloon leverages, while ensuring the status, errors, warnings and other notifications are properly displayed to the screen.   Description   NI SmartBalloon offers any LabVIEWdeveloper an opportunity to produce highly customizable and modern-looking balloon notifications vertically enqueued on the right side of your monitor. The library is basically made of 4 functions (see diagram below). All the intelligence is abstracted in an engine that is responsible for spawning the balloons at the right position on the screen, and move them accordingly when a balloon vanishes or was dismissed. Indeed, the new SmartBalloon 3.0 can handle multiple balloons being displayed at a given time (the maximum number of balloons depends on the resolution of the screen).   Examples   Here is an example provided with the package to show the ease of use of the API:     Requirements   Software LabVIEW 2015 or later (Full or Professional Versions)    References NI SmartBalloon Library on LVTN   Support   Please post comments, feedback and questions in the comments below.   History   Version Date Description/Changes 3.0.1 25/10/2016 Fixed an issue where some palette VIs could be broken when dropped on a new VI. The SmartBalloon events should now be accessed through a property node on the SmartBalloon Library object wire. Updated Sample Code License text. 3.0.0 13/06/2016 Refined architecture (incompatible with older versions) Ability to enqueue several balloons on the screen Ability to capture when a balloon is clicked 2.0 03/2015 Added new balloon type (Symbol+Text) 1.0 05/2014 Initial Release   Downloads NI SmartBalloon on VIPM
View full article
This LabVIEW reference library allow you to convert an arbitrary  LabVIEW data structure to and from a human-readable XML string (or  file).  The reference library (GXML) uses a custom data schema which  emphasizes data hierarchy and makes the XML easier to read.   Code: vipm://ni_lib_gxml Discussion Forum:https://forums.ni.com/t5/Components/Reference-Library-for-Converting-Between-LabVIEW-and-XML-Data/td-p/1041232    
View full article
The current version of this library is provided in VI Package Manager.   Link to Most Recent Version attached below   Overview   Modbus is a commonly-used protocol for industrial communication. At present, National Instruments provides three options for Modbus connectivity.   Modbus I/O server, available through the LabVIEW Real-Time Module or the LabVIEW Datalogging and Supervisory Control (DSC) Module, which provides a high-level API for accessing Modbus data. Learn more at Connect LabVIEW to Any PLC With Modbus This free Modbus Library API release, which includes a low-level interface and provides control over Modbus not offered by I/O servers at the expense of the connection management and request scripting offered by the higher-level API. **This Library is Unsupported**   Description   Modbus is an application-level protocol which defines a set of functions used for interaction between a master [client] device, such as an HMI or PAC, and a slave [server] device, like a PLC, gateway, or sensor. Every interaction between master and slave is a request-response interaction. That is, the master initiates all communication and is responsible for sending requests to which the slave must respond. A number of function codes are pre-defined by the protocol for both setting and getting data on a slave, but other functions may be defined by the user. One goal of this NI Labs release is to provide a better platform for users intending to support additional function codes on either the master or slave sides of the protocol, and to allow users to customize behavior more readily if a particular device does not adhere to the specification. In this library, the request generation and response parsing code is defined by the master function definition.   The pre-defined function codes focus on 4 main types of data: coils, discrete inputs, holding registers, and input registers. Coils and discrete inputs are two sets of 65,536 boolean values which can be accessed by the master. Master devices have full read/write access to coils, but discrete inputs are read-only from the point of view of the master. Holding registers and input registers are two sets of 65,536 integer values (16-bit, unsigned) which can be accessed by the master. As with the boolean values, holding registers are read/write while input registers can only be written by the slave device itself. Each bank of values is addressed by a single U16 integer, meaning that the address ranges from 0 to 65,535.   Besides these 4 types of data, later versions of the specification added a new type of data, called objects. These objects are simply strings that can be stored in the memory of the device and which contain device identification data. The definition and meaning of objects 0x00 through 0x06 is defined by the specification, and objects 0x07 through 0x7F are reserved. However, objects 0x80 through 0xFF can be defined by the slave device and chosen to store any data chosen by the device manufacturer. The first three objects are called "basic" objects, all other specified objects are "regular", and device-defined objects are "extended". For more information, view the Modbus specification.   These data sets are contained in the slave data model. The default Modbus implementation is called the standard data model, but other data models can be generated to override the standard model. This data model also defines how the slave will respond to master requests.   Wrapping this Modbus protocol data unit (PDU) is an application data unit (ADU) that defines the full packet sent out across the network. There are three main variants, IP, RTU, or ASCII, but it is straightforward to implement a new packet format. IP is intended to be used with a TCP/IP network, while RTU and ASCII are binary and human-readable packets for a serial network. In this library's implementation, the packet format is independent of the network. For historical reasons, because Modbus was originally developed for serial networks, the PDU is limited to 253 bytes. For RTU and ASCII ADUs, this creates an ADU size of 256 bytes. The IP ADU contains additional information and is 260 bytes long. In this library, the code set associated with the ADU is called the transmission data unit, and the code associated with the PDU is called the Modbus data unit. The network across which the ADU is transferred is defined by the network protocol family of classes.   All functions in this library are wrapped by an API class which includes an implementation of master and slave functionality. This API is what is shown on the palette. The object-oriented nature of the code makes it easy to modify API behavior, or even core function behavior, as necessary.   Using the Library   This library is distributed as a VI package, meaning that it requires JKI's VI Package Manager for installation. Once installed, the Modbus API will be available on the Data Communication function palette and the Add-ons Palette. Each palette (master and slave) contains a basic example of the functionality of the API. The master example demonstrates basic connection and error handling, as well as the ability to set and get certain data items from the slave. The slave example demonstrates setting and getting data, as well as the retrieval of properties related to the background connection handler including the status of the handler, and the number and status of all current connections.   Requirements   Software LabVIEW 2012 or later NI-VISA for Modbus serial communication Support   At present, this library is experimental and unsupported. Please see the licensing notice below. For the discussion around this API, please visit the NI LabVIEW Modbus API Discussion.   NI Labs Licensing Notice   Because the software technology available on NI Labs is experimental and has not yet been released for large-scale commercial use or fully tested by NI, the terms of the NI Labs license agreements vary from the standard NI software license terms. Further, the license terms for specific NI Labs technology may vary. Please carefully read the terms of the license agreement included with each NI Labs download before accepting those terms. This library uses the NI Sample Code License.   Known Issues     Release Notes   [1.0.9.22] Warning: A VI was renamed in this version to make it consistent with the rest of the library naming scheme. Specifically Write Multiple Registers was renamed to Write Multiple Holding Registers. In addition to this change, documentation was correct with respect to the default parity and Read Exception Status correctly checks to make sure that the ADU is a serial ADU.   Download   The current version of this library is provided in VI Package Manager.   Source Code   The source code for the LabVIEW Modbus API is hosted on the following GitHub repo.   https://github.com/NISystemsEngineering/LabVIEW-Modbus-API   Please submit issues on the GitHub repo for any bug reports or feature suggestions, or submit a pull request if you make enhancements to the API.   Changelog: 22-March-2023: Removed mentions of SAPHIR add-on products "ModBusVIEW over TCP" and "ModBusVIEW over Serial" as they are no longer available.   
View full article
Modbus is an application-level protocol which defines a set of functions used for interaction between a master [client] device, such as an HMI or PAC, and a slave [server] device, like a PLC, gateway, or sensor. Every interaction between master and slave is a request-response interaction. That is, the master initiates all communication and is responsible for sending requests to which the slave must respond. A number of function codes are pre-defined by the protocol for both setting and getting data on a slave, but other functions may be defined by the user. One goal of this NI Labs release is to provide a better platform for users wishing support additional function codes on either the master or slave sides of the protocol, and to allow users to customize behavior more readily if a particular device does not adhere to the specification. In this library, the request generation and response parsing code is defined by the master function definition.   Description and Code: https://forums.ni.com/t5/Reference-Design-Content/LabVIEW-Modbus-API/ta-p/3524019 Discussion: https://forums.ni.com/t5/NI-Labs-Discussions/NI-LabVIEW-Modbus-API-Discussion/td-p/3373078
View full article
Floating point math operations on FPGAs are important for many control and simulation applications. In LabVIEW FPGA, most math operation nodes in the Numeric and Comparison palette support the single-precision floating point data type. However, these primitive nodes cannot run inside a Single-Cycle Timed Loop to achieve higher performance. Additionally, these nodes cannot be configured for resource optimization at the cost of performance.
View full article
Many embedded and industrial control applications require a mechanism to store and manage data in one location in the application so that different parts of the application have access to the current value of I/O channels and others variables. The Current Value Table (CVT) is a set of LabVIEW VIs that developers use to store and retrieve data asynchronously from different parts of an application. The CVT is based on functional global variables, also called LabVIEW 2 style global variables, and can be used on most LabVIEW targets.   Description   Machine control, automation and monitoring applications are typically developed as a number of independent processes running on one or more systems. Each process performs a separate task such as communication to other systems, I/O, control logic, data logging, etc. These independent processes share a set of common data or variables which allows them to work together to accomplish the tasks of the application. Sharing one common set of data enables centralized I/O operations with the I/O data being shared by many processes.   The Current Value Table (CVT) serves as the central data component and can be used in a wide range of applications. It allows other application components to share a common data repository and have direct access to the most up-to-date value of any variable used between components. Using this architecture one component in the application can handle all of the I/O operations and share the I/O data variables or tags with the rest of the application components. Application operations such as alarm detection, user interface updates, process logic, etc. are all handled by separate processes that share the same data repository.   Figure 1: Placing the CVT in context of the application functional blocks   Implementation   The Current Value Table is implemented in a two layer hierarchy consisting of core VIs and API VIs. The core contains all of the functionality of the CVT, including the data storage mechanism and additional service functions. The API VIs provide access to the CVT functionality in a simple interface. There are three groups of API functions that provide slightly different access to the CVT and vary in flexibility and performance, as well as easy-of-use.   Figure 2: CVT VI Hierarchy    The core data structure consists of two VIs which support tag management for the entire CVT, and an additional data storage VI for each data type supported.   The Memory Block polymorphic function stores all data for the system, and consists of a single VI for every data type supported. This functional global variable allows you to clear memory, read or write a single value in memory, and read or write a set of values in a single call.   The Tag List and Group List functions store all information necessary for the access and management of that data. The tag list stores the name, type, description, and memory location of each tag. The group list stores information about any groups formed in the table. Both of these functions store information by name in the form of variant attributes. Variant attribute "get" and "set" functions provide an extremely fast lookup which is superior to a linear array search for data sets larger than approximately 40 tags.   Users can extend the supported data types in the CVT by using the current VIs as a template and adding VIs for additional data types. Booleans, 32-bit integers, double precision floating-point numbers and strings are currently supported.   Core   The core VIs consist of two VIs for each data type supported by the CVT. Each of these VIs is configured to provide a set of functions or methods to their callers and uses shift registers to store data between calls to the VI.     The first of these VIs is the data storage VI called MemBlock. It contains a shift register which stores all of the CVT data for a single data type. It contains a few basic functions (Init, Read, Write) that provide access to the data. Different variables of the same data type are stored in an array in the MemBlock VI. To access an individual variable the caller needs to know the index of the desired data item in the array.         Figure 3: Implementation of the CVT Memory Block Core VI     The second core VI (Tag Memory) maintains a list of properties for each of the values stored in the Memory Block VI including the name and index of each value. This VI enables an application to retrieve the index in the storage array using the variable name. It also stores a string description for each value.     Figure 4: Implementation of the CVT Tag Memory VI   API - Using the CVT   The CVT contains three sets of API functions to provide different interfaces that can be chosen according to the needs of an individual application. The basic API provides simple write and read functionality. Two additional APIs provide a higher performance interface to the CVT, but place some restrictions on the application when using the CVT. All three APIs share the same common core VIs and can be used in conjunction with one another, so you can choose the appropriate function for each individual access to the CVT.   Create Tags   Before the CVT can be used to store and retrieve data it needs to be initialized to allocate memory in the Memory Block and define the variable properties in the CVT Tag Memory. The initialization of the CVT is defined using a cluster array that contains the attributes of the tags used in an application.   Version 3 of the CVT introduces a new cluster which defines groups of tgas in the CVT. This cluster is incompatible with the cluster used in prior versions of the library, but a conversion VI is provided for backwards compatibility. This cluster can be created as a constant on the diagram or loaded from a file. Version 3 of the CVT also adds the ability to create new tags as needed during runtime, without overwriting existing tags. The initialize VI allows the user to select whether or not they wish to clear the C Figure 5: Initializing the CVT using a constant cluster array   Load From File   Rather than specifying the CVT Tags to Create as a constant or control, it is generally desirable to load the configuration from a file. Once the tags have been added the current tags your system requires, the current values can be saved to disk for documentation or system set up. Using a file allows you to modify the available tags and the properties of tags without having to modify the code of your program.  An XML editor also reduces the effort required to create and configure large tag lists.  The CVT API includes the CVT Load Tag List VI to load the XML tag configuration file.   Figure 6: Loading the CVT TagList from a file Standard API   The standard API contains functions to read and write data items in the CVT using the variable name as an identifier. Using the standard API the variable name can be a static string or can be created at runtime using the LabVIEW string functions. In the API call, the variable name is used to lookup the index of the variable and then the value is accessed using the index.   To improve performance, version 3 of the CVT only performs the lookup on the first call, if the lookup previously failed, or if the tag name input changed from the previous iteration. This API uses polymorphic VIs to switch between data types. For writes, this data type is selected automatically based on the wire type. Reads can be selected by providing a default value or by manually selecting a type. The appearance of the VI will change based on the instance selected.   Figure 7: Example accessing different CVT variables using the basic API   All of the basic API functions, including the initialization VI, are contained in the main CVT function palette which is installed in the User Libraries function palette in LabVIEW.   Figure 8: CVT Basic API Function Palette   Static API   The Static API (Static Write.vi, Static Read.vi) is very similar to the basic API. However it requires that you use a static name (constant string) in your application when accessing a variable. This restriction allows each instance of the Static API to only perform the variable index lookup operation once on the first call to each instance. It then buffers the index for subsequent accesses providing a significant performance advantage when repeatedly reading or writing the same variable in the CVT. The Basic Example shows how to use the Static API.     The Static API functions are available in the Advanced subpalette of the main CVT function palette.   Figure 9: CVT Static API Function Palette   Index API   The Index API is an extension of the Static API and provides even better performance. Using the Index API you use two VIs to access a value in the CVT. The first VI is used to retrieve the index of a variable (Get Index.vi) in the CVT. This step is only performed once for each variable used. Then the index is used to access the variable value (Write Index.vi, Read Index.vi). This provides the thinnest possible API to repeatedly access the same value in the CVT. See the Advanced Example for how to use the Index API.   Figure 10: Example using the CVT Index API   The Index API functions are available in the Advanced subpalette of the main CVT function palette.   Figure 11: CVT Index API Function Palette   For sets of tags which share the same data type, the Advanced API can be used to further boost performance by eliminating the sub-VI overhead of each lookup in memory. Performance will vary, but a rule of thumb is to use set of indices any time you wish to access three or more tags of the same type. Because tag names themselves are untyped, the Advanced API look-up function returns the tag type along with the references in order to provide a type confirmation to the application code.     Group API   Sometimes, it can be beneficial to attach a name to a set of tags of varying data types rather than referencing each tag individually. Version 3 of the CVT adds a group API which allows the user to read or write a set of tags simultaneously. One method for forming a group is to create the group during initialization.   Groups can also be formed at run-time. Once a group has been formed, it can be accessed by the group name rather than the individual tags. Similarly to the Standard API, a look-up will only be performed if the group name changes or if an error occurs. Users cannot modify an already formed group, but groups can be deleted and reformed using this API. Care should be taken to ensure that tags are looked up after a group has been deleted or reformed. Once the lookup has been performed, the group can be read as a whole, in the order specified.   Utilities Functions   In addition to the VIs that access the stored variable values, the CVT also provides utility VIs to access additional properties or attributes of each variable. The current Utilities API provides the ability to retrieve the variable description. The description is a string attribute associated with each variable that may be used to store arbitrary information that relates to the variable.   Read Tag Description.vi provides a tool for retrieving the stored description of a tag.   List Grouped Tags.vi and List Grouped Tags By Type.vi provide a utility for retrieving the members of a group. The first function returns the full list as entered. The second returns a list which is organized by type, with a type descriptor for each set.   Finally, Save CVT to Disk.vi and Save Grouped Tags to Disk.vi provide tools for storing the currently loaded CVT data to disk. Save CVT to disk will initiate a lookup of every tag in the system on first call, and will use that information to perform an extremely efficient index read on the data on subsequent calls. Save Grouped Tags to Disk will perform a lookup in the same fashion as the Basic API. Both functions will then pack the data into an XML file and save it in the location specified.     The Utilities API functions are available in a subpalette of the main CVT function palette.   Figure 12: CVT Utilities API Function Palette   These properties are stored in the TagList core VI for each data type. In order to add additional variable properties to the CVT, a developer must add the new property to the CVT Tags to Create control TypeDef and then add a new case to the TagList core VIs to provide a method to retrieve the new property from the TagList. API functions can be added following the template of Read Tag Description VI.   Examples   Using the CVT is very simple in most applications. The first step is to define the variables that will be used by the rest of the application and shared through the CVT. The variables to be used need to be defined in the tag configuration array, either as a constant on the diagram or using another method.   In the code of your application the CVT needs to be initialized once by passing the tag configuration array to the Create Tags VI. Once the CVT is initialized you can write and read any of the variables in the CVT using the three previously described APIs.   If you try to access a variable not defined in the CVT, the access function returns an error using a standard LabVIEW error cluster.   Figure 13: Example using the CVT functions to share data between two loops   Support   Please submit your feedback in the Current Value Table (CVT) discussion forum so that we can improve this component for future applications.   Older Versions   There has been a number of major versions of the CVT library with incompatibilities between version 2 and 3. Previous version's functions have been deprecated, but version 2 is retained in VIPM for preexisting projects. If you have any issues updating to the newer version specifically from the CVT library, please post to the discussion forum.   Installation   The Current Value Table library is available in the LabVIEW Tools Network (LVTN) repository and can be installed directly from VI Package Manager (VIPM).   vipm://ni_lib_cvt?repo_url=http://ftp.ni.com/evaluation/labview/lvtn/vipm   CVT Model Page on the LVTN   References   Changes in Current Value Table (CVT) Version 3   Discussion   http://forums.ni.com/t5/Components/Current-Value-Table-CVT/m-p/583424   Source Code   https://github.com/NISystemsEngineering/CurrentValueTable   Known Issues   https://github.com/NISystemsEngineering/CurrentValueTable/issues   (This document has been moved from ni.com and was previously located at http://www.ni.com/example/30326/en/ .)
View full article
Note: This is an older example. Consider using the IEEE 1588 Precision Time Protocol for your synchronization needs.   Introduction to Distributed Clock Synchronization and the IEEE 1588 Precision Time Protocol   Overview   This example describes a library that provides better timing accuracy and precision for distributed LabVIEW applications by distributing the timebase process to the networked nodes. The distributed timebase has several potential applications but it is most commonly used to time stamp data and events at the I/O nodes.   Background   When data values and events are are to be monitored or logged they must be time stamped so that they can be correlated in time for display or analysis.  For distributed applications, the traditional method is to transmit the data to a central computer where it is time stamped using the computer’s clock.  This centralized approach works well for applications where the timing uncertainty created by network and processing latencies are acceptable.   For distributed applications that require millisecond-level precision and accuracy, the distributed timebase (DTB) library provides a simple tool for synchronizing the local timebase on each I/O node.   The DTB library also addresses the following requirements for distributed system synchronization: Operation that is relatively insensitive to network delays Behavior that is suited for accurate elapsed-time calculations (no discontinuities, sharp accelerations or reversals of time) Flywheel operation in the absence of a time reference   Implementation   The distributed timebase (DTB) library is implemented as two processes.  The time reference process can run on any network node.  It generates a UDP packet once per second containing the master time value.     The timebase process runs wherever a synchronized local timebase is required (typically on I/O nodes).   The time reference and timebase processes are based on the LabVIEW millisecond tick timer, which is a relatively stable and reliable timing source that is available on most LabVIEW targets.   Programming Interface - Using the DTB   The DTB library includes 5 public VIs. Time Reference Process VIs Time Reference VI – Generates the UDP time packets. Abort Time Reference VI – Terminates the time reference process. Timebase Process VIs Timebase VI – Receives the UDP packets and synchronizes the local timebase. Abort Timebase VI – Terminates the timebase process. Get Time VI – Gets a current timestamp.  This VI is used in the application code.   Examples   The following examples demonstrate how to use the DTB library VIs.   Time Reference Application   The time reference process can run as part of the application on any network node.  There should only be one active time reference process in the system.  The Time Reference VI runs in parallel with other application code.   It can be dropped outside of other programming structures on the diagram of the top level VI.   The Abort Time Reference VI is used in the cleanup phase of the application code to terminate the time reference process.     I/O Node Application   The Timebase VI runs in parallel with other I/O node application code.   It can be dropped outside of other programming structures on the diagram of the top level VI.   The Abort Time Reference VI is used in the cleanup phase of the application code to terminate the Time Reference process.       Limitations   There are a few limitations that you should be aware of when using the DTB library.   The time reference must be running to initialize the I/O node timebases and keep them synchronized.  Once initialized the timebase processes can run for short durations without the time reference (flywheel operation) with minimal timebase error.  In flywheel mode, the relative drift between local timebases will be somewhere in the range of +/-0.2% (about +/- 7 seconds per hour) The time reference and I/O nodes must be on the same subnet.  LabVIEW RT does not support UDP multicast, so the DTB library uses UDP broadcast mode to distribute the time packets. CPU loading at the I/O node can introduce jitter in the local timebase.  To minimize this effect, the Timebase VI is implemented with a timed loop running at priority = 100.  For data acquisition applications this should work well.  For control applications, you may need to make careful tradeoffs between timebase and control loop jitter.   Additional information on features and licensing are available in the ReadMe file.   Feedback   This example was created by the NI Systems Engineering group. You can give us feedback by posting questions and comments below.   References   Choosing a CompactRIO Synchronization Technology Configuring IEEE 1588 Synchronization with the NI PXI-668x Timing and Synchronization Module Configuring GPS Synchronization with the NI PXI-668x Timing and Synchronization Module
View full article
    The attached example contains an implementation of STM in LabWindows/CVI and examples of its use.   Requirements   This code requires the Simple Messaging Library (STM) The LabVIEW example code included in the attached example requires LabVIEW version 8.6 or higher. The C code was written in LabWindows/CVI 9.0.  Much of the code can be converted to other LabWindows/CVI versions with minimal effort.   Description   The zip file contains the following:   CVI Folder   This folder contains the LabWindows/CVI STM implementation as well as an example of its use.  The following files are significant:   CVI\_STM_libraries Folder   STM_Comm.h and STM_Comm.c These files implement the main STM communication.  This is directly used to connect to the server / client, disconnect from the server / client, and send / receive messages.  Additionally, the functions in these files allow you to receive notification of a successful connection, the loss of a connection, the receipt of meta data, the receipt of any data on the STM socket, the receipt of an STM message, a successfully transmitted message and/or a connection error.     STM_Convert.h and STM_Convert.c These files provide a number of functions which help you to encode and decode data into a format acceptable by LabVIEW.  This is called flattening and unflattening.  Note that not all possible data types are implemented. If you need a data type that isn't available, use the provided functions as a guide and the refer to Flattened Data for the data format.   CVI\Server and CVI\Client Folder   STM Server Example.h, STM Server Example.c, and STM Server Example.uir These files implement an example of using the LabWindows / CVI STM libraries to run an STM server and accept connections from an STM client.   STM Client Example.h, STM Client Example.c, and STM for CVI client.uir These files implement an example of using the LabWindows/CVI STM libraries to create an STM client that connects to an STM server.   LabVIEW Folder This folder contains LabVIEW VIs that implement the same functionality as the CVI Client and Server examples. This code requires the Simple Messaging Reference Library (STM) to open.  This example is a good test for the LabWindows/CVI implementation as it uses multiple data types and arrays in its STM messages.   Feedback   Please submit your feedback and questions on this example in the STM discussion forum. General product support questions should be directed to NI Technical Support.
View full article
  The attached file contains a client implementation of STM in Microsoft Visual Studio 2010 and an example of its use. This example does not implement a server for STM connections, although much of the code can be re-used for a server implementation.   Requirements   Simple Messaging (STM) Communication Library The LabVIEW server code included in the attached example requires LabVIEW version 8.6 or higher. The Visual C++ code was written in Microsoft Visual Studio 2010.  Much of the code can be converted to other MS VC++ versions with minimal effort.   Example Description   The attached example contains the following:   VC++ STM Client Folder This folder contains the VC++ STM implementation as well as an example of its use.     The following files are significant: STMSession.h and STMSession.cpp These files implement the STMSession Class, which implements the main STM communication.  This class is directly used to connect to the server, disconnect from the server, and send messages.  The class also provides messages via a STMDispatch object.   STMDispatch.h and STMDispatch.cpp These files implement the STMDispatch Class, which provides notifications to the application when STM communication events occur.  To define handlers for these messages, inherit from this class and overload the associated functions.  This class allows you to receive notification of a successful connection, the loss of a connection, the receipt of meta data, the receipt of any data on the STM socket, the receipt of an STM message, a successfully transmitted message and/or a connection error.  To register for notifications, you should call the STMSession:: SetDispatch function and pass an object of a class that inherits from STMDispatch.   STMConvert.h and STMConvert.cpp These files provide a number of functions which help you to encode and decode data into a format acceptable by LabVIEW.  This is called flattening and unflattening.  Note that not all possible data types are implemented. If you need a data type that isn't available, use the provided functions as a guide and the refer to Flattened Data for the data format.   STMExample.h, STMExample.cpp, STMExampleDlg.h, and STMExampleDlg.cpp These files implement an example of using STMSession and STMDispatch to communicate with an STM server.   LV Server Folder This folder contains a LabVIEW server designed to communicate with the C++ example client.  The example is a CompactRIO system that acts as a server for multiple STM clients.  The cRIO streams analog waveforms from a cRIO module, scans digital inputs, updates digital outputs, and transfers a cluster of system status information.  This example is a good test for the C++ implementation as it uses multiple data types, arrays, and clusters in its STM messages.   Feedback   Please submit your feedback and questions on this example in the STM discussion forum. General product support questions should be directed to NI Technical Support.
View full article
The System Management and Information (SMI) Library is recommended for new designs using LabVIEW 2013 or later. SMI retains all of the features of CRI, however palette member VIs are not "drop-in" replaceable. The CRI Library has been deprecated, and no future versions are planned for release.   The development of advanced and dynamic CompactRIO (cRIO) applications sometimes requires the ability to detect the current configuration of a CompactRIO system. The CompactRIO Information (CRI) library provides functions to retrieve information about a local or remote cRIO controller, backplane, and modules, including the type and serial number of each of these system components. It can be used with CompactRIO, Single-Board RIO (sbRIO), myRIO, MXI-Express RIO, and EthernetRIO, for reporting the configuration information of RIO hardware controller, chassis, and modules for local or remote targets.   Functionality   The CRI library provided with this tutorial allows you to programmatically retrieve information about the components of a CompactRIO (cRIO) system. It provides access to the following information:   Controller Model Name Model Code Serial Number MAC Address Host Name IP Address   Backplane Model Name Model Code Serial Number   Modules Module ID Vendor Name Model Name Serial Number   The CRI library includes two sets of VIs, one set to run directly on a cRIO controller targeted with LabVIEW Real-Time, the other set to run remotely to retrieve the configuration of any cRIO system on the network.   Using the CRI Library   The CRI installer will add the CRI function palette to the User Library function palette. All of the CRI VIs are located in the main palette.   Figure 1: cRIO Information (CRI) function palette     The CRI library includes a high-level function (Get cRIO System Info) to retrieve the complete system configuration of a CompactRIO chassis. This VI returns information about the controller, backplane and modules.   Note:   In order to retrieve information about the modules located in the cRIO backplane the function must load a custom bitstream onto the FPGA. This bitstream will replace any existing bitstream or LabVIEW FPGA VI running on the FPGA. Use this function carefully if the cRIO system and FPGA may be monitoring or controlling any external hardware.   Figure 2: CRI Get cRIO System Info.vi   The remote version of this VI allows you to retrieve the information from a cRIO system on the network by specifying the system IP address or network name. In order for this function to work properly the remote cRIO system must be configured with a compatible version of LabVIEW, NI-RIO, NI-VISA and the NI-VISA server.   Figure 3: CRI Get Remote cRIO System Info.vi   Controller and Backplane Information The high-level function CRI contains three individual VIs to retrieve information about the controller, backplane and modules. Using these VIs individually you can customize these operations in your application as necessary.     The controller and backplane information are read directly from drivers and registers in the controller and backplane. The VI is run while targeted to the cRIO controller.   Figure 4: Retrieving the controller and backplane information   Modules The VIs included in the CRI library for retrieving information about the individual modules in a chassis deploy a custom bitstream to the FPGA in order to retrieve information from EEPROM memory on each individual C series module. This custom bitstream aborts and replaces any other bitstream or LabVIEW FPGA VI currently running on the FPGA. Therefore you must use this function carefully to avoid causing any problems with devices and actuators connected to the physical I/O of the system.     To retrieve the current module configuration you must specify the type of cRIO backplane used in the system so that the correct bitstream is downloaded to the FPGA.     To retrieve information about the modules in a remote cRIO system, specify the system IP address or network name.   Figure 5: CRI Get Remote cRIO Modules Info.vi     The list of supported backplanes of each version of the CRI library is provided in the VI package description.   The CRI library includes a separate FPGA bitstream for each of these targets. If the Get cRIO Modules Info VI is targeted to the LabVIEW Real-Time controller of a cRIO system, all bitstreams referenced in the VI are downloaded to the program memory of the cRIO system even though the current system only contains one possible cRIO backplane. This can use up a significant portion of the cRIO program memory (RAM). In order to optimize your application and reduce memory usage, the CRIO library includes individual VIs for each of the cRIO backplanes which only include the bitstream for one of the cRIO backplanes/FPGA targets. You can use these if you know during development which of the cRIO backplanes will be employed in the deployed application.   Note: If a C series module is removed from a running system, the first time the module configuration is read using the CRI library, the vendor and model ID returned from the now empty slot may not be 0. It may be returned as a non-0 value and the module name will be <Undefined>. On the next operation it will return a vendor and model ID of 0.   Implementation   This section provides some additional information about the implementation of the CRI functions, which may be useful in customizing these VIs or implementing similar operations in your application.   Controller and Backplane   The VIs provided to retrieve controller and backplane information use standard LabVIEW Real-Time and NI-RIO functions  to retrieve the information.    The CRI Get cRIO Controller Info VI uses a modified version of the RT Ping Controllers VI to retrieve the information. This function may also be used to retrieve information from a PXI or Compact FieldPoint LabVIEW Real-Time controller.   The CRI Get cRIO Backplane Info VI uses functions from the NI-RIO driver to retrieve information about the backplane. The model code of the backplane is converted to an enumerated value representing the  backplane model name. The conversion is performed in the cri_Parse Backplane ID subVI using a lookup table containing  the list of backplanes and their model codes.   Figure 6: Block diagram of CRI Get cRIO Backplane Info.vi   The lookup table containing the list of available backplanes is stored in and provided by cri_cRIO Vendor and Components Library.vi. This VI contains a list of all current cRIO devices and vendors and their IDs and is used in a number of CRI VIs. The list of devices is stored in the default value of a series of front panel indicators. Any new cRIO devices may be added to these lists.   Figure 7: cri_cRIO Vendor and Components Library.vi: Lookup tables of cRIO components and vendors   Modules   The information about each individual module is stored in an EEPROM located on the module and includes the module and vendor ID and the module serial number. This information can be read in any LabVIEW FPGA VI using the I/O property node.   Figure 8: LabVIEW FPGA diagram and indicator used to retrieve information from four C series (cRIO) modules     The CRI library uses a simple LabVIEW FPGA VI to retrieve this information from all slots in the backplane. A unique FPGA VI is used for each backplane type. These FPGA VIs are compiled and the resulting bitstream (*.lvbit) is provided with the CRI libraryVIs.   The source code and project for these FPGA VIs is not included in the installed CRI library, as it is not required to retrieve the module information. Only the compiled bitstreams are required. The source code and project is provided in a separate download ZIP file if desired.   The project used to generate the FPGA bitstreams includes a separate FPGA target for each of the cRIO backplanes. For each target, a cRIO module is configured for each slot in the backplane to read the module information from the EEPROM of each module. The project uses a NI 9203 for each slot in the configuration, but the software allows you to retrieve the module information from any module regardless of the module type. This technique is used to retrieve the module information from all slots in the backplane regardless of the type of module in each slot. Figure 9: LabVIEW project used to generate the FPGA bitstreams for retrieving module information   After the module information is retrieved for each module, it is returned to the host VI running either on the cRIO controller or on a networked target. In the host VI (e.g. CRI Get cRIO-9101 Modules Info.vi) the module ID is converted to the vendor name and module name using the lookup tables contained in cri_cRIO Vendor and Components Library.vi.   Figure 10: CRI Get cRIO-9101 Modules Info.vi: Retrieving and converting module information on the host     Applications   The CRI library can be used to add advanced functionality to many different types of cRIO-based application. Here are a few examples of how the CRI library may be used.   Logging of System Configuration   In many applications where data is recorded or logged it is necessary to also record information about the recording system being used in order to meet certain standards requirements. Using the CRI librarycyou can retrieve information about all of the cRIO components used in the system including their serial numbers and can record this information in a file or database along with the data being recorded. When components are replaced in a system it is easy to track these changes. A more advanced system may record the calibration intervals for each module in a database and notify the user if individual modules will require re-calibration in the near future.    Dynamic FPGA Code Selection   Due to the nature of FPGAs, a LabVIEW VI performing I/O operations is developed and compiled for a specific configuration of module types in the backplane. A bitstream generated from a LabVIEW FPGA VI for one configuration of  modules cannot be used with a different configuration of I/O modules. For example if you have configured a NI 9215 analog input module during the compile process, you can not run the bitstream using a NI 9201 analog input module instead. However, you can configure and compile multiple FPGA VIs, one for each possible module configuration, and then select the proper FPGA VI or bitstream at run-time to match the current configuration of modules.    Using the CRI component you can detect the current configuration of modules in the backplane and can then select the proper FPGA bitstream to download and run. This detection and selection of the FPGA bitstream will be part of LabVIEW Real-Time application running on the cRIO controller.   Application Licensing   In some cases you may want to apply a license to an application and link it to a specific set of hardware. This would prevent a user to move the application/code from one cRIO system to another system containing the same hardware. Using the CRI library you can uniquely identify each system component using its serial number, as well as the MAC address of the controller, and can build a licensing solution that links the application to the specific set of hardware.   The process of creating a license key and linking the application to the hardware is not handled by the CRI library and must be implemented separately.   Download and Installation   The current version of CRI (v2015.0.0.1) is available through the LabVIEW Tools Network using VI Package Manager (VIPM). It includes support for MXI-Express RIO and EthernetRIO expansion chassis, in addition to existing support for myRIO and select sbRIO targets. VIPM also contains older versions of CRI, compatible with previous versions of LabVIEW. You can install them using the Install Other Version.... option in VIPM, although they may not include support for all of the latest controllers and backplanes.   Support and Feedback   Please post questions, comments and suggestions for the CRI library in the CRI discussion forum.
View full article
The Asynchronous Message Communication (AMC) Library is a general purpose LabVIEW API for sending messages within a process, between processes, and between different LabVIEW targets (systems on a network) in a LabVIEW application.   The Queued Message Handler (QMH) design pattern is a general purpose VI architecture that can be used as the basis for a wide range of LabVIEW VIs. It uses the AMC API to send and receive messages. This design pattern can be used to implement state machines, user interfaces for applications, asynchronous communication processors, as well as other tasks and system components within a larger application.   This design pattern is similar to other VI architecture implementations often called queued state machines. As the design pattern can be used for many purposes other than a traditional state machine and state-oriented tasks, the name for this design pattern has been chosen to be representative of the implementation of the design pattern.   Overview   The purpose of the Asynchronous Message Communication (AMC) library is to provide an easy-to-use extensible messaging architecture for a variety of local and distributed LabVIEW applications. It allows you to send messages within one process of an application, between different processes on one LabVIEW target or between processes on different LabVIEW targets connected over an Ethernet network.   LabVIEW application processes in the context of this discussion are the individual ongoing operations you define as part of your application. They are typically implemented using either a While loop or Timed loop, but in some cases may also consist of a For loop or other finite program structure.  Processes may include a user interface VI of your application, an I/O engine, a communication engine, a data logging engine, or a state-machine driven control process.  The AMC library is used to send different messages between these processes. A message may be a command for another process to start a specific operation, perform a specific action, may be a status update, may be notification of a fault or error in particular part of the application, etc. The API is designed to be used for asynchronous messages which occur at undefined intervals and typically not very frequently. Messages or data which need to be sent frequently and at regular intervals between specific processes (e.g. data streaming) may be implemented with better run-time performance using other techniques such as raw LabVIEW queues for local processes or TCP-based communication for distributed processes. The Simple TCP Messaging (STM) reference library is good example of a TCP-based communication architecture designed for throughput performance.   Messages   A message is a piece of information contained in a LabVIEW cluster and defined by a Type Definition (TypeDef) in the AMC library. The TypeDef can be customized for the needs of your application by adding additional elements or changing the existing elements. The message definition included in the AMC library contains a message name (string), value (string), Attributes (keyed string array) and some additional parameters such as Receiver Host, Receiver Process, etc. These additional parameters are used by the AMC infrastructure and should not be changed or removed unless you clearly understand how they are being used in the different functions of the library.   Figure 1: Components of a message   Some developers may prefer to use a Variant instead of a string for the message value or to use Variant attributes to store additional attributes instead of a keyed array. If you do modify the message TypeDef you will also need to adapt a few of the functions in the library such as the conversion to and from XML to match the message type. Sending Messages Locally The simplest use of the AMC library is to send a message from one part of a process to another. A common such application is the use of the AMC VIs in the queued message handler (QMH) design pattern which is described later on this article. In the QMH design pattern an event handler such as the UI event structure captures events from a source (the UI in this example) and passes them as messages to another part of the process (the message processor) to be taken care of. Other applications of the AMC in a single process are any type of producer/consumer design pattern.   Internally the AMC library VIs use a LabVIEW queue to buffer messages between the sender and receiver.   Figure 2: Sending messages within a LabVIEW process   A slightly more advanced use case of the AMC VIs is to send a message from one process to another. on the same LabVIEW target. Messages are still sent through a LabVIEW queue as the same queue can be referenced in both processes. In this case each receiver process will instantiate a named message queue and any other process can send a message to the receiver process using the message queue name. Each sender queue references the receiver process and queue using the queue name provided by the receiver process.   Figure 3: Sending message between LabVIEW processes on one target   For bidirectional message communication between two or more processes each receiver process will create its own receiver queue and any other processes can send their message to one common queue for each receiver. This means that each process only needs one message queue instead of establishing a separate connection between each pair of communicating processes. Sending Messages Across the Network When passing messages across the network from one LabVIEW target to another, messages must be passed along using a network transport protocol. The protocol used by the AMC library is UDP as it does not require an established connection between each pair of communicating targets. This allows the AMC library to easily pass messages between any number of targets on a network in a distributed LabVIEW application.    To handle messages sent using UDP at the receiver, each target which will be accepting incoming messages must run the AMC Dispatcher process. This process maintains an open UDP port and listens for incoming messages from any other targets on the network. When a message is received in the dispatcher it is forwarded to the message queue of the local receiver process. The name of the receiver process is included in the parameters of the message itself.   Using this design a process on one target can send a message to any named process on another target in the application. The sender only needs to know the target name (IP address) and the name of the receiver process on the remote target.   Figure 4: Sending messages to a process on a remote (networked) target   The AMC Dispatcher provides a number of additional service functions described later on which can be used in an application to verify existence of individual remote targets and processes as well as to enumerate all the processes available on a remote target.   Asynchronous Message Communication (AMC) API   The AMC API is organized into a number of different groups of VIs. These groups contain VIs for   Sending and receiving messages and managing local message queues Managing the local and remote AMC Dispatcher Registering and unregistering local message queues   The AMC function palette contains the most commonly used VIs on the main palette and has a number of subpalettes for the remaining groups of VIs. Additional subpalettes contain a number of templates from common design patterns using the AMC VIs.   Figure 5: AMC Function Palette   Managing Message Queues There are four basic VIs included in the AMC API to manage message queues.   Create Message Queue   Each process which will be receiving messages uses the Create Message Queue VI to create a new message queue with a unique name. The name is provided by the process itself. When creating a new message queue you can also place some initial messages in the queue which will be read by the process. This is commonly used in the QMH design pattern to perform some initialization actions in the local process.     Destroy Message Queue   When a process is shutdown any message queue created by the process must be terminated using the Destroy Message Queue VI.   Check Message Queue Status   A process can check the status of its local queue and the number of messages located in the queue using the Check Message Queue Status VI.   Flush Message Queue   If desired a process can empty the local message queue and remove all waiting messages without processing them using the Flush Message Queue VI. Sending and Receiving Messages Messages can be sent using a number of different VIs in the AMC API.   Send Local Message Send Local Messages   Messages can be sent to a process on the local target using the Send Local Message or Send Local Messages VI. If the Process input is blank the message will be sent to the message queue referenced by the Message Queue in parameter, otherwise the message is sent to the local message queue specified by the process name. The Priority Message input allows you to place messages on the front of the message queue instead of the back. Messages placed on the front of the queue will be the first ones dequeued in the receiving process.   Send Network Message   Messages are sent to a process on a remote target using the Send Network Message VI. This VI sends the message using UDP directly to the remote target specified in the Receiver Host input where the AMC Dispatcher will forward the message to the local message queue specified in the Receiver Process input.   Send Message   TheSend Message VI is a low level generic VI that can be used to send messages to a local or remote process.   Read Next Message   The Read Next Message VI is used to retrieve the next message from the message queue to be handled in the local process. The message queue is passed in by queue reference as it will be created in the same process.   The Termination List input is used as part of the QMH design pattern or other similar message processors. Any message being dequeued which matches any of the names in the Termination List will cause the Exit Process output of the VI to be set to True. This can be used to automatically terminate the processor loop. The default termination message is 'Exit'.   Using these Message Send and Read VIs you can quickly and easily send flexible messages to any process in your application. Remember that to send messages to a remote target, the receiver target must have the AMC Dispatcher running as described in the next section.   Network Communication and the AMC Dispatcher To enable receiving messages using AMC across an Ethernet network the AMC Dispatcher must be running on the receiving LabVIEW target system. The AMC Dispatcher is a standalone VI and process which open and monitors a UDP port for incoming messages and forwards them to different message queues on the local target based on the Receiver Process parameter in each message.   Figure 6: AMC Dispatcher Palette   On most LabVIEW targets (Windows XP, Windows XP embedded, Windows Vista and LabVIEW Real-Time) you can use the Dispatch Start VI and Dispatch Stop VI to dynamically start and stop the AMC Dispatcher. On a LabVIEW Windows CE target you must call the AMC Dispatcher statically by placing it in your main VI in parallel to the rest of your application. When called statically the AMC Dispatcher is a regular subVI and will not return until terminated it by send an Exit message to the AMC Dispatcher itself.   The AMC Dispatcher function palette provides additional service functions which can be used to further automate your application or verify remote targets. These VIs send different requests to AMC Dispatchers running on remote targets. All of these functions require that the AMC Dispatcher is also running on the local target which is sending out these requests as the remote Dispatchers will send back responses which are received by a local AMC Dispatcher.   The Dispatch Ping VI is used to send out a ping to a specific network target and AMC Dispatcher in order to verify that the AMC Dispatcher is running and able to receive messages on the specified remote target.   The Dispatch PingAll VI is used to send out a ping to all network targets on the local subnet which will prompt all AMC Dispatchers on the local subnet to respond. This function is used to establish a list of targets on the local subnet which can receive AMC messages.   The Dispatch Verify Queue VI is used to send out a query to a specific target and verify the presence of a specific named message queue and associated process. This VI is used to establish if a particular process is running and able to receive messages.   The Dispatch Get All Queues VI is used to request a list of all messages queues available on a specified remote target.  AMC Queue Registry The AMC Queue Registry is a LabVIEW Functional Global Variable and associated interface VIs which is used to keep track of the list of message queues used within one target.   Figure 7: AMC Queue Registry Palette   The Create Message Queue and AMC Destroy Message Queue VIs use these VIs to update the list of message queues. The registry is also used by the AMC Dispatcher to respond to a Get All Queues query from another target.   Queued Message Handler Design Pattern   The Queued Message Handler (QMH) design pattern is a VI template which is included with the AMC reference library. It is available on the AMC function palette and can be dropped directly onto the diagram of a blank VI.  THE QMH is a basic producer-consumer architecture which can be used as the basis for a wide variety of LabVIEW VIs throughout an application. Common uses of the QMH design pattern are the user interface of an application, dialog windows, command and communication parsers, state-based controllers and more.   The purpose of the QMH design pattern is to receive, store, and then process messages. Messages can be events from a user interface, commands received from a communication interface and others. In general a message is an asynchronous event which requires some action, operation, service, or other response.   The QMH is implemented using the Asynchronous Messaging Communication (AMC) library, which stores messages from one or more message generators or sources. Messages are read from the AMC message queue by the message processor. The message processor consists of multiple cases or states, each dedicated to process a specific message coming from the queue.   Figure 8: Queued Message Handler Design Pattern   The message queue can be accessed from multiple message generators who all place messages on the queue for processing by the message handler. However, it is common that only a single message generator exists in a particular implementation such as a user interface VI.   In addition to dedicated message generators, processing routines within the message handler may also place new messages on the message queue while processing other messages. For example, an error in processing one message may cause the message handler to place an error message on the queue to be subsequently processed by another routine in the message handler.   During normal operations of the QMH, messages are typically placed at the end of the queue and processed from the front of the queue in a First-In First-Out (FIFO) fashion.    Figure 9: QMH normal operation placing new messages at the end of the queue   In some cases it is desirable that a new message on the queue will be processed as soon as possible. In this case the message may be put at the front of the queue using the Priority Message flag in the AMC library and will be processed the next time the message processor retrieves a message from the queue.   Figure 10: QMH priority operation placing a new error message at the front of the queue   The Queued Message Handler (QMH) design pattern is built around the AMC library and LabVIEW queues in order to store messages and uses a While Loop/Case Structure-based message processor. To simplify the use of the QMH design pattern in new VI's and applications, the AMC library includes a set of templates and examples, which can be used as a starting point for new VIs and applications. After installation of the AMC reference library the QMH templates are available in the AMC subpalette of the User Libraries function palette. Messages Definition When developing a queued message handler, there are a number of possible ways to define the message stored in the queue. Common implementations include strings, variants and enumerations. Each of these choices offers different advantages and disadvantages.   The AMC reference library uses a string as the basic data type for messages, as it provides the ability to easily pass any message to the queue without the need to define a set of permissible messages in the VI or application. This simplifies the process of adding new messages to the application and simplifies using the reference library in a wide range of applications. However, using a string as the message name datatype does make it more likely to create a typo in the message name or to add messages to the queue which are not handled in the message processor. Care must be taken when specifying messages and a special error case in the message handler should be used to detect and report any unhandled messages.   Instead of a string, an enumeration can be used to define a specific set of messages allow by the application. Creating a TypeDef enumeration does make it easier to change the set of allowed messages in an application, while preventing any typos in selecting a message during programming. However, when using an enumeration, the set of allowed messages needs to be adapted for each use of the AMC library and therefore one set of VIs for manage the message queues and messages can not be used for multiple applications of the QMH design pattern.  Creating the Message Queue and Adding Messages Before adding messages to the queue it must be created using the Create Message Queue VI. As part of creating the queue you can place a number of initial messages on the queue. These messages will be the first messages handled in the message processor. Typically these messages are used for the startup or initialization of the VI.   After creating the queue, messages can be added to the queue using the AMC Send Local Message VI.   In the following diagram  the queue is created and three initial messages are added to the queue. In the user interface event handler the Write Config File message is added to the queue when the operator presses the Save State button on the UI. The message processor is not shown in this diagram.   Figure 11: Message Queue Initialization and UI Event   You can also add multiple messages to the queue in a single operation using the Send Local Messages VI.  Multiple messages are passed as a string array to the VI.   Figure 12: Example of adding multiple messages to the message queue   In addition to the messages stored on the queue in some cases it is useful to be able to pass additional data such as values or attributes along with the messages. This additional data is used in the message processor to customize the processing of the message. Message values are passed as a string or string array to Send Local Message(s). The previous diagram includes the new value of the Clock Style control as a parameter with the Set Clock Style message. Processing Messages From the queue, messages are read in the message processor loop and then handled by a separate case for each of the messages used in a message handler. The basic message processor includes the Read Next Message VI and a case structure with individual cases for each message.   Figure 13: Message processor loop showing one message case 'Set Clock Style'   Reading Messages from the Queue   The Read Next Message VI includes a few specific features that should be observed in the message processor. The default operation of this VI is to return the next message from the queue and the associated value string and attributes keyed array. The message name is used as the case structure selector for the message processor and the value and attributes may be used in the specific message processor case. Timeout   The timeout value on AMC Read Next Message determines when the VI returns if no message is available on the queue. In this case an empty message string is returned from the VI which should be handled in an appropriate case. The message handler template included in the QMH design template contains a message processor case labelled "", "Wait" which is called if there is a timeout on the AMC Read Next Message VI. This message processor case can be used to handle background tasks necessary in the VI operation such as front panel updates, etc. This case can also be called by placing a Wait message on the queue.   QMH Termination   Terminating the QMH must be handled so that both the message processor and all message generators such as the user interface event loop are shutdown properly. In some cases the message generating loop may continue to run if it also handles other operations in the VI. However, it should not add any more messages to the queue after the message processor has been shut down.   Typically the QMH will be terminated in response to a user action from the front panel such as a Quit button or a message received from another part of the application. In the message generator a message is added to the queue to indicate to the message processor to shutdown. In addition the message generator loop can be shutdown by passing a True to the While loop conditional Stop terminal.   When the message to shutdown the QMH is received in the message processor, it should execute any necessary operations in the corresponding message case before terminating the message processor loop. The Read Next Message VI is designed to recognize one or more messages for termination of the QMH and will return a True value on the Exit Process output which can be used to terminate the message processor loop. The default message to shutdown the local process is Exit, but it can be changed by passing the desired shutdown message name(s) to the Read Next Message VI. Default Message Processor   Due to the use of strings as the message name datatype it is possible to make errors or typos when adding messages to the message queue. Any such erroneous messages will not have a corresponding message case in the message processor. Therefore the Case structure default case of the message processor should be used to catch any undefined messages from the queue. Normally any messages passed to this case are the result of a programming error and should be reported as such. Once a VI or application has been completely tested no erroneous message should trigger this message case.   Figure 14: QMH Default Message Case   QMH Template   The Asynchronous Message Communication reference library includes a template of the QMH design pattern. The QMH template can be placed on the diagram of an empty VI from the AMC Templates function palette. Due to some slight differences in the LabVIEW execution engine for Windows CE there is a separate QMH template for Windows CE-based touch panel targets.   The following figure shows the diagram of the QMH design pattern template.   Figure 14: Queued message handler template available in the QMH function palette   The QMH template is targeted at a UI-based VI which processes UI events in the message handler. The UI events handled by the VI can be customized in the message generator loop on the left. Message processor cases can be added to the loop on the right.   The template can be adapted to other types of applications and VIs by modifying the message generator loop. If necessary the message processor may also be adapted. The template should be used as a reference design and customized according to the needs of the individual application.   Examples The Asynchronous Message Communication reference library includes several examples showing the use of the AMC library and QMH design pattern. These example are installed along with the reference library VIs in the <LabVIEW>\examples\AMC\ folder.   References   The Asynchronous Message Communication (AMC) reference library and Queued Message Handler (QMH) design pattern presented in this article is only one possible implementation of the general concept of a queued message handler or queued state machine. The following links provide references and discussions on similar and related design patterns from a variety of sources.   Developer Zone: Application Design Patterns: State Machines JKI Software: State Machine Delacor Queued Message Handler (DQMH)   Source Code   Development of the Asynchronous Messaging Library has been moved to Github, and you are invited to contribute to this library by participating in discussion and code submissions on Github.   Source: https://github.com/NISystemsEngineering/AsynchronousMessageCommunication Issues: https://github.com/NISystemsEngineering/AsynchronousMessageCommunication/issues   Installation   The latest version of the Asynchronous Message Communication (AMC) library can be downloaded and installed with VI Package Manager™ (VIPM).    VI Package Manager is an installer for LabVIEW VIs and toolkits. It places VIs directly into the palettes, allows you to install VIs into multiple LabVIEW versions, and ensures that any dependency VIs and toolkits (provided in other VI packages) are also installed. VI Package Manager is a product and trademark of JKI Software. Previous Versions The latest version of the AMC library, 3.3, is not code compatible with earlier versions of AMC.  The previous version, 2.1.4 (ni_lib_amc-2.1.4-5.ogp) is provided below for compatibility with applications written previously. The package can be installed with VI Package Manager.   The earliest version of the AMC reference library, called the Queued Message Handler Design Pattern and Reference Design Library version 1.0.7 (qmh_107.zip) is provided for applications or VIs based on these tools. The ZIP file includes the Windows installer, VI Package, and a PDF containing the previous version of this document.   Support   You can give us feedback or ask questions by posting to the AMC reference library discussion thread.   General LabVIEW support questions should be addressed to product support or the appropriate discssion forums.
View full article
The Structured Error Handler (SEH) library provides tools for handling specific error codes in an organized fashion.  The SEH consists of a configurable Express VI that helps you handle specific errors and subVIs that categorize errors for use by a central error handler.   Download and Release Notes: https://www.vipm.io/package/ni_lib_seh/  
View full article
Please note that this project is no longer being actively supported and does not support some of the newer connection methods.   The LabSSH and LabSFTP libraries provide interactive SSH communication and SFTP file transfer from a LabVIEW application to a remote machine.   The libraries are shared by Labvolution, a UK Alliance Partner.       Requirements LabVIEW 2015 References For videos on how to use the libraries, see the following links:   LabSSH - http://www.labvolution.com/ssh-with-labview/ LabSFTP - http://www.labvolution.com/sftp-file-transfer-labview/   Support Please post questions or comments here or get in touch with me directly.   Downloads The source code is attached to this document.  
View full article
A circular buffer is a data structure of a fixed size that operates as if its ends were connected together to form a ring.  The circular buffer is a useful way to buffer data between two operations such as data acquisition and analysis.  It allows you to decouple and parallelize different operations which would normally be used in a sequential manner.  It is also useful in applications where operations using the same data set are happening at different intervals.
View full article