Use messages to send commands, status updates, or 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, LabVIEW NXG Web Module, and G Web Development Software.
Note This example uses the G Web Development Software 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.

    1Open Configuration initiates a connection with a SystemLink server.
    2Open creates a message session with the server, which allows you to subscribe to a message queue.
    3Subscribe registers an endpoint, such as a web application, to a specific topic.
    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.
    4Read 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.
    Note

    NI Web Server has a maximum timeout of 10 seconds. You can edit the timeout for the NI Web Server.

    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.

    1Open Configuration initiates a connection with a SystemLink server.
    2Open creates a message session with the server, allowing you to publish messages to a message queue.
    3Publish 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.

    4Close terminates the message session with the server.
    5Close 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.
    Note Topics are case sensitive.