The following are examples of TCP communication between a LabVIEW and a C++ application, both executing on an NI Linux Real-Time target.
There are two examples; LabVIEW Server with C Client and C Server with LabVIEW Client. Both examples are configured for localhost communication.
Software versions:
LabVIEW and LabVIEW Real-Time 2015 (2013 and 2014 projects also attached)
C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition 2014
Note: For the most up-to-date C/C++ Tutorials for NI Linux Real-Time, visit ni.com/info and enter the Info Code NILRTCrossCompile.
Included Files:
Caveats:
The LabVIEW project is default configured for an sbRIO-9637 but this can be changed by adding a new target to the project and transferring the example files to that target.
The Eclipse Projects are configured to build for an ARM target but can also work for Intel x64 targets. You will need to update the Prefix and Path values in the Cross Compile settings in the project (Project Properties >> C/C++ Build >> Settings >> Tool Settings tab >> Cross Settings).
LabVIEW Server with C Client Example Instructions:
1. Run the TCP Server.vi on the Linux RT controller. Note that the default port to listen on is 10117.
2. Run the C Client and LV Server TCP Example Debug application on the target providing it arguments for the IP Address and port to communicate. For this example it should look something similar to: C Client and LV Server TCP Example Debug 169.254.50.37 10117
3. The LV TCP Server code waits for the amount of data to read, reads the corresponding data, calculates the mean, and displays the mean and source data to a chart.
4. The C Client sends 50 sets of 100 random integers ranging from 0 to RAND_MAX (int max 2147483647).
5. The example will stop automatically after the client has sent 50 sets.
LabVIEW Client with C Server Example Instructions:
1. Run the C Server and LV Client TCP Example Debug application on the target providing it an argument for the port to listen on. For this example the default port is configured for 10117 in the code the command should look similar to: C Client and LV Server TCP Example Debug 10117
2. Run the TCP Client.vi on the target.
3. The C Server code accepts the connection to the client and then reads a known size (804 bytes) from the IP socket. It then calculates the mean of this data and prints it to console.
4. The LabVIEW Client continuously sends 100 random doubles ranging from 1 to 0.
5. Stop the client to terminate the connection and end the example.