Controller.Timer Property

Returns the current value of the controller’s clock, in units of seconds quantiized into 125 usec intervals, as a Double.

...Controller.Timer( select )

Prerequisites

None

Parameters

select

An optional numeric value that selects the reference time for the value returned.  Set to 0 to return the seconds since January 1, 1988 based upon the time-of-day setting.  Set to 1 to return the seconds since the controller was booted.  If omitted, this value defaults to 0.

Remarks

This method reads the current value of the controller’s clock and returns the time in units of seconds. This value is quantized into 125 µsec intervals, the system clock tick period.

If select = 0, this property returns the time since January 1, 1988, according to the system time-of-day setting. If you change the current time-of-day (using the Date console command, the web interface, or DataID 121), the next time this property is read, its value will reflect the change in the time-of-day setting. This value is useful for generating absolute timestamps. This value is not recommended for computing incremental time differences such as time delays and time outs since altering the time-of-day during the delay will result in unexpected results. Given the number of significant bits in a Double, this Timer value will not lose accuracy until approximately the year 2124.

If select = 1, this property returns the time since the controller was booted. The starting point never changes until the controller is rebooted, so this value is useful for computing time differences and timeout checking. Changing the time-of-day does not affect this value, so it is recommended that it be used for computing time differences. Given the number of significant bits in a Double, this Timer value will not lose accuracy until the controller has been running for 136 years.

Examples

Dim StartTime, ElapsedTime As Double
StartTime = Controller.Timer(1) ' Reads controller clock
Controller.SleepTick(2/Controller.Tick) ' Sleep for about 2 seconds
ElapsedTime = Controller.Timer(1)-StartTime ' Value will be approx 2


Dim EndTime As Double
EndTime = Controller.Timer(1) + 5 ' Timeout 5 seconds from now
While Signal.DIO(my_sig) = 0
If Controller.Timer(1) > EndTime Then
' Timeout error handler
Exit While
End If
Thread.Sleep
(100) ' Wait 100 msec
End While

See Also

Controller Class | Controller.SleepTick | Controller.Tick