Application of Zijin Bridge Real-time Database - Typical Cases of Writing Data to Relational Database by Function

The production information platform of a natural gas company is a platform for statistics and display of key production data. The three parts of the equipment key parameter qualification rate, equipment operation status, and vibration equipment alarm monitoring are provided by the Zijinqiao real-time database.

The functional requirements of the customer are this:

1. The qualification rate of the key parameters of the device. The upper and lower limits of the alarm shall be read from the specified relational database table. The technician shall modify the limits of the upper and lower limits of the alarm according to the need. The Zijin Bridge software calculates the key parameters of the device according to the limit value. The qualification rate is calculated and then stored in the table specified by the relational database.

2. The equipment operating status. The real-time value is read by the information platform in real time. Historical values ​​are periodically stored in the table specified by the relational database.

3, equipment vibration alarm monitoring, real-time values ​​read by the information platform in real time, do not need to store historical values.

The real-time data of equipment operation status and equipment vibration monitoring is through the open OPC Server interface, and the other party collects real-time data in real time. The qualification rate of the device's key parameters and the history of the equipment operating status are obtained through the Zijinqiao real-time database software and the historical data. Write to the SQL Server database and read it from the SQL Server as needed by the production information platform system.

The software version used by the system: Zijinqiao Real-time Database Software V6.5.

The screenshot of the function window is as follows. Since this window does not need to be displayed, no beautification is done:

Functional description of each part:

1- Alarm time statistic component, which is used to count the cumulative alarm time of the tag number to calculate the qualified rate.

2- Device status real-time report, real-time display device status value, through the script to store the value of the corresponding bit number to the database.

The 3-digit alarm upper and lower limit report reads the alarm limits of the parameter from the relational database.

4-Manually read the qualified rate alarm limit button, click to read the alarm limit of the relational database.

5- Check the report of data that has been written for the current day to view data already written in the database.

6-View device status/pass rate data button. Click the button to view the device status or qualification data for the most recent day.

The bottom part of the window, that is, 5, 6 blocks is actually not necessary for the function, but is convenient for developers to check whether the data in the remote database is successfully stored.

This article mainly introduces the function of the "qualification rate of key parameters of the device". The "equipment operation status" part is very similar, and the "equipment vibration monitoring" part does not need to store data to the relational database, so these two parts will not be described too much.

Next, begin to explain the key parameters pass rate function section:

1. A new alarm time statistic component is added in the window, named Alarm1, and the tag number that needs to be added is added to the component, and the bit number is set to use its own alarm limit value.

2. In the point configuration, a new 'report relation data source point' is added, and a relational database for reading data is connected.

3. A new free report is added in the window, the relational database is connected, and the new report relation data source point is connected, and the report is named. In this case, the report is named Fr1.

4, create a table template.

To use the predefined SQL functions of Zijinqiao Software to insert data into a relational database, first create a table in a relational database according to a fixed table structure. The SQL function cannot generate a table directly. Instead, it needs a given template to create a table according to the template. This requires the definition of a table template in advance.

The following figure is the table template to be used in the qualified rate data table. The table to be created has four fields, namely, 'date, bit number name, value, weight', and the corresponding field names are 'UpdateTime, TagName, TagValue, TagLevel', this field is required by the customer.


Qualification Rate Table Template

Create a table using the function SQLCreateTable(), where a window integer variable w_cID is defined for use by the SQL function. For the usage of the predefined SQL functions of the Zijinqiao real-time database, the reader is advised to check the help, which will not be described in detail here.

Once the data table is created, the table template is no longer needed. For this reason, the first data table was created using a button. After the creation, the button is deleted. Therefore, there is no script for creating a data table in the window.

5, create a binding table.

After the data table is created, the next step is to insert data into the table. To insert data into a relational database table, you need to use the 'binding table' of the Zijin Bridge real-time database. The field names in the binding table must be exactly the same as the fields in the table template. Otherwise, the data will fail when inserted.

In addition, four intermediate variables (the variable name part in the figure) need to be established, which correspond to the four fields of the data table and are used by the binding table. The specific usage will be introduced in detail in the later part of the script.

Qualification Rate Binding Table

6, the script.

As the Zijin Bridge real-time database version 6.5 software, the window cycle execution script cycle can not be greater than 15 minutes, so in order to achieve the desired function, define the following integer window variables: w_cID, w_t1, w_t2, w_t3, w_t4, w_TBegin, specifically used in It is explained in the following script.

Enter the window:

After entering the window, execute the following script. The first three lines are the time for w_t1, w_t2, w_t3 assigned to the next day zero point; the fifth line w_TBegin is assigned the time of the day zero, which is the start time for the alarm statistics component to perform statistics; the sixth line Connection database used by the data storage, because the connection character relates to customer information, so removed here, the reader can view the help on the Zijinqiao software built-in SQL function usage, which contains a detailed description of the connection database. W_t4 is assigned to the device status data storage script at 8:30 am on the following day, regardless of the qualified data storage.

W_t1 = LongTime(StrLeft(StrTime($Curtime,0),10) + " 00:00:00") + 86400;

W_t2 = w_t1;

W_t3 = w_t1;

W_t4 = LongTime(StrLeft(StrTime($Curtime,0),10) + " 08:30:00") + 86400;

w_TBegin = LongTime(StrLeft(StrTime($Curtime,0),10) + " 00:00:00");

SQLConnect (w_cID, "This part is a database server connection string, inconvenient to disclose");

Cycle execution:

First, the alarm limits for critical parameters are read from the relational database to the report Fr1 every day five minutes before midnight. Since the alarm limit is maintained by the craftsman, it may be modified according to the process requirements, so read it again before calculating the pass rate every day. The script is as follows:

If $Curtime >= w_t1-300 && $Curtime < w_t1-240 then

W_t1 = $Curtime + 86400;

#Fr1.SqlSelectCmd("select number, index level, lower limit, upper limit from TM_device key control parameters");

Delay(1500);

For i = 1 to #Fr1.RowCount()+1

#Local.SetDataStr(#Fr1.Txt(1,i)+".EU",#Fr1.Txt(2,i));

#Local.SetDataReal(#Fr1.Txt(1,i)+".EULO",#Fr1.Val(3,i));

#Local.SetDataReal(#Fr1.Txt(1,i)+".EUHI",#Fr1.Val(4,i));

# next

#Local.RegUpdate();

Endif

The first line of the script is to judge the execution time of the script in this section. When the system time is in the period from 5 minutes to 4 minutes before the zero point, the script execution starts.

The second line is the time to increase the value of the variable w_t1 by one day, so that the next execution time is the same time of the next day;

The third line is that the report Fr1 reads the alarm limit from the table of the relational database;

Line 4 is the delay time so that the report Fr1 can completely read the data in the table;

In the 5th to 9th loops, the alarm limits and weights in the report Fr1 are set to the corresponding bit numbers. The sixth line is to set the weights, the seventh line is to set the alarm lower limit, and the eighth line is to set the alarm limit;

In the tenth row, the information of the points after the sixth, seventh, and eighth rows are refreshed.

After reading the alarm limit, the next step is to calculate the pass rate of the tag number based on the alarm limit value. The following script is to judge that the system time is between 4 minutes and 3 minutes before zero. It starts to execute. It also increases the value of variable w_t2 by one day, which is the same as w_t1. Then it starts the statistics of the alarm time by the alarm component. The statistical time is One day, 86400 seconds.

If $Curtime >= w_t2-240 && $Curtime < w_t2-180 then

#w_t2 = w_t1;

#Alarm1.Start(w_TBegin,86400,1);

Endif

After the alarm statistics component completes the statistics, the statistical data needs to be extracted and then calculated. Then the calculation results are stored in the database table.

If $Curtime > w_t3-60 && $Curtime <= w_t3 then

W_t3 = w_t1;

For i = 0 to #Alarm1.GetTagCount()

Bind_TagValue = 1 - (#Alarm1.GetCellHi(0,i) + #Alarm1.GetCellLow(0,i))/86400;

Bind_TagName = #Alarm1.GetTag(i) + ".PV";

Bind_StrTime = StrTime($Curtime,1);

For j = 0 to #Fr1.RowCount()

If #Alarm1.GetTag(i) == #Fr1.Txt(1,j+1) then

Bind_TagLevel = #Fr1.Txt(2,j+1)

Endif

Next

SQLInsert(w_cID,"XHQ_HGL","XHQ_BindHGL");

Next

Endif

This part of the script is to write data to the database table.

The first line is still the judgment time. When the time reaches one minute before the zero point, the script is executed. First, the time variable w_t3 is increased by one day, which is the same as w_t1.

The 3rd to 13th loops calculate the value of all the bit numbers in the alarm component one by one, and then store them in the database table.

The fourth line sums up the upper limit alarm time and the lower alarm limit time of the ith column of the alarm component, then divides the time by one day to obtain the failure rate, and then subtracts the failure rate by 1 to obtain the qualification rate value. Variables used for binding tables;

Line 5 assigns the tag number of the alarm component i column to the binding table variable;

Line 6 is to assign the current time to the binding table variable;

Lines 7~11 are to find the weight of the current i-th column number in the report Fr1, and then assign it to the binding table variable;

On line 12, the four binding table variables have been assigned. This line uses the SQL function of Zijinqiao Software to insert the value of the binding table variable into the relational database table.

At this point, a cycle of the i-th column of the alarm component is completed until the qualified rate statistics of all the bit numbers in the alarm component are inserted into the data table, and the cycle is completed.

Exit window:

There is only one line of script here, which is to disconnect from the relational database when exiting the window.

SQLDisconnect(w_cID);

The key to the entire script is the periodic execution part. Here we use a little trick. Since the Zijin Bridge real-time database version 6.5, the period of the periodic execution script cannot be greater than 15 minutes, an integer variable is used here to pass the value and system of the variable. The current time is compared. Only when the conditions are met, the script can be executed. Otherwise, the script is not executed. This ensures that the script is executed only around the specified daily zero point.

In addition, in order to ensure that each part of the script can be completely executed and there is no time conflict, three different time variables are set and executed at non-intersecting times. In addition, this method does not affect the normal operation of other periodic scripts that need to be executed frequently.

to sum up:

In this example, the use of a report relationship data source point in combination with a free report reads the data in the relational database table. This has the advantage of being simple to operate and does not require writing too many scripts, but it cannot write data to the database table.

It also uses the predefined SQL functions of the Zijin Bridge real-time database software to write data to the relational database. The advantage of the SQL function is a full-featured, almost all operations on the relational database table, including query, insert, delete, build tables, delete tables, etc.; The disadvantage is that the combination of operations relatively free report and report relationship source data points to be tedious Some need to create table templates, binding tables, and manually write some scripts.

Plastic Earphone

Wired Earbuds,Earbuds With Mic,Wired Earphones With Mic,In-Ear Headphone With Mic

Guangzhou YISON Electron Technology Co., Limited , https://www.yisonearphone.com