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

Supplemental Videos


Learn how to use retargeting to switch between projects on the fly.

Video recorded using: Ignition 8.1


(open in window)

[00:00] In this lesson, we're going to discuss and demonstrate the idea of retargeting. Retargeting is really one of the most powerful capabilities of the Vision module, but it's one that a lot of people are not aware of. Retargeting means swapping between running Vision applications, potentially in different gateways on the same running Vision Client. Using retargeting, you can break up your larger application into separate projects by logical grouping on a single gateway, which can be great for maintenance. But it also lets you create a seamless SCADA system across gateways by having clients retarget amongst multiple gateways, even if cross WANs into different facilities. Retargeting is a very powerful capability, but one that's achieved through some fairly simple scripting. So let's dive into it. On this busy desktop, we have two separate Ignition projects side by side, each one a clone of the other.

[01:04] Each one is simply displaying a current random tag value to an LED display. The tag values used are shown on these two random double tags. And we can see that each one is distinct. Project A uses double one and Project B uses double two. Then each project has a button allowing us to swap between the executing projects in a client, or in other words, retarget from one project to the other. Let's see this run in a client window and see what it looks like. For starters, we'll go down to our taskbar and restore this minimized client. As you can see, it's going to start out with Project A. Then we'll log in with some user credentials. How about as an admin user? And we can see that we're now in Project A. Then if we click on the retarget button we now find ourselves over in Project B.

[02:07] And if we click on the retarget button again we now find ourselves back in Project A. We've now retargeted between the two running projects and we can go back and forth at will now, as we'll show right here. You may have noticed however that we didn't have to log into Project B for the initial retargeting or either project for any subsequent retargeting. That's because projects A and B both share the same user profile in the gateway. The retargeting feature seamlessly forwards our credentials for logging into Project A over to Project B. Of course, if those credentials didn't match or if Project B was using a different authentication profile the retargeting would make you log back in to the target project. Next, let's our attention back to the two designers to see how all of this is done.

[03:03] For starters, let's open the scripting windows for each of the buttons, like so. And on line two we can see that simple basic retargeting can be done with one single line of script. We'll use system.util.retarget along with the name of the target window. And obviously, the other one will be very similar with a different window name. Now this works simply because we had a very plain simple scenario. Of course, if we were trying to do something a bit more elaborate, such as retargeting to a project on a different gateway, other optional parameters would come into play. For example, we might need to specify a different gateway address, so we might need to specify an alternate IP address and port number combo. Or we might wanna specify an optional sequence of startup windows. Normally when you retarget to a new project, it will start up the project's standard set of startup windows. But if you give it another list of startup windows as input, those windows will be opened instead.

[04:03] More details on these options are given in the user manual, along with some good examples. However, let's next consider one specific enhanced example. The case of passing some arbitrary information over to the target project. For example, let's say that when we retarget to the other project we want to pass along the current LED tag value from this project over to the target project. So for starters in each project, we will begin by disabling the simple starting target retarget example, like so. And we'll enable the parameter passing example. In each case, we're simply highlighting the code of interest and using Control + slash to enable or disable the code of interest. And then we will apply both sets of changes and we will push out the changes out to both running projects on our common gateway in this case.

[05:09] So to pass the data over to the other project we'll make use of dictionary key value pairs. Here we have a parameter called TestParam whose value will get set to the current value of LED component as has been extracted on this prior line. And note that also here we have to use positional notation with the optional input params, since this is actually the third possible input per the function's interface. So on this A side, we see how to obtain and pass the desired value on a retarget. The value is going to get transmitted using global scripting variables. So next, let's see how to consume that value on the other side. To do this, we need to add an event script at the window level for system B, not at its root container level, since it has a Vision window open target event.

[06:11] We want these steps to be fired upon the first opening of the window upon a retarget, so that's why they are here. I'll move this down outta the way a little bit. So in the Vision window open event script we opened the globals dictionary using system.util.getGlobals, like so. And to avoid any first time startup problems, let's first make sure that there is some global data to work with. Which is why this if on line seven. If we haven't retargeted yet to this application maybe there won't be any global data just yet to drill down into. Next, on line eight, let's also check that there is in fact a global var called TestParam. Assuming that there is, we will index by name to obtain it. Then we'll round it to two decimal places to match the LED display.

[07:06] And now we have the past value on hand rounded. Then we need some place to display this data. So in our project browser, that will be the purpose of this label component, which at the moment is invisible to the user because it's not displaying any text on it yet. So next, back on line 13, we'll obtain the component we're after. Here, event.source represents the window which fired this event script. Then, .rootContainer is the container which holds the component we want, which we can get using getComponent and the component name of interest. So now that we have the component name on line 14, we will update its text property using some labeling text and the string equivalent of the numerical global value. So all of this taken together when the window is opened will pull and display the global parameter we sent from Project A over to Project B through the retargeting mechanism.

[08:13] So finally, let's see the end result of the parameter passing we've just described. So we will save all our changes, and we'll make sure to push those changes out to the gateway. And let's display the other designer. And then we will restore our client window from the taskbar. And since we've got some project updates available, we'll accept those. So then when we retarget to Project A, when the LED shows 61.46, we see that we've retargeted over to Project B with a value 61.46. And we can go back to the A project when the value is 20.03. And we pass that value back over to the A project side.

[09:12] So in this lesson we've seen how simple it is to do a simple retarget from one client application to another. And we've also seen how to pass parameters back and forth between running client applications using retargeting.

You are editing this transcript.

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