Example Code

Universal Network Streams

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Description

Overview

Have you ever had a problem with using Network Streams? The example I prepared can be run on PC, cRIO, sbRIO in all imaginable configurations - also when the program is compiled to an executable. It will help you easily integrate Network Streams into your application.

 

Description

It happens, that even though the program works fine, when you create an executable or change the target the endpoints stop communicating and you need to modify the code. Usually the main problem is the endpoint name - you should always follow the rules described here.

What my code does, is that it automatically detects whether the application is run from development environment, or an exe file. Depending on that, it constructs proper endpoint names, and publishes them using network published shared variables. This way both the "reader" and "writer" can automatically connect, even if you don't provide an IP.

 

context.PNG

 

 

I have tested this solution in many combinations:

EXE on PC <=> RTEXE on RT

VI on PC <=> RTEXE on RT

VI on PC <=> VI on RT

EXE on PC <=> VI on RT

Everything worked fine - without any code modifications.

 

 

The use of shared variables is not always feasible, so you can modify the code to fit your needs. The endpoint name can be for example just displayed on the front panel. The core of this example is context.vi. It is responsible for building proper endpoint names, and is universal.

 

Steps to Implement or Execute Code

1) Download the attachment.

2) Go through the code, read the documentation.

3) Move the "user 1" and "user 2" VIs to create your own setup.

4) Run the program.

 

Requirements

LabVIEW 2013 SP1

Network Variable Engine (if using an RT target)

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
PrimaryKey
NI Employee (retired)
on

Great job, though based on my previous work

Piotr Kruczkowski
Certified TestStand Architect
Certified LabVIEW Architect
stockson
NI Employee (retired)
on