This lesson is part of the Sequential Function Charts in Ignition course. You can browse the rest of the lessons below.

LESSON LIST

Autoplay Off

Description

Here is a detailed explanation of how the Action Step functions in a Sequential Function Chart. You can configure the Action Step to function On Start, On Stop, as Timer, or an Error Handler. This video loops using a chart counter variable as its example.

Video recorded using: Ignition 7.9

Transcript

(open in window)

[00:00] The Action Step is one of the most important elements in the SFC Toolkit. The Action Step run scripts to do things like write to tags or run database queries. An Action Step is configured by adding various actions each of which will run a script. The Actions you can configure are: On Start, which will run when the step first starts running, On Stop, which will run right before the step stops, Timer Actions, which run while the step is running, and Error Handlers, which will run if one of the other actions raises an uncaught error. These Actions are defined by implementing a Python function, which has been defined for you. So, you can see here that this On Start function receives two parameters, chart and step. Chart is a reference to your Chart Scope, and step is a reference to the Step Scope, which is a very similar type of object except that, unlike the Chart Scope, which lasts for the whole lifetime of a Chart Instance, the Step Scope only lasts as long as the step is running. You're guaranteed that both the On Start and On Stop actions will both run once, but the Timer Actions may not necessarily run. They only run if there's a Transition beneath the step which is false for long enough for the Timer Actions to fire. So, for example, in this setup, you note that the Timer Actions just won't fire because there's no Transition beneath a step. And, anytime a step doesn't have a Transition beneath it, it acts the same as if there were a step, I'm sorry, if there were a Transition who's value is always true. Your Action step can be configured with any number of Timer Actions, each of which can have it's own execution rate. However, you should beware that these Timer scripts will never execute simultaneously, in fact, none of the Actions on the Action script will execute simultaneously. So, if you have a Timer Action whose script takes a long time to complete, it might block some of the other Timer Actions from executing when they're supposed to execute. If you need multiple things to execute at the same time, you should use a Parallel section. As soon as a Transition underneath an Action step becomes true, this step will wait for any of the Actions that are currently running to finish, and then it'll enter the stopping state, and it will execute the On Stop Action, if any. And, the step will remain in the stopping state for as long as the On Stop Action takes to complete, after which the step will be stopped. Only after the step stops can the Chart then execute the next element. The Error Handler Action is an optional Action that let's you catch any uncaught scripting errors thrown by other Actions. So, if you don't have an Error Handler, and one of the other Actions raises an uncaught error, the Chart Instance will abort. But, if you do have an Error Handler, this will be called instead, and you can deal with the error. If this script causes an error, the Chart will abort. Let's take a quick look at how to use these Action steps in practice. So, I'm going to go ahead and take this step, and configure my On Start Action to run a script. And, in this script, you can do all the normal stuff you normally do in scripting. So, I have system right here at my fingertips, so I could say, "System dot "tag dot right", or what have you, but in this example, I'm just going to write some variables to Chart script. So, I'm going to say, "Chart dot message "is equal to I started", and I'm going to make another one, chart dot count, equal to zero. In my one second Timer Action, I'm going to increment that counter, so chart dot count, plus equal one. And, on my On Stop, I'm going to go ahead and alter the message, so chart dot message is equal to I'm done. All right. Now, I'm going to take this Transition, and configure it to wait for the count to be, let's just say five. So, that should let the step run for five iterations of my Timer. All right, let's go ahead and save this, and start it up here, and watch it run. So, we can see it that I'm running, you can see my counter counting over here in the Chart Scope, my message just switched to I'm done 'cause five seconds isn't very long, and that's it, that's how you use the Action Step.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.