There are times when you need to have some logic running continuously on a Red Lion Crimson device. This Tech Tip will show you several ways to achieve this.
For devices with or without display pages, the program can be called from either the On Tick or On Startup Global actions under the communications area as shown below. Selecting On Tick will execute the program every 1s. Selecting On Startup will run the program once at the device start and will require an endless loop for the program repeat.
In order for the program to release processor time back to Crimson for other tasks, the program should have the Execution Tasks set to Background X. Where X is 1-3 for the 3 background tasks that allow for up to 3 independent task threads. The selection for External Data relates to the reading of tags and what should happen if the data is not available. The Run Anyway check box allows the script to run even if the tag data is not available.
An example program for On Tick would be as follows. This would result in the value of MyTag incrementing by 1 every 1s until it reaches 1500 when it will return to 0 and start incrementing again.
If logic needs to execute faster (or slower) than every 1s, the program can be called On Startup using an endless loop. This loop will execute as fast as possible depending on the requirements of communications and other tasks. This could cause the device to appear sluggish and unresponsive. To avoid this and to control the rate with this logic runs, the Sleep command should be used. This puts the task to sleep for the period inside the braces in milliseconds and frees up the device to attend to other tasks. The Sleep command should only ever be used in a background task. If used in a foreground task it will sleep the device and impact performance.
For devices that have display pages, there are few extra options as shown below. There is very little distinction between On Power Up and On Startup. On Power Up occurs first and On Startup Up is slightly later. The Crimson Help states that the difference between these “does not concern most users”. On Tick is also the same 1s as described earlier and On Update defines an action to be run on each display update.
These methods are valid ways to run repetitive logic that needs to run at a regular interval that cannot be tied to a screen object, user action, or PLC tag value.
For more information on Red Lion Crimson software contact us by clicking here. |