Table Of Contents

Sending Messages Between Systems

Last Modified: November 7, 2019

Use messages to send commands, status updates, or structured data, such as JSON, between systems and applications. Messages operate as a network queue, which uses the publish/subscribe model.

What to Use

You can find the SystemLink Message and Configuration APIs on the Data Communication palette in LabVIEW and LabVIEW NXG.
spd-note-note
Note  

This example uses the LabVIEW NXG Message and Configuration APIs. You can use the same code in LabVIEW to send messages between systems.

What to Do

  1. Create the following diagram in a VI to subscribe to and read messages.

    Customize the gray sections for your unique programming goals.

    Open Configuration initiates a connection with a SystemLink Server or SystemLink Cloud.
    Open creates a message session with the server, which allows you to subscribe to a message queue.
    Subscribe registers an endpoint, such as a web application, to a specific topic.
    spd-note-note
    Note  

    Subscribers of a topic receive every message published to that topic beginning from the point they subscribe. They do not receive or have access to messages sent before that point.

    Read returns a message from the queue.
    If there are no queued messages, the call synchronously blocks up to the timeout specified or to the maximum timeout defined by the web server, whichever is smaller. If you leave the timeout milliseconds input unwired, the Read node has a default timeout of 100 milliseconds. In this example, the timeout is set to 2000 milliseconds.
    spd-note-note
    Note  

    Both NI Web Server and SystemLink Cloud have a maximum timeout of 10 seconds. You can edit the timeout for the NI Web Server, but you cannot adjust SystemLink Cloud's timeout.

    To adjust the timeout for NI Web Server, edit the configuration file of the server. Refer to Configuring NI Web Server more information.

    Use Unflatten from JSON when using Read to make messages easier to parse from a web browser.

    Use a While Loop to continue reading messages until a condition is met. In this example, the node reads messages until there is an error.

  2. Create the following diagram in a VI to publish messages.

    Customize the gray sections for your unique programming goals.

    Open Configuration initiates a connection with a SystemLink Server or SystemLink Cloud.
    Open creates a message session with the server, allowing you to publish messages to a message queue.
    Publish writes a message to a topic. If multiple messages are published, the subscriber reads the messages in the order they are received.

    Use Flatten to JSON when using Publish to convert LabVIEW data types to string, which is the only data type messages support, and to easily interact with the data when reading messages in LabVIEW and other JSON-supported languages.

    Use a Case Structure to set up conditions for when to publish. In this example, Publish write messages until you move the Publish switch to the off position on the panel.

    Use a While Loop to continue publishing tags until a condition is met. In this example, Publish writes messages until there is an error.

    Close terminates the message session with the server.
    Close Configuration cleans up connections associated with the configuration by invalidating any open references to created objects.

Troubleshooting

If you encounter errors, try the following troubleshooting strategies:
  • Call Subscribe before calling Read. You must subscribe to a topic before your program will read a message.
  • Verify that you are subscribed to the right topic before running the code.
    spd-note-note
    Note  

    Topics are case sensitive.


Recently Viewed Topics