Timers

There are two Timer Components that can be used to execute custom code at a specified "tick" interval.

Note: The OnTick() script can be used to define the custom code for the timer. After adding a Timer device, right-click the Timer device in the Project Explorer, and select On Tick from the Scripts menu. If, for example, the application should execute the Task when the Timer "ticks" to its next interval, the $Tasks.Task.Run(); script would be added to the OnTick() script.
  • High Precision Timer

    The High Precision Timer is useful for executing code at very small intervals (for example high-speed functionality, reading I/O lines), with a higher degree of accuracy. It can be set to an interval of 1 millisecond.

    There are a limited number of High Precision Timers available per system; Cognex recommends that no more than 3 or 4 High Precision Timers be used, per project.

  • Standard Timer

    The Standard Timer is suitable for most user-interface updates, and other non-critical items (or example, updating the HMI status periodically). It can be set to an interval of 20-30 milliseconds.

    There is no limit on how many standard timers you can run per project.

    Note: The standard timer runs on the UI thread, so it can block the UI if a long running process is performed in the OnTick() script.
ControlDescription
NameThe name of the timer.
IntervalThe rate at which the timer should tick, in milliseconds.

Tags & Functions

TagDescription
Start()Function that starts the timer.
Stop()Function that stops the timer.
IsRunningA Boolean tag indicating whether or not the timer is running.
OverrunCount

Measures the time taken to run the OnTick() script; if the time to run the OnTick() script is longer than the specified Interval value, the OverrunCount value will be incremented by 1.

Note: The OverrunCount tag only applies to the High Precision Timer.