Set RT System Time to Windows PC Time Down to Milliseconds

Updated Apr 17, 2018

Reported In

Hardware

  • CompactRIO Controller
  • CompactRIO Single-Board Controller
  • CompactRIO Controller (Legacy)

Software

  • LabVIEW
  • LabVIEW Real-Time Module

Driver

  • NI CompactRIO

Operating System

  • Windows

Issue Details

I am setting up CompactRIOs (cRIOs) and single-board RIOs (sbRIOs) and want them to have the same time as my windows computer.  The cRIOs and sbRIOs will never communicate with each other and are not on a network.  Once the cRIO or sbRIO is set up, they are disconnected from the computer and run headlessly without network connection for the duration of the application.  I need to make sure that when I set each RIO up that their system time is as close to my PC's time as possible so there is less variation between each system.

Solution

Since there is no continuous connection between the computer and the cRIOs and sbRIOs and since they do not have network connection, we cannot use the usual synchronization technologies such as SNTP and IEEE 1588.  However, we can set the clock on each RIO system to the clock on the PC during the configuration stage when the cRIO or sbRIO is connected to the computer.  You can write a VI that does the following steps:
  1. Pull the time from the Windows OS:
    1. Place a Call Library Function Node on the block diagram.
    2. Double-click the node to open the Call Library Function dialog box.
    3. Click the Browse button and select the kernel32.dll (usually found at C:\WINDOWS\system32\kernel32.dll).
    4. Select GetSystemTime from the Function Name drop-down list.
    5. Select stdcall (WINAPI) from the Calling Conventions drop-down list.
    6. Under the Parameters tab, for return type select Numeric and select Signed 8-bit Integer.
    7. Click Add a Parameter After and for Type select Adapt to Type and for Data Format select Handles by Value.
    8. Click the OK button to configure the Call Library Function Node.
    9. This function returns a structure of eight WORDS (16-bit unsigned integers). To replicate this in LabVIEW, create a cluster of eight WORDS (U16 numerics). The eight WORDS represent the Year, Month, Day of Week, Day of Month, Hour, Minute, Second, and Millisecond. Wire the cluster to the input of the Call Library Function Node.
    10. Type Cast the output of the function node to the same cluster created in the previous step.
    11. The output of the Type Cast will contain all the system time information. 
  2. Format the Windows System time into a LabVIEW TimeStamp format:
    1. Unbundle By Name the output of the TypeCast
    2. Build the TimeStamp string using Format Into String node and the format string argument of %d:%d:%d.%d %d/%d/%d.
    3. Use the Scan From String node and the format string argument of %<%H:%M:%S:%3u %m/%d/%Y>T or the one specific for the format you want to make the string into a TimeStamp datatype. 
  3. Open Up a session with the RT Target that you want to set the time for and use the Set Time.vi (Real-Time >> RT Utilities >> System Configuration >> Utilities >> Set Time.vi) to set the system time on that RT Controller.  You will take the TimeStamp created from the previous step to feed into the Set Time.vi. 
When you run the VI that does the three steps described above, the RT controller will be set to the time of your Windows Computer.  Note that the time pulled from your Windows Computer is in UTC/GMT time.

Attached is a VI that will pull the time from you Windows (64-bit) PC and set the time on the Real-Time Target of your choosing.

Additional Information

You can check to make sure the time you set on your RT Controller is correct while you set the time by using System Property Nodes as shown below:


On your RT Controller side, you can pull the time using Get Date/Time In Seconds.

WAS THIS ARTICLE HELPFUL?

Not Helpful