Creating Memory, Expression, and Query Tags

Memory tags are simply values you use as setpoints or for storing information. Expression tags let you perform calculations based on other tags. Query tags execute a SQL query, whose result provides the tag value, and they can reference other tags to build dynamic queries.

Creating Memory Tags

Memory tags are simply values. You can use them as setpoints (that are not stored in the PLC) or just for storing extra information. The value is specified during configuration and is stored globally when written.

To create memory tags

  1. From Tag Browser, right-click on Tags or a folder of your choice and select New Tag > Memory Tag.

    images/download/attachments/6034154/image2015-4-7_16-56-2.png

  2. In the Tag Editor, type a Name (for example, Memory Tag), initial Value, and Data Type.

    images/download/attachments/6034154/image2015-4-7_16-56-41.png

  3. Click OK.

    That’s it! You now have a memory tag that you can read from or write to. This is just like having a global variable for your project.

Creating Expression Tags

Expression Tags are driven by an expression. The expression syntax is the same as for property bindings and allows mathematical operations, references to other tags, logic operations, and more. Expression Tags cannot be written to.

With expression tags you can do a special calculation based on other tags. In this way, you can do the calculation one time and view it on any window in your project.

To create an expression tag

  1. In the Tag Browser, right-click on Tags or a folder of your choice and select New Tag > Expression Tag.

    images/download/attachments/6034154/image2015-4-8_9-6-31.png

  2. In the Tag Editor, type FtoC Expression for Name and choose Float4 for Data Type.

  3. Click on the Expression tab on the left side of Tag Editor.

  4. Type in any expression using Ignition’s Expression Language. See Expression Functions in the Appendix for information on all expression operations and functions.

    Copy in the following expression:

    (5/9) * ({[~]Refrigeration/ambientTemp} - 32)

    images/download/attachments/6034154/image2015-4-8_9-7-35.png

    If you want to use a different tag, just replace the {[~]Refrigeration/ambientTemp} tag path with any Tag of your choice.

    Note that instead of typing the referenced tag path (in this example Refrigeration/ambientTemp), you can use the Tag icon on the right side of the Tag Editor > Expression window to select the tag path.

    images/download/attachments/6034154/image2015-4-8_9-8-43.png

  5. Click OK.

    You will see the value from your calculation on the Tag. Note that the Expression tags are evaluated at the rate the Scan Class is set to.

    images/download/attachments/6034154/image2015-4-8_9-9-23.png

    With an expression tag, you can also choose to write the value back to another OPC item. In the Tag Editor > Expressions, simply click the check box next to Write value back to OPC item? and select the tag you want to
    write to. Every time the value is calculated, the value gets written to the selected tag.

Creating Query Tags

Query Tags execute a SQL Query, whose result provides the value for the Tag. Like SQL binding in Vision, SQL Query Tags can reference other tags to build dynamic queries. Query Tags cannot be written to. The value of a SQL Query tag comes from the database through a SQL query.

To create a SQL query tag

  1. In Tag Bowser, right-click on Tags or a folder of your choice and select New Tag > Query Tag.

    images/download/attachments/6034154/image2015-4-8_8-56-0.png

  2. In the Tag Editor window, type Current Time for Name and choose DateTime for Data Type.

  3. Click on SQL Query tab on the left side of Tag Editor.

  4. Type in any SQL query you want.

    Note: The query must return a scalar result because the data type is not a dataset.

  5. In the drop-down list, select the database to run the query through, for example MySQL.

  6. Copy in the following query:

    SELECT CURRENT_TIMESTAMP

    images/download/attachments/6034154/QUERYTAG.PNG

    Query Type

    In certain circumstances you may want to update the database instead of querying it for data. The query tag will accept an update query and update the target data source. The value attribute of the tag becomes the number of rows affected by the update query.

    The data source refers to the default data source of the tag provider as opposed to the default data source of the project.

    In the Gateway Configure Section, go to Tags > Realtime and edit the appropriate tag provider. Set the default database connection that this tag provider will use for its query tags.

  7. Click OK.

    You will see the value from your SQL query on the Current Time Tag.

    images/download/attachments/6034154/image2015-4-8_8-57-57.png