Create a server on the Academic RIO Device that listens for UDP datagram messages from a client running on the PC host, accepts client information including the desired state of the four onboard LEDs, sets the LEDs accordingly, and returns the state of the onboard 3-axis accelerometer and pushbutton.
Transmit the JSON string as a UDP datagram client request
Receive the server response (another JSON string) and convert to a cluster display showing server information (name, IP address, system time) and the state of the onboard pushbutton and 3-axis accelerometer
UDP server:
Listen for UDP datagrams on a user-defined port
Receive the client request (JSON string), convert to a cluster display, and set the state of the onboard LEDs according to the request
Create the JSON string containing server information and pushbutton and accelerometer states and return it to the client
Display all IP addresses known to the host
Code can be easily modified to transfer any type of information between the client and server
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.
Download and unpack the
rt_udp-client-server.zip (for use with NI myRIO 1900)
or the
NIELVISIII-rt_udp-client-server.zip (for use with NI ELVIS III)
archive, and then double-click the ".lvproj" file to open the project. NOTE: This project was written for a NI myRIO 1900 or NI ELVIS III connected by USBLAN at IP address 172.22.11.2.
If you are using a different IP address or another Academic RIO Device (Example: NI myRIO 1950 or NI RIO Control Module) do the following:
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"
Open and run “RT Main” under “NI myRIO 1900” to start the UDP server
Open “PC Main” under “My Computer”:
Ensure that “server IP address” matches one of the available IP addresses of the UDP server running on the Device; you should see 172.22.11.2 when the Device is connected by USBLAN, otherwise another IP address when connected by wireless
Ensure that the “server port” number matches the “listening port” indicator on the UDP server
Run “PC Main and observe the following:
“client message sent” cluster indicator updates with PC-related information
“server message received” cluster indicator shows the Device system information and sensor states
The same sets of information sent and received appear on the cluster indicators of the UDP server running on the Device
Click the “client LED request” buttons on the UDP client (“PC Main”) to generate single messages to control the Device onboard LEDs
Click “auto-send” to generate periodic client requests; change the physical orientation of the Device to change the accelerometer values, and push the onboard button, too
Note that the “my available IP addresses” process updates once a second on the client and well as the server; try enabling/disabling the Device wireless or connecting/disconnecting the wired Ethernet to get a feel for the various networks available to each system