Blog

How to Communicate with a VeriStand Custom Device Using LabVIEW

How to Communicate with a VeriStand Custom Device Using LabVIEW

Table of Contents:

  1. Why Should We Configure Custom Device Messaging?
  2. How to Send Messages between a Custom Device and LabVIEW
    1. Step 1: Pass Engine Event Ref into Custom Device Engine
    2. Step 2: Create Event Structures in Asynchronous Loop to Receive Messages
    3. Step 3: Create LabVIEW Code Module to Send Message

Why Should We Configure Custom Device Messaging?

Back to Table of Contents

Creating Custom Devices in VeriStand is a powerful tool that allows developers to package and deploy code for a device simply by adding the Custom Device to a system definition file.

There are two primary methods for transferring data to and from a custom device: channels and messages. Channels are typically used to read or write data in a control loop, and they can be interacted with by a user through a VeriStand screen once deployed. On the other hand, Messages generate events to configure and command custom device actions or properties.

Messages to Custom Devices are sent through LabVIEW code modules. There are many advantages to communicating with a Custom Device using messages from LabVIEW:

  • Messaging data allows for more flexibility in the types of data sent to a Custom Device engine
    • VeriStand channels only support DBL numeric data, while messaging supports other data types
    • The number of channels is fixed by the system definition file, so data structures, like arrays, need to have a fixed size
  • Because most Custom Devices are deployed through VeriStand onto RT systems, the ability to send messages between the Custom Device and LabVIEW allows for communication with a PC-based LabVIEW application
  • LabVIEW code modules for Custom Device messaging can be used in TestStand steps to develop large sequencing and test applications with a Custom Device
     

How to Send Messages between a Custom Device and LabVIEW

Back to Table of Contents

Step 1: Pass Engine Event Ref into Custom Device Engine

Back to Table of Contents

When messages are sent between LabVIEW and a VeriStand Custom Device, the Custom Device engine treats the message as a user event. Before handling this user event in the async loop(s) of the Custom Device, all asynchronous loops should be passed the reference to the Custom Device engine events. This reference contains the events associated with Custom Device messaging in the engine and can be obtained with NI VeriStand - Register Custom Device Events.vi. Below is an example implementation of RT Driver.vi with the engine event reference being passed as an initialization parameter into the code that starts the asynchronous Custom Device process.

Example implementation of RT Driver.vi with the engine event reference being passed as an initialization parameter into the code that starts the asynchronous Custom Device process 

Step 2: Create Event Structures in Asynchronous Loop to Receive Messages

Back to Table of Contents

Now that the Custom Device engine events reference is accessible from the asynchronous loops, event structures may be created to handle message events. There are two messaging events within the engine event reference: Message (String) and Message (Byte Array). Both events contain a Command, Data, and a Response Event. The difference between the two user events is the format of Data.

  • Command: the name or type of message being sent
  • Data: the data associated with the command
  • Response Event: an event reference to send back data to LabVIEW; consider using this to send back data processed by the Custom Device or a confirmation that the message was received

As shown below in the example code, a case structure may be implemented to handle each type of incoming message to the Custom Device. Each case contains logic to handle the message Data as well as generate a response and error message (if applicable). The response and error are bundled as a message response and sent back to LabVIEW through the Response Event.

Example code, a case structure may be implemented to handle each type of incoming message to the Custom Device

One limitation of messaging between VeriStand Custom Devices and LabVIEW is that messages can only be formatted as strings or byte arrays; however, messages of any type may be flattened to a text string and converted into a byte array. Below is an example of how message Data could be handled within a case to receive data of a type associated with the message Command and send any type of response data back to LabVIEW as a byte array. In LabVIEW, message Data and responses can be converted to or from a byte array in a similar manner.

An example of how message Data could be handled within a case to receive data of a type associated with the message Command and send any type of response data back to LabVIEW as a byte array

Step 3: Create LabVIEW Code Module to Send Message

Back to Table of Contents

After setting up event structures to handle messages sent to the Custom Device, the final step is to send messages and receive responses in LabVIEW. This is made simple by the Custom Device Communication Palette.

  • First, use NI VeriStand - Open Custom Device Reference to open a reference to the Custom Device specified by Custom Device Path (also known as Node Path) and Gateway IP Address that can be used to send messages
  • Next, call NI VeriStand - Send Custom Device Message to send the formatted message’s Command and Data, ensuring that the Data sent is of the type expected by the engine
  • When a response from the Custom Device is received, call NI VeriStand - Close Custom Device Reference to close the messaging reference.

.Create LabVIEW Code Module to Send Message

Scripting VIs based on a VeriStand system definition file can programmatically obtain references to Custom Devices and return properties such as the Node Path which is used in the VeriStand messaging VIs to open a messaging reference to a Custom Device. Stay tuned for more VeriStand tutorials and blog posts — including how to create a system definition scripting library!

Learn more about our LabVIEW Programming, and contact us today for your next project!

Comments

There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above:

Related Blog Posts