RT Communication using the Workers TCP Libraries

Purpose :

To demonstrate how you can use the Workers TCP Server and Client libraries to stream data between a host PC and an NI real-time (e.g. CompactRIO) system.

Introduction

The ability to develop and run Workers applications on NI real-time targets was introduced in Workers 4.0. Several changes were made to the framework to make this possible. This also included the introduction of the Debug Server application which assists developers debugging Workers applications running over a local network. TCP Server and Client Worker libraries were also added to the Worker User Library tool, enabling data streaming between Workers applications running anywhere on a local network.

When developing Workers applications on NI real-time targets such as a CompactRIO, you may want to stream data back to a host PC or stream data from the host PC to the CompactRIO (cRIO). While LabVIEW provides ways to communicate between a host PC and a cRIO, such as with Network Shared Variables, these are not recommended for streaming data between the host PC and cRIO.

The TCP Server and TCP Client libraries supplied with the Worker User Library tool can be used to stream data between any two Workers applications on your local network. In this example, a TCP Server runs on a host PC and a TCP Client runs on a cRIO. After establishing a connection, string data is streamed between the host PC and the cRIO. The Workers applications' call-chains are represented in the figure below:

Figure 1 - Workers architecture used in the real-time TCP Server/Client example

Method

The Worker User Library (accessible from the Workers tools menu) contains the Workers TCP Server library and the Workers TCP Client library, as shown in Figure 2 below. These TCP libraries are supplied with an example project that demonstrates how to stream data between a TCP Server and multiple TCP Clients, with both server and clients running on the host PC (click Open Example Project in the tool to open the example project).

For this article, we will run the TCP Server library in a Workers application on a host PC, and the TCP Client library will run in a Workers application on a cRIO.

Figure 2 - Workers TCP Server and TCP Client libraries available in the Worker User Library tool

These libraries can be added to any Workers project by selecting either the TCP Client or TCP Server library (Figure 2) and pressing Add selected Item to Project. The Worker User Library tool will then create a copy of the selected library and add it to your project. You can then use the Public APIs for the TCP Server and/or Client libraries to obtain the functionality of these Workers libraries.

At the end of this article is a link to the Workers Community 'Additional Example Projects' repository, where you can download the example project that this article discusses. The remainder of this article will walk you through the usage of this example project that demonstrates how to stream data between a host PC and a cRIO using the Workers TCP Server and Client libraries.

Example Project Walk-through

The GitHub repository for this example contains two LabVIEW projects. The Host PC project contains the code for the Workers application that will run on the host PC. The cRIO Project contains the code for the Workers application that will run on the cRIO. The Worker call-chain diagrams of these applications were shown previously in Figure 1. To run these applications, you will need:

  • Workers 5.0 (or later) installed into LabVIEW 2017 or later (on host PC)

  • An NI real-time target such as a cRIO attached to the host PC

  • The IP address of the host PC that the cRIO is connected to

Following the steps below will help you run both of the applications in the correct sequence.

  1. Open both of the LabVIEW projects, as shown below in Figure 3.

    Figure 3 - Workers projects for both the host PC (left) and the cRIO (right)


  2. Make sure that the real-time target in the cRIO project corresponds to the real-time target that you have connected to your host PC. (Tip: you can add another real-time target to the cRIO project and then drag and drop the code in the project into your new target device.)

  3. Open and run the Workers Debug Server application on the host PC.

  4. Run the launcher VI of the host PC project. This will open the front panel of the head Worker's Main VI, as shown below. Press Start Listening on Port and the square LED next to the button should turn green. This means that the Workers TCP Server is now running on the host PC and listening for connections from TCP Clients.

    Figure 4 - Front Panel of head Worker's Main VI (Host PC Project)


  5. Open the front panel of the Launcher VI in the cRIO project. Enter the IP Address of the host PC of the ethernet port that the cRIO is connected to into the empty field Server IP Address, as shown below.

    Figure 5 - Front Panel of Launcher VI (cRIO Project)

    Important: The IP address you enter here needs to be correct for a connection to the host PC to be established. This value is also used for the Workers application on the cRIO to connect to the Debug Server application which is also running on the host PC. If this value is incorrect, then you will not see the Workers application running on the cRIO appear in the Debug Server's Application Manager window.


    Tip: if you do not know the IP address of the host PC that the cRIO is connected to, you can see the IP addresses that the Debug Server application is listening on, by pressing the Settings button in the Debug Server's Application Manager window. One of these IP addresses will be the one you need.


    Figure 6 - Debug Server's Settings dialog

  6. Run the Launcher VI in the cRIO project to deploy the Workers application to the cRIO. When the application has been deployed successfully to the cRIO, you should see the application appear in the Debug Server's Application Manager window, as shown below.

    Figure 7 - Debug Server's Application Manager window

  7. The front panel of the head Worker's running Main VI should now show that the cRIO TCP Client application has connected to it. You can now type a string in the textbox on the front panel. This string will be sent to the cRIO, and the Workers application running on the cRIO will return it back to the host PC Workers application. The received string (that matches the sent string) should appear as you type text into the text box, as shown below.


    Figure 8 - Front Panel of head Worker's Main VI (Host PC Project)

  8. The demonstration is complete. You can safely shutdown the Workers application running on the cRIO through the Debug Server, by selecting Send 'Start Exiting' Request from the selected application's right-click menu, as shown below.


    Figure 7 - Debug Server's Application Manager showing right-click menu

    Important : make sure that the host PC application is running BEFORE you run the cRIO application, otherwise the cRIO application will hang for approximately 60 seconds before it timeouts trying to connect to the non-existent TCP server application on the host PC.

Source Code

The LabVIEW source code for the example discussed in this article can be found in the Workers Community Additional Example Projects repository here.

You can use https://download-directory.github.io/ to download individual folders directly from the GitHub repository.