Unpacking the NiagaraAX Expr Object

Fair warning, things get technical here. But if you’ve been working on the Niagara platform and have wondered about the little Expr object, a versatile yet under-used tool, then get ready to take notes. This break-down is thanks to Eddie Turner, who works in our Tech Support department. His wizardry with Niagara is just one of the reasons he answers all of your program questions on the daily.

The Expr object, found in the kitControl palette util folder (and in kitControl’s logic folder as ExprLogic and the Math folder as ExprMath) is a nifty object that I see replacing many of the uses for program objects or other complex application logic runs.

From the Help files for the Expr object, here’s how it works:

(AX-3.6 and later) BqlExprComponent (Expr) provides the means to create custom math and logic operations based upon manually-added slots and one or more BQL expression statements. Slots can be various baja types such as primitives Double, Float, Integer, Boolean, or String, or status types such as StatusBoolean, StatusNumeric, and so on. Slots are used either as inputs, or as one or more outputs. BQL expressions are entered in the component’s “Expr” property.

The scariest part of that description is the repeated use of the acronym BQL. I’m no BQL expert but even just in modifying the sample query in the object itself, I have found Expr to be very helpful.

Where I see the true power of this object is in reducing the number of function blocks needed to accomplish a task, making it so I only have to run the math or logic in just one object instance.

Let’s talk real world applications, though. Say the engineer has created a complex formula that takes in live values and mushes them up with some constants to present a result. What do you do?

I’ll make up a meaningless example here, just to walk you through the process. (Notice I added a slot called “inE” – you can add and remove slots, just be careful about their type and remember that you have to access them in the query by name; the addition or subtraction of slots is done on the object’s slot sheet.)

Here’s my fancy made-up equation in the object:

inA + 1 + inB + 2 + inC + 3 + inD + 7 + inE as ‘out’

Here’s the answer on the wiresheet…

NiagaraAX Expr Object_Graphic2

How about combining numbers and Booleans? Here’s the expression (inD and inE and out have been replaced as Boolean slots):

(inA + inB + inC = 3) or (inD and inE) as ‘out’

Here are some caps of the results:

Neither condition is true, out equals false…

NiagaraAX Expr Object_Graphic2

Numeric condition is true, out equals true…

NiagaraAX Expr Object_Graphic3

Boolean condition is true, out equals true…

 NiagaraAX Expr Object_Graphic4

Even with these simple samples, you can image how much application logic can be replaced by this one object. So, start playing around with your own made-up situations and then find real-world ones to apply it to. And if you have questions along the way, remember we’re here for you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s