Synchronize the system clock to a NIST time source
Synchronize the system clock time based on querying the Internet Time Service (ITS) maintained NIST (National Institute of Standards and Technology): Open a TCP/IP connection to the "Daytime Protocol" port 13, read the 51-character string, parse the string for time and date information, validate the result (look for a server health indicator and a "magic string"), and then adjust the system time.
Use cases
Synchronize the RT system clock to an external time source (Internet Time Service, or ITS)
Include in the RT start-up VI to keep the system clock always up to date (RT has no built-in real-time clock to preserve the correct time/date across power cycles)
Features
Communicates with the NIST Internet Time Service (ITS) via a TCP/IP connection
Opens a TCP/IP connection to the “Daytime Protocol” on port 13
Reads the returned 51-character string, and parses it for the time and date information
Validates the returned string by checking that the “server health” digit is at least 1 and that the label “UTC(NIST)” magic string is present before actually adjusting the RT system time
Packaged as a subVI (“sync clock to NIST time.vi”) that you can easily incorporate into your own project
Keep in mind
RT requires a network connection capable of reaching the Internet
Consult a time zone selector service such as the TWiki.org Timezone Selector to obtain your time zone, a required input for the LabVIEW “Set Time” VI that adjusts the RT system time
Adjust the “century number” input should you be running this code after the 21st century
IMPORTANT: Do not run this subVI more frequently than once every 4 seconds or your IP address may be blocked the NIST time server!
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:
Run the “check internet access (tcp)” VI to confirm that the Device can reach the Internet (the “Internet OK” indicator lights up).
Download and unpack the
rt_time-sync-to-nist.zip (for use with NI myRIO 1900)
or the
NIELVISIII-rt_time-sync-to-nist.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” and observe the following:
The “time before sync” indicator displays the system time before an attempt is made to contact the NIST time server; this value is likely quite far from the correct time depending on the “System Start Time” stored on your Device (to see this value, use NI MAX or browse to http://172.22.11.2 (requires USBLAN connection) to look at the “System Settings” tab for your device)
The “time after sync” shows the updated time after contacting the time server
An inactive “sync OK” front-panel LED indicates that the synchronization process failed, possibly due to an unavailable Internet connection, inability to contact the time server, or garbled return string