Using Programming Commands

SAC and the Program Block

When SAC scans a Program block, it generally runs all of the block's commands within one scan period. After scanning the Program block, SAC does not scan it again unless:

  • The block is placed on scan again by the operator or another block, such as an Event Action block or another Program block.
  • The database is reloaded.
  • The block contains a test or wait command, and the specified condition is not met. For example, if you have an IF command that tests for a specific level and issues a GOTO command to a previous step if the level is not met, SAC continues to scan the block until the condition is met.
  • GOTO 0 is the Program block's last statement. In this case, the block continually loops and SAC scans the block according to the specified scan time.

Delaying Program Commands

Certain commands limit a test command's duration. For example, you may want to use the WAITFOR command to have the Program block wait for an Analog Input block to receive a value of 50 before it proceeds to the next command. However, if the Analog Input block never receives a value of 50, the remaining commands never execute. To avoid this result, you can use the MAXWAIT command. This command specifies how long the block waits before it automatically goes onto the next command. You could then use the GOTO command to tell the Program block to jump to a particular command found later in the programming sequence. For example:

09 MAXWAIT 60
10 WAITFOR AI1 = 50
11 GOTO 16

In this example, the block waits 60 seconds before executing the GOTO command. The GOTO command specifies that step 16 is the next step to execute.

If you set up a command that waits a long time to complete, you should also include a command that notifies you when the wait ends. This method allows you to determine if an event has occurred. For example:

04 WAITFOR AI1 = 50
05 MSG AI1 IS NOW 50

In this example, the message "AI1 IS NOW 50" prints only when AI1 has successfully reached a value of 50. If AI1 never reaches 50, the message is not sent to the enabled alarm destinations.

Clamping Values

If the Program block sends a value to another block and the value exceeds a target block's EGU range, iFIX clamps the value to the block's high and low EGU limits. For example, if you SETOUT a value of 150 to a block whose EGU range is 0 to 100, the setout value is clamped at 100.

Execution Errors

The Program block goes off scan whenever it cannot execute a command. Prior to going off scan, the block sends a message to all the enabled alarm services in its alarm areas. The off scan message explains at what line the block stopped and why.

Make sure you test your Program blocks thoroughly before placing it in actual operation. You can use the debugging commands, SETDEBUG and CLRDEBUG, to help test your Program blocks before placing them online.