Example Code

Set TimeStamp for LabVIEW RT Device using NTP

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 Real-Time Module

Code and Documents

Attachment

Description

Synchronizing with an NTP server in this way is not recommended. Please see the Choosing a CompactRIO Synchronization Technology article for details on how to sync with an NTP server.

 

 

 

Why is this vi available?

 

Sometimes system clocks drift in time, also useful when synchronising multiple devices to a known time stamp using a known NTP server. This vi will set the time of a networked RT device from a known NTP location.

 

How to use?

 

Place the "Get TimeStamp from NTP" subvi within a timed loop. Specify a Time Server IP Address for the NTP server you would like to synchronize to. Do not run the time loop too often, as this can also cause the RTC to drift ( Using LabVIEW to Read the Real-Time Clock (RTC) Directly From BIOS )

 

SubVI

 

Get TimeStamp from NTP.png

 

Recommendations

 

  • Place in a timed loop, and set the time loop to run every hour. This will allow to set the time every hour to account for time drift.
  • Need to make sure you have the Network Gateway and DNS set correctly for your network as the vi uses UDP.

 

Requirements

 

  • LabVIEW 8.6
  • LabVIEW RT
  • Real Time target
  • Connection to the internet and correctly set network settings

 

 

Ashish Naik
Automotive Business Development Manager
National Instruments UK

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

Comments
Paolo_Squillari
Member
Member
on

Good job!!! I I was looking for this VI since 3 months!

Thank you very much.

Paolo.

falseth
Member
Member
on