Navigation: Standard Controls >

Timer Control

 

 

 

 

General
The Timer control is a count-down timer. It is set in seconds, (or fractions of: 1.5), with the interval property. It counts in hundredths of a second (0.01) and can be set to run only once, with runOnce enable, otherwise it will repeat its countdown indefinitely. Each time it reaches 0 it will trigger the event code and reset. It may be manually reset. The time can be shown as seconds or as 'Hours:Minutes:Seconds', or as fractions if showHMS is enabled. Note that the name appears in the text of the control.

 

Take care with high speed timers so that event code does not overwhelm the processing queue. The bottom bar on the Serial Control can be used to view the amount of data in the processing queue.

The timer may be started by setting runTimer to 1 or it can be started and stopped by double-clicking on it, if dblClickControl is enabled. It may be paused by setting runTimer to 0. The current time in seconds can be accessed at any time using [controlName] or [controlName.count]. It is a value and should not be changed directly.

NOTE: When an interface is saved, the runTimer property is NOT saved to prevent a Timer from running before finishing the interface processing. If running the timer automatically is desired, in the event code use:
 <load>!this.runTimer=1    // Enables timer when interface is done loading by !runLoad instruction.
 

Control Creation
Controls may be placed on the main or children interfaces using the Controls Palette, use F2 to open from the desired interface. When placing, it will ask for the name of the control, tmr is the recommended prefix for the name, such as tmrStop. It will also ask for the time of the interval. Once done, click a location or draw to desired size. Like most controls, the font size will be based on the height of the control.

A control may also be created using code, such as from the file save, the Debug/CLI window, the microcontroller sending the string, or other controls.
 !makeTimer Name, Left, Right (,Width, Height, interval)     Parameters in () may be omitted.

If it is to be on a child interface:
 !interfaceName.makeTimer Name, Left, Right (,Width, Height, Interval)     Parameters in () may be omitted.

Example:
 !makeTimer tmrStop, 20,20,20,5,20

Once placed, it may be repositioned and resized by unlocking the interface’s controls, F9, and dragging/sizing it. It may be copied or deleted by placing your mouse pointer over it and using CTRL-C and CTRL-X, and pasted using CTRL-V.

 

Instructions:
Instructions are used to inform the control to perform some operation.
The timer has one beyond the common ones:

reset                     Resets the timer to interval value, will not stop the timer.

See Instructions for more information on instructions.

 

Properties
Properties are the look, ‘feel’, and other characteristics of a control or object. They may be viewed or set using the Debug/CLI or the Interface Editor. Placing the mouse pointer over a control and pressing F3 will open the Interface Editor. Here you may view all accessible properties of the button control and modify them as desired. Please see the Interface Editor page for more information on the editor.

Properties may be set in code using:
 !controlName.property=someValue
 The default property, count, should not be set.

They may be read in code using:
 [controlName.property]

 

When used in its Event Code, [this] may be used in place of the controlName for reads and writes.

Ensure 'Transparent' is off when using the backColor.

The interval property is used to set the timer interval to a value, such as 10.5 seconds. Setting while running will switch it to the new interval.
 !controlName.interval = 20

The timer can display the count in seconds or in HH:MM:SS depending on the state of showHMS.

The runTimer property is used to enable or disable the timer by setting it to 1 or 0.

 

Values
 count:   The current count of the timer can be accessed with [controlName.count] or [controlName] and is always in seconds.

 

Update Value
An Update Value is used to update a property of the control when new analog, digital or message data arrives. As count is the default value, this feature should not be used with the timer’s default value, but other properties could be used, such as interval:

.interval = [ain0]

It will update with each subsequent string received.

 

Event Code
The only event trigger is when the timer reaches 0. Please see Event Code for a full discussion on event code.

The use of !this.someCommand or !this.someProperty in the event code refers to the control that is running it, as does [this.someProperty] or [this] for the control’s name and [[this]] for the control’s default value. This allows controls to have the same generic code for unique purposes and reduce coding issues such as if the name is changed.

Double-Clicking the Event Code text area will open the Code Editor where, like the Debug/CLI, it can provide contextual help and suggestions. Please see the Code Editor page for more information.

The code for a button control can be executed from other code in the interface using:
 !controlName.run

The control will trigger its normal event code when clicked. The only named trigger event the control currently supports is <load>, which will run its code when the !runLoad instruction is issued which goes to all control or !control.run <load> is used which will trigger the specific control. Load can be used to set a certain value in the control when the interface is loaded or !runLoad issued.

Please see advanced topics on using event triggers and passing data to events.

Supported Event Triggers:
 Timer reaches 0, no event trigger identifier used.
 <load>   Triggered when a !runLoad is issued, such as when an interface is loaded.

 

Events based on real time
The timer can be used to cause an action based on date/time, such as when the time reaches 15:30 (note, it uses 24 hour time) by setting up the event code. Create a 60 second timer with the event code of:
 !if [systemHour]==15 && [systemMinute]==30 !then !bell;? it’s time!
 A good name for the control would be: tmr1530.

Or, it could use controls on the interface making it settable:
 !if [systemHour]==[txtHour] && [systemMinute]==[txtMin] !then !bell; ? It’s time!

Similarly, a timer could perform a function every hour by testing only the currentMinute.

 

More Information:

There exist multiple means of getting information about specific control values, properties, instructions, and events. The Control Editor shown above has abbreviated descriptions in the right-hand column. Expand the window and column to see more at once.

The Controls Viewer allows users to see details on controls. Open using F6 and expand out to find the information of interest including examples of use.

 

The Debug/CLI and Code Editor also provide contextual help. Please see those pages on using them for help.

 

 

 

 

 

Copyright © 2024 SelmaWare Solutions, LLC