Call us! 512-349-0334 or (877) INDUSOFT

How to Make a Multi-Second (or Minute, or Hour, etc.) Timer with One Tag in InduSoft Web Studio

InduSoft Web Studio users occasionally want to make a multi-second timer and usually end up using a Scheduler Worksheet and perhaps also a Script Task and count the number of seconds (or minutes, etc.) until the counter reaches the goal, and then write some value to a trigger tag (usually a Boolean), using a technique that needs two or more tags.

Is there a simpler way to do this? Yes, with some caveats.

By using a Scheduler Worksheet and putting the desired system time interval tag (e.g., Second, Minute, Hour, etc.) into the “Trigger” field and choosing “Change” in the “Event” field, whenever that system tag changes value, the value in the “Expression” field will be written to the trigger tag entered into the “Tag” field. The event can be disabled for certain Boolean conditions (e.g., the result of an expression being a “0” or a “1”) by entering that value into the “Disable” field (real or integer values in expressions resulting in a non-zero value are evaluated as a “1”).

Therefore, if you fill out a Scheduler Worksheet as shown here:


…the tag “bTrigger” will toggle between 0 and 1 every 10 seconds of the system clock.

If you change the denominator in the Modulo function to a 2, 5, 6, 10, 20, or 30, the trigger tag will be toggled every 2, 5, 6, 10, 20, or 30 seconds, respectively.

A slight modification of this technique by placing a “1” into the Expression field will ensure that the trigger can be reset when you desire it by writing the reset value (0) back to the trigger tag in your scripting when-or-as needed, creating a true toggle situation such as when a procedure or subroutine is called, the trigger value can be reset when the routine is complete.

Notice the caveats when using this technique: First, the technique only allows you to create a 2, 5, 6, 10, 20, or 30 second timer. Why is this? The Modulo function returns the remainder of a division operation. Since there are 60 counts in the system tag “Second” before it resets (as used in this example), anything that can divide into 60 and return a “0” as the remainder will allow the value in the “Expression” field to be written to the tag in the “Tag” field at the trigger event.

For example, suppose you wanted to create a 23-second timer with this technique and you enter “23” into the denominator field. It would work properly in the first 23 second interval (23), the second 23 second interval (46), but when the system tag resets back to “0”, the resultant division returns a “0” remainder. (0/23 = 0 with “0” left over). So the final toggle would occur at a 14 second interval instead of 23. So for this case, it is necessary to create the counter as was mentioned in the first paragraph.

The second caveat is that the occurrences of the clocked trigger tag are synchronized to the computer clock. This is really no good if you need a truly asynchronous counter for a specific number of seconds. In this case, it would be necessary then to go ahead and build a counter script with independent Start, Stop, and Counter tags, etc., and just use the system tag “Second” change as the interval trigger to increment the counter in the script.

Comments are closed.