FactoryTalk Optix

Events and Methods in FactoryTalk Optix

In FactoryTalk Optix:

  • An event is a thing that happens
  • A method, or command, is an action that’s taken.

Events and methods can be paired to create application logic. For example, when a button is clicked, a variable increments.

In this video, I’ll show you how to work with events and methods in FactoryTalk Optix. We’ll cover the basics of using predefined events to call methods and also look at more advanced topics like custom events and external events.

Let’s get started by looking at predefined events and global methods.

Setup

In FactoryTalk Optix, I have created a new project and added two screens and a navigation panel to the project. On the first screen, I have added a button, a spin box, and a rectangle.

The value of the spin box is linked to a variable, which I have creatively named Variable1.

Initial Project

Events and Commands

In Optix, certain objects have predefined events. These are available at the bottom of the properties pane.

A button has the following predefined events:

  • MouseClick, which fires when the button is clicked,
  • MouseDown, which fires when the button is pressed, and
  • MouseUp, which fires when the button is released
Predefined Events

Shapes like rectangles also have events. These events only fire if the Hit Test Visible property of the object is set to True. When this property is set to False, clicks pass through the shape to objects inside the shape.

Hit Test Visible

To add an event listener to an event, you can click the plus icon beside the name of the event.

Add an Event Listener

When you click the plus icon, a menu opens that displays a list of all of the available commands that can be invoked by this event.

Global Commands

The Commands folder contains global commands that are not specific to an object. This folder is divided into subfolders.

The Variable Commands subfolder contains commands that are used to change the values of variables in the project.

Variable Commands

The Core Commands folder contains commands that let you interact with the runtime like closing or restarting the application.

Core Commands

The Alarm Commands folder contains commands related to alarms such as Acknowledge All and Confirm All.

Alarm Commands

Finally, the UI Commands folder contains commands that let you interact with the application’s user interface by displaying a virtual keyboard or opening a dialog box.

UI Commands

Local Commands

Some objects also expose local commands that you can use to interact with them. For example, the Navigation Panel has methods that can be used to change the current panel by tab index or name.

Local Methods

Using Commands

In this example, I will use the Increment Value command to increment the value of Variable1 so I select the Increment Value command and click Select.

Select Command

The command is now listed under the MouseClick event in the button’s properties:

Method Added

Command Arguments

As you can see here, the Increment Value command has some Input Arguments. Input Arguments provide a way to pass data to a command when it is called.

In this case, the VariableToModify is Variable 1, and the Delta is 1.

Method Arguments

Commands can also have Output Arguments. Output Arguments are pieces of data that are returned after the command has executed.

Test

When I run the application now, I can see that the value of Variable is incremented by 1 every time I click on the button.

Test

Multiple Commands

You can add multiple commands to an event.

When an event has multiple commands, the commands are executed in the order that they are listed.

Custom Events

As well as default events, objects in Optix can have custom events.

To create a custom event, you can right-click on any property on an object and create an event from the New menu.

Custom Event

There are three different types of events that are available to add:

A Changed Event is fired when the property’s value is changed.

A Transitioned Event is fired when the property’s value meets a certain condition. The conditions can be equal to, not equal to, greater than, greater than or equal to, less than, or less than or equal to.

Transitioned Event

Finally, a Range Transitioned Event is fired when the property’s value goes into or leaves an inclusive or exclusive range.

Range Transitioned Event

What’s pretty interesting is that you can create custom events for variables as well as properties. So, in the properties for Variable1, I can add a Transitioned Event.

Custom Event on Variable

In this case, the event fires when the value of Variable1 is greater than 10.

Configured Event

I can invoke methods when this event fires by using the plus icon. You should notice that the list of available commands is smaller than what we had seen previously. That’s because the variable is not part of the UI so the local methods related to the Navigation Panel aren’t available.

Available Commands

External Events

If we wanted this event to trigger a local method to change screen, we could add an External Event to the Navigation Panel for this event.

To do that, I click on the plus icon in the Events section of the Navigation Panel’s properties and select the event that I want to listen for.

Add an External Event

Now, I can use this event to invoke the Change Panel by Tab Index method of the Navigation Panel.

Command for External Event

When I run the application, I see that the screen switches when the value of Variable1 exceeds 10.

Test

Wrap Up

In this tutorial, I have shown you how to work with events and methods in FactoryTalk Optix. By now, you should be comfortable with:

  • Adding event listeners,
  • Invoking methods when events are fired,
  • Adding custom events to objects and variables,
  • Adding external events to objects

One thing to note is that although you can do something in Optix, it doesn’t mean you should. I try to avoid adding events directly to variables or adding external events to objects because they can be very hard to trace and debug.

In my next tutorial, I’ll do a deep dive into the local methods that are available in the Navigation Panel object and look at how you can use these methods to build an interesting navigation system in an Optix project. If that sounds interesting, make sure to subscribe to the mailing list to be notified when its published.

Industrial Automation Tutorials

© All Rights Reserved.