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

LESSON LIST

Autoplay Off

Supplemental Videos

LESSON

Startup and Shutdown Scripts

Description

Learn how to configure basic scripts when Perspective sessions are started or stopped.

Video recorded using: Ignition 8.0

Transcript

(open in window)

[00:00] In Perspective, we have the option of configuring scripts that run on a gateway whenever a session starts or ends. These scripts have a variety of use cases. Maybe we want to log an entry in a database, indicating that a session was launched or closed, or maybe we want to pass a value into our newly opened session. To configure a Session Event from the designer, we are going to go into our project browser and find session events under Perspective, and then we're going to double click. And now we can select a Session Event script to configure. So if I wanted to configure an On-Shutdown event, I can click shutdown. And if I wanted to configure an On-Startup event, I could click Startup. The structure of these two events are very similar. Both scripts simply take a session object as a parameter and allow you to configure any script that you like. To see the structure of this session object, I'm going to click cancel and then I'm going to come down and click the gear icon here. And on the right hand side, you can see all of our session's properties.

[01:04] All of these properties will be available from the session object. Noticeably, this includes any custom properties we configured. I, for an example, configured a sessionNum property. Now, I have already configure a view that uses this custom property called View. And if I click on my label here, and I drill into the binding of this text property, we can see that I'm referencing my session known property in this expression binding. My goal from here is just to use a Session Startup script to populate the custom property. So that it will be feed through to this view. To do that, I am going to cancel out of this. And I'm going to go back into my Session Events, and I am going to configure a very basic Session Startup script. Session .custom .sessionNum = 5 To see this in action, I am going to click okay and I'm going to save the project. And then I'm going to run a session by clicking on tools. Coming down and clicking launch Perspective and launch Session.

[02:11] And as we can see the session started with the parameter value I specified.

You are editing this transcript.

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