Send command and status messages through a low-latency lossless network-based data communication channel between the RT target and PC host system.
Use cases
Exchange command and status messages with the PC host
Intermittent data transfers that require minimum latency (delay)
Lossless data transfer, i.e., when every data point matters
Features
Ideal for exchanging messages between two endpoints, one on the RT target and the other on the PC host
Transfers any LabVIEW data type – not necessary to first flatten the data to strings as required by standard UDP and TCP protocols as in the TCP client-server and UDP client-server code examples
Keep in mind
Use a timeout value of zero for the stream writer to ensure that the message is immediately send through the channel, otherwise the network stream manager in an attempt for efficient use of the network connection may buffer (hold) several messages before sending in a batch
Streams can be destroyed at either endpoint, i.e., it is not necessary for both VIs to do this
Stopping a VI also destroys its endpoints – special care is required to ensure a VI does not attempt to read/write the network stream once the other VI has stopped
LabVIEW block diagram elements
Locate these elements with "Quick Drop" (press Ctrl+Space and start typing the name); click on an icon to see more sample code that uses that element:
Example code
Connect your Academic RIO Device to your PC using USBLAN, Ethernet, or Wi-Fi. NOTE: Not all Academic RIO Devices have Ethernet and Wi-Fi connectivity options.
If using the NI myRIO 1950 or NI RIO Control Module start with the NI myRIO 1900 Archive.
Different IP address: Right-click on the "NI myRIO 1900" Device, choose "Properties", and then enter the new IP address
Different device:
Right-click on the top of the project hierarchy, select "New Targets and Devices", keep the "Existing target or device" option, and then find and select your particular device
Select all of the components under the "NI myRIO 1900" device: click the first one and then shift+click the last one
Drag the selected components to the new device
Right-click the "NI myRIO 1900" device and select "Remove from project"
Run “RT Main”
Review the available RT target IP addresses:
172.22.11.2 corresponds to the USBLAN
127.0.0.1 is the loopback address (not reachable by other network hosts)
Other addresses may appear depending on your particular network configuration, e.g., wireless and wired connections
“RT Main” creates one endpoint of the network stream as a reader, and then displays “messages” (integers) sent from the PC host as they arrive; the VI shuts down the endpoint when a negative integer is received
Open “PC Main” and enter a suitable IP address (the USBLAN is default)
Run “PC Main”
“PC Main” creates the other endpoint of the network stream as a writer
Enter a message of one or more integer values and then click “send”
Change the message and click “send” again; right-click on the array control and choose “Insert Element Before” or “Delete Element” as needed
Click “Stop” to send a -1 to shut down the RT VI
Re-run “PC Main” without running “RT Main” and observe that the “RT connected?” indicator is off – this indicates that the reader endpoint of the network stream does not yet exist
Click “send” and observe that the button is stuck down – this indicates that the PC host writer is blocking data flow until the network stream is established; run “RT Main” to clear the blockage
Assemble URL of RT-side network stream reader endpoint
Create network stream writer endpoint on PC side
Indicate when endpoint on RT side is connected
Send one or more integers as “messages” when “send” button is clicked
Send -1 when “Stop” button is pressed to signal RT to stop
Wait for RT endpoint to be destroyed and then stop
RT Main
Display available IP addresses
Create network stream reader endpoint
Read and display the integer “messages” received from PC
Stop when -1 is received and destroy the endpoint
“PC Main” details
Network stream URL is of the form “//IPaddress/endpoint” where “IPaddress” designates the IP address in dot-decimal notation of the RT target and “endpoint” designates the name of the RT-side reader endpoint, e.g., “RT-reader”
Boolean “F” constant initializes the front panel indicator “RT connected?”
“Create Network Stream Writer Endpoint” function creates the PC-side endpoint with the name “PC-writer” and with buffer size and data type; use default timeout of -1ms to block until the RT creates its corresponding endpoint
Property node confirms RT is connected and updates “RT connected?” indicator using a local variable
Event structure:
Write integer “messages” to the network stream when “send” button is clicked
Important: Use 0 timeout to ensure that messages are transmitted immediately
Send -1 when “Stop” button is pressed to signal RT to stop
Property node in while loop polls network stream status to wait until the RT-side endpoint is destroyed
“RT Main” details
“String To IP” with “Multiple Output” option returns array of all available IP addresses of the RT target
For-loop with “IP To String” with “dot notation” enabled converts IP addresses to dot-decimal notation; “PC Main” must use one of these addresses
“Invoke Method” initializes the “messages received” indicator
“Create Network Stream Reader Endpoint” function creates the RT-side endpoint with the name “RT-reader” and with buffer size and data type; use default timeout of -1ms to block until the PC creates its corresponding endpoint
Read and display integer “messages” from the network stream as they arrive
Reading a negative value for the message stops the main loop and destroys the RT-side endpoint
Using the Right Networking Protocol (http://www.ni.com/white-paper/12079/en)
Discusses the three most-common communication models -- command or message-based, process data, and streaming/buffered -- and the available networking protocols that are best suited to each model: TCP, UDP, network-published shared variables, network streams, and web services.