Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

In FactoryStudio, an advanced SCADA and HMI software, it is possible to establish a robust and secure connection with a PostgreSQL database using the TagHistorian feature. The TagHistorian allows for the collection and storage of tag data, providing a real-time, accurate history of your process dataYou can use a PostgreSQL database with the Tag Historian feature. The steps to achieve this involve renaming databases, creating and testing the PostgreSQL connection, configuring tags and tasks, and writing specific queries for select, insert, update, and delete operations. By effectively using this feature, users can send values to the PostgreSQL database and successfully execute different queries, leading to an efficient and accurate real-time data management system:

  1. Rename Databases.
  2. Create and Test the PostgreSQL Connection.
  3. Configure Tags and Tasks.
  4. Write Specific Queries for Select, Insert, Update, and Delete Operations.

On this page:

Table of Contents
maxLevel3


Configuration PostgreSQL

via TagHistorian

In this example, we present the configuration of Postgre using TagHistorian.

First, you can access Datasets>DBs and need to rename the SQLite database "TagHistorian" to "TagHistorian2" or another name.

?Image Removed

Now you can access Datasets>DBs, select the PostgreSQL Data Provider option and click on "Create new..." and create the Postgre with the name TagHistorian.

Image Removed

In the ConnectionString column, you can configure the Server parameter with the IP of the Postgre Server, the Port, and the name of the Database configured on the Postgre server.

Don't forget to configure the LogonName and LogonPassword column.

Note

Note: to modify the password column, you need to switch to Administrator.

Image Removed

Click Test and check the connection with the Postgre Server.

In Datasets>Queries, some queries were created as shown in the image below. We use Select, Insert, Delete, and Update in this example.

Image Removed

Now, in Tags>Objects, it is possible to create some Tags to use in this example. The Integer01, Integer02, and Integer03 are Tags that we will use to send values to the Postgre DB.

The "TriggerUpdate", "TriggerSelect", "TriggerInsert" and "TriggerDelete" are used to trigger some task scripts that we will create in the next steps.

Via Tag Historian

Follow the steps below to configure PostgreSQL using Tag Historian.

  1. Access Datasets > DBs.
  2. Rename the SQLite database TagHistorian to TagHistorian2 or any other name. You should rename it because the system will use the TagHistorian name to configure the Postgre SQL.
  3. In DBs, click the plus icon to create a new Database Connection.
  4. In the Name field, enter TagHistorian.
  5. Choose PostgreSQL Data Provider as the Provider for the database.
  6. Click OK.
    Image Added
  7. In the data grid, click the Connection String column of the newly created row.
  8. Configure the connection. For the Server field, enter the IP address of the PostgreSQL server. In addition, you need to provide the Port, Database name, and User ID. After filling in all fields, click Test to ensure the connection with the PostgreSQL server is working correctly.

    Image Added




Configuration Example

This example presents necessary steps to connect and start using a PostgreSQL DB. To run the example, it is necessary to created objects in other modules of the platform. Below you find a list of modules used and the necessary configurations.

In Datasets > Queries you need to create the queries below. Access Datasets Queries to learn how to configure queries.

  • QuerySelect
  • QueryInsert
  • QueryDelete
  • QueryUpdate

In Unified Namespace → Tags, we created some tags to save values in the database. To learn how to create and configure tags, access Unified Namespace. The created tags are described below:

  • Integer01, Integer02, and Integer03 are used to send values to the PostgreSQL database.
  • TriggerUpdate, TriggerSelect, TriggerInsert, and TriggerDelete are used to trigger script tasks created for the example.
  • QuerySelect
The tag "QuerySelect"
  • is used to receive the result of the Select query.

Image Removed

In Tags>Historian, it is necessary to configure In Historian → Historian Tags, configure the Integer01, Integer02, and Integer03 tags to Table1. Remember that the PostgreSQL connection must be configured to work with Tag Historian, Table1 which is standard and is configured to use PostgreSQL.

Image Removed

Now, in Scripts>Tasks you can create some tasks to In addition to the above configuration, you need to access Scripts → Tasks and create tasks for Select, Delete, Update, and Insert, and configure configuring the Trigger column with the marks created before.

Image Removed

The scripts areearlier. Below, you will find all required scripts:

  • Select Query

    Code Block
    languagec#
    @Tag.QuerySelect = @Dataset.Quey.QuerySelect.SelectCommand();
    @Info.Trace("Select OK:

Image Removed

Insert query:
Image Removed

Update Query:

Image Removed

Delete query:

Image Removed

  • " + @Tag.QuerySelect);


  • Insert Query

    Code Block
    languagec#
    int i = @Dataset.Query.QueryInsert.ExecuteCommand();
    @Info.Trace("Insert OK:" + i);


  • Update Query

    Code Block
    languagec#
    int i = @Dataset.Query.QueryUpdate.ExecuteCommand();
    @Info.Trace("Update OK:" + i);


  • Delete query:

    Code Block
    languagec#
    int i = @Dataset.Query.QueryDelete.ExecuteCommand();
    @Info.Trace("Delete OK:" + i);


After finishing the configuration and creating the scripts, you We can run the project and give some provide different values to the Tags . thus, within pgAdmin 4 we can see that Table 1 was created with values that were given.

Image Removed

Thus, we trigger tasks through Trigger Tags, all Queries were successfully performed.

Image Removed

Our Table within Postgre is updated with the Queries we created before.

created. Thus, if you access the PostgreSQL Server, you can access the created Table1. You can also check that all values you provided are within Table1 due to the execution of previously created queries.

Image AddedImage Removed



In this section...

Page Tree
root@parent
spacesV10