Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

NetworkTimeProtocol coding for CRBasic


SignalGuy Sep 12, 2013 07:59 PM

In an unattended environment with an active 3G modem, a networked CR1000 has been programmed to capture data samples every 100 milliseconds. This data is stored with a time stamp that needs to be relatively accurate. Loggernet has been configured to automatically update/correct the CR1000 clock but only works when LoggerNet is running on local host PC running Windows 7 Professional. Power stability at site is an issue, and in testing, when the PC restarts, LoggerNet does not auto-restart - even when shortcuts are placed in Win7 Start-up folder. I was reading in forum that NetWorkTimeProtocol() can be incorporated into a scan loop in the running CRBasic program, but no examples of CRBasic coding are given. I would like to see coding samples for NetworkTimeProtocol()that include the IP address for an NTP server so the CR1000 does not have to rely on LoggerNet running for CR1000 timeclock updates. Your experiences regarding this feature also welcomed. Thanks in advance for any help offered.


jra Sep 13, 2013 03:02 PM

SignalGuy,
In CRBasic there is an example program for every instruction. Select the instruction from the Instruction Panel, click the Help button, see the link to an Example at the top.
I hope that helps.
Janet


SignalGuy Sep 13, 2013 07:05 PM

Thanks for your response Janet.

To keep track of relative time, I was thinking about incorporating a variable that tracks the number of scans that occurs through the Scan loop. A threshold value would be pre-determined that would coincide with the desired update of the Station time through the NTP server.

Because the datalogger program is configured to do scans every 100 milliseconds (or 10 times per second) and the desired NTP update interval will be set to 5 minutes, which is 300 seconds, the scan counter would need to be set to count 3000 scans and reset.

Using the IP address for ‘time-nist.symmetricom.com’, here is the CRBasic program code that I added to the program to include the NetworkTimeProtocol() command in the CRBasic program:

---------------------------------------------------------
Public Loop1 As Float
BeginProg
Loop1 = 0
Scan (100,mSec,0,0)
'NEW - Count Loop to run NetworkTimeProtocol function every 5 minutes (300 sec x 10 samples per sec)
If Loop1>3000 Then
NetworkTimeProtocol("12.10.191.251",-21600,1)
EndIf
If Loop1>3000 Then
Loop1=1
EndIf
Loop1=Loop1+1
NextScan
EndProg
---------------------------------------------------------

I am sure that the CRBasic coding can be written tighter, but its my first attempt at this.

The offset here to GMT is 6 hours, but does not take into account Daylight Savings Time. I manually synched the CR1000 timeclock to the host PC and could see when the CR1000 timeclock first updates to Standard Time. So far (4 hours have passed) its worst case tracking is about 1 second slow.

I have declared Loop1 as a Public Variable so I can track its operation on a Numeric Screen. When it starts, both the record counter and loop1 variable track exactly. Every 3000 loops, the Loop1 resets to 1, and so far the records track on the 3000 count rotation.

My next post will advise the error after a few days of operation.

Please feel free to share comments.

Regards - SignalGuy

* Last updated by: SignalGuy on 9/13/2013 @ 1:06 PM *


SignalGuy Sep 16, 2013 03:50 PM

After more than 2.5 days of operation, there was less than 2 seconds of time difference from true Internet time to the CR1000 internal timeclock. In fact, the local host PC was reconfigured at the same time as the software code was added to the CR1000 program to the same NTP server and there was a 14 second difference when checked at the same time. When I allowed the host PC to resync back to the Windows default time server, the time on the PC corrected those 14 seconds. The next change was to make the program check the NTP site every 100 seconds (Loop1 value is now 1000). More later!

Log in or register to post/reply in the forum.