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

Learn how to design a chart that can interact with an operator at a client terminal and vice versa. You can use the system.sfc.StartChart function to start the SFC, and use message handlers to pass information back and forth.

Video recorded using: Ignition 8.1

Transcript

(open in window)

[00:00] In this lesson we're going to learn how we can use sequential function charts to interact with vision clients. Why would you need to do this? Imagine you have a chart that controls a process. An operator initiates the process from a client and at some point later the chart may need to confirm if something is in the correct position. It may also need the operator to manually add an ingredient or confirm another action. There's a number of reasons why a sequential function chart might need to communicate with the user interface. With sequential function charts however, they are executed on the gateway so they can't directly open up a vision window to send notifications or something like that. To achieve this, we can make use of a combination of techniques. I already have this set up in my project and there's a number of parts that have to work together. I'll walk you through all of them and then we'll see it in action. To start, I have this SFC named feedback. The chart expects that a client ID is sent into it. That's going to be the ID of the client that the chart is trying to communicate back with.

[01:07] If the chart starts and the client ID isn't there, we log an error message to the system console. Otherwise we have a short two second delay and then we send a message down to the client. This is done using system.util.sendMessage(), which invokes a message handler on the client. So we specified the name of the project. In this case, I'm in a project called SFC. The message handler name, which is feedback prompt. The ID of the client session to invoke the message handler on which is the parameter that will be passed to this chart and a payload, which is whatever message I'm trying to send to the client. In this case, we're just sending the ID of the chart. So the chart is invoked with the ID of the client and then it sends a message to that client with the ID of the SFC instance. And then it waits for a chart scope variable named choice to become either A or B, at which point it just lights up one of these action steps that do nothing. Moving on, I am making use of some vision windows for the operator to use.

[02:05] The main window which will open on startup has an SFC monitor component and a button to start the SFC. Let's review the buttons action performed script by right clicking into the scripting option. First it gathers the ID of our client with system.util.getClientid(). It then starts an instance of the feedback SFC and sends it the expected client ID parameter using system.sfc.startChart(). This also returns the unique identifier of the chart. And finally these last two lines set the SFC monitor components instance ID property to the charts id. This will pull the running chart into view on the component. My other window feedback popup is a popup window that the operator can use to make the choice between A or B. This window gets the chart ID passed into it as a root container parameter and it also has two buttons. Let's review the action perform script for the A button. Again, I'll right click into the scripting option.

[03:04] The script first gathers the chart ID root container property. Next, it makes use of the system.sfc.setVariable() function. This function allows us to set a variable on a running sfc. It expects at least three parameters, which are the charts instance id, the name of the variable and the value we want to assign. In this case, we are using the single character capital A. If we move over to the B button script, it looks exactly the same. However it sets the choice variable to a capital B. It's useful to note here that there is an additional scripting function that can serve the purpose of setting SFC variables and that is system.sfc.setVariables(), which is used in cases where you would want to set many variables at once. Now the piece that brings this combination of techniques together is under client event scripts, then message. If we remember back to the prompt action step, it calls system.util.sendMessage(). It's invoking this client message handler named feedback prompt, which receives the payload, which was a dictionary parameters that just had the chart ID in it.

[04:08] And this message handler simply opens the feedback popup and passes the chart ID of the chart that it received from the message payload to the feedback pop-up window. Let's go ahead and launch the project so we can see all these pieces in action from the client side. So we'll go ahead and start up our chart. And we didn't error out because we successfully sent it our client ID and now we're stuck here at the prompt step. So the prompt step executed. It invoked our client message handler, which opened our feedback pop-up window and now it's waiting. It's waiting for the choice to become either A or B. So we're going to go ahead and choose B. And you can see that B was chosen and there was a new variable in the chart scope called Choice whose value is B. And if we do start this all over again, you can see if you choose A, the A path will be followed. To summarize this lesson, we can use system.util.sendMessage() to call a client message handler, which can then interact with the client in some way.

[05:07] This may range from altering something on the window to requesting user input. The client can then call system.sfc.setVariable() to write back to the chart if necessary, allowing the chart to continue if it was waiting for the input. So that is how you can connect SFCs and client instances together.

You are editing this transcript.

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