Tuesday, January 29, 2013

Dynamically add SQLTags from Ignition Client

I am finding more and more customers that want to create completely templated projects in Ignition where the configuration comes from a SQL database. They usually want to allow the customer to make configuration changes in the client. In order to achieve that, you need a way to dynamically add/edit/delete devices and tags. Ignition doesn't give you functions to do that out of the box.

Now you can! I have written a special module that exposes scripting functions to manipulate database connections, devices, and tags. It is called the "IA Labs Scripting Module." It is a 100% free module that you can download and try out today.

Simply click on the link below to download the module. You can install it in the Ignition Gateway configuration page under Configuration > Modules.

IA Labs Scripting-module_1.1.0.modl

Right now the only documentation for the module is on our online forum located here:


It lists out all of the functions and how to use them. Here is a list of the functions:

Database Functions

Device Functions
system.device.refreshBrowse - Only for AB controllers

Tag Functions

The most popular function is the system.tag.addTag function that adds new SQLTags to Ignition. I get a lot of questions on how to use the function so I thought it would be best to post a few examples.

The first example is very basic, how to add an OPC tag:

system.tag.addTag(parentPath="Folder", name="TagName", tagType="OPC", dataType="Int4", attributes={"OPCServer":"Ignition OPC-UA", "OPCItemPath":"[DeviceName]N7:0"})

Most of the parameters are self explanatory except for the attributes. The attributes is a dictionary of key/value pairs for all the configuration items on a tag. All of the possible attributes are listed in the forum (use the link above). Let's say that I want to add the same tag but store history on the tag as well, the function would look like this:

system.tag.addTag(parentPath="Folder", name="TagName", tagType="OPC", dataType="Int4", attributes={"OPCServer":"Ignition OPC-UA", "OPCItemPath":"[DeviceName]N7:0", "HistoryEnabled":1, "HistoricalScanclass " : "Default"})

You can see two new attributes have been added, HistoryEnabled and HistoricalScanClass. Not only can you add an OPC tag but you can also add a UDT instance:

system.tag.addTag(parentPath="Folder", name="UDTInstanceName", tagType="UDT_INST", attributes={"UDTParentType":"NameOfUDT"}, parameters={"ParamName":"ParamValue"})

That will add a new UDT instance of the UDT named "NameOfUDT". Since UDTs have parameters that must be filled out you can specify another argument called parameters that is also a dictionary of key/value pairs. My UDT had a property called "ParamName" and I set it to the value "ParamValue." 

Next, let's show how to add a tag with an alarm. We just need to specify all of the alarm properties as attributes, like this:

system.tag.addTag(parentPath="", name="N7_0", tagType="OPC", dataType="Int4", attributes={"OPCServer":"Ignition OPC-UA Server", "OPCItemPath":"[MLX]N7:0", "AlertMode":1, "AlertDisplayPath":"Machine A", "AlertNotes":"Notes for the alert", "AlertAckMode":2}, alarmList="Out of Range;Medium;1.0;1.0;0;;;0.0;SEC$")

The only tricky part is coming up with the alarmList attribute value. If you export a tag in the Ignition designer to a CSV file you will see the "AlarmStates" column. You can copy and paste the alarm states value to the addTag function.

Lastly, let's add an expression tag:

system.tag.addTag(parentPath="Folder", name="ExpressionTagName", tagType="DB", dataType="Int4", attributes={"ExpressionType":1, "Expression":"{Path/To/SomeTag} * {Path/To/AnotherTag}"})

The tag is a DB type with two attributes, ExpressionType and Expression. 

There are many other functions you can play around with in this module. I hope to add new functions soon to manipulate OPC servers and transaction groups dynamically. 

If you have any questions or feedback on the module, feel free to post to our online forum.

Wednesday, January 2, 2013

Ignition Designer: Dependencies and Spotlights

Ignition's designer has a lot of features that can make designing new projects easier. Two such features are dependencies and spotlights. We don't really talk about these features in the documentation so I guess you can call them hidden features or gems.

Designer Dependencies

When you are designing screens in Ignition you are constantly linking (binding) properties to tags and other properties on the same window. Each time you bind a property to something else you are setting up a dependency.

Let's look at a small example. Add a tank component and a slider component to a window. Bind the tank's value property to the slider's value property through a "Property" binding. By doing that, the tank is now dependent on the slider. If you try to delete the slider component Ignition won't let you saying "Cannot Delete. Non-Selected component Root Container.Cylindrical Tank depends on selected component Root Container.Slider."

People always ask, "Is there a way I can see who is linked to who?" Yes, the designer has a built-in feature to show all of the dependencies. Just simply click on View > Dependencies > Show All from the file menu in the designer. It will draw arrows from components to other components to illustrate such dependencies.

The direction of the arrow is important. In our example above, the arrow is drawn from the slider to the tank. The arrow shows how data flows. When the slider changes the tank will update. So, if the arrow is going away from the component it means those components are linked to it.

This is an extremely important feature when designing templates or indirect popup windows. Components inside of templates are always linked in some way to the template parameters. That way the template can dynamically change. With indirect popup windows you pass in a value that is used in all of the component property bindings.

In both cases, if you turn on the dependencies you can easily see if one of the components is not linked to the template parameter or the value passed in. If you don't see line drawn to the center something may be wrong.

Pressure label doesn't have an arrow because it is not bound
using the template parameter. In this case that is expected.


Designer Spotlights

Spotlights are another great feature of the designer. Spotlights allow you to see invisible components, components that have bindings, and components that have scripting on the window by painting a box around the component.

There are a lot of situations where you will have invisible components in the designer. It can be challenging to figure out if there are any and where they are. If you turn on the invisible spotlight, it is easy to pinpoint where they are. Click on View > Spotlights > Invisible to turn the spotlight on. The image below shows that there are two components invisible (the purple outline) in this window.

The binding and scripting spotlights are the same idea but show which components have binding or scripting configured.

If you turn on both features dependencies and spotlights, you will get a good idea of how a window is configured.