Issue
Synchronizing time across many networks and multiple time zones
Product Line
Andover Continuum
Environment
Continuum Cyberstation
Cause
Guidelines for implementing an efficient yet compact Cyberstation PE program to synchronize time on large installations consisting of many Continuum networks across multiple time zones.
Resolution
The solution presented here requires that in each network the time master (controller with the lowest ACCNetId) is identified by setting its description to PTM. (Primary Time Master)
It is also recommended that the controller with the second-lowest ID is identified as the STM.
Obviously, the program itself could identify the time master for each Network but doing this outside of the program makes for a simpler, more robust implementation.
To implement the solution, simply create a program in one of the Continuum Cyberstations and insert the code provided below.
Configured the HOUR System Variable in the Cyberstation to trigger the program.
The program, as written, will sync the time once a day at 3:00 AM
There is a local variable (Verbose) that controls the level of information the program prints to the message window, recommends this be set to print everything when the implementation is first put in place to ensure it is operating as expected, then print only errors afterward.
'This program synchronizes time between Cyberstation and controllers across Networks and time zones.
'Program is triggered by the HOUR system variable
'SETUP
'In each network, the controller with the lowest ACCNetID must be identified as the Primary Time Master
' by setting its description to PTM
'Optionally, the controller with the second-lowest ACCNetID can be identified as the Secondary Time Master
' by setting its description to STM
'v1.0 SE PSS 1010 1011 1110 - FOR PROOF OF CONCEPT PURPOSE ONLY
'--------------------------------------------------------------------------------------------------
Object theCX
Object theNetwork
Object theWS 'The Workstation where the program is running
Number WS_UTCOffset 'The UTC Offset of theWS
Number syncDone
Number Verbose 'Prints to theWS message window. Set to 1 to print errors only, set to 2 to print synchronization information.
Line INIT
If Hour <> 3 then Stop 'sync time once a day at 3am
theWS = CurWorkstation() 'get the name of the Cyberstation where the program is running
WS_UTCOffset = getname("root\" ; theWS Alias ; " UTCOffset") 'and theWS UTC Offset
Verbose = 0 'default to silent operation
Goto SynchronizeTime
Line SynchronizeTime
If OpenList("Network", theNetwork) is Success then
While GetObject(theNetwork) is Success 'for each Network...
If Verbose = 2 then Print "Syncronizing time on NETWORK: " ; theNetwork Alias
If OpenList("InfinityController", theCX, theNetwork) is Success then
While GetObject(theCX) is Success 'for each CX controller in the network...
syncDone = False 'reset the sync done flag
'Print theCX alias REMOVE COMMENT TO PRINT CX NAME, HELPFUL WHEN DEBUGGING THIS PROGRAM
If theCX Description = "PTM" and theCX CommStatus = OnLine then 'is this controller the time master and if so, is it ONLINE?
If Verbose = 2 then Print "Time syncronized on NETWORK: " ; theNetwork Alias ; ", CONTROLLER: " ; theCX Alias ; " (Primary Time Master)"
getname(theNetwork Alias ; "\" ; theCX Alias ; "\Date") = Date + ((theNetwork UTCOffset - Cyber221 UTCOffset) * 60) 'synchronize its time
syncDone = True 'we're done with this network...
Break '...so break out of the inner while loop
Endif
If theCX Description = "STM" and theCX CommStatus = OffLine then 'look for a secondary time master if primary not online
If Verbose = 2 then Print "Time syncronized on NETWORK: " ; theNetwork Alias ; ", CONTROLLER: " ; theCX Alias ; " Secondary Time Master"
getname(theNetwork Alias ; "\" ; theCX Alias ; "\Date") = Date + ((theNetwork UTCOffset - Cyber221 UTCOffset) * 60) 'synchronize its time
syncDone = True 'we're done with this network...
Break '...so break out of the inner while loop
Endif
Endwhile
CloseList(theCX)
If syncDone = False and Verbose > 0 then Print "No time master found online for NETWORK: " ; theNetwork Alias ; "," ; Date
Else
If Verbose > 0 then Print "ERROR, can't open Controller list " ; Date
Endif
Endwhile
CloseList(theNetwork)
Else
If Verbose > 0 then Print "ERROR, can't open Network list " ; Date
Endif
Stop
Line E
If Verbose > 0 then Print "Program hit ERROR line, " ; Date
Stop