0% found this document useful (0 votes)
555 views

Weintek To MySQL Database Server

This document discusses how to configure a Weintek HMI to connect to a MySQL database server. It covers setting up the database server object to connect to the MySQL server, configuring SQL Sync to transfer historical data from the HMI to the MySQL server, and configuring SQL Query objects to retrieve data from tables in the MySQL server and populate tags on the HMI. The document provides step-by-step instructions and screenshots to illustrate the configuration process in Easybuilder Pro.

Uploaded by

Alberto Molina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
555 views

Weintek To MySQL Database Server

This document discusses how to configure a Weintek HMI to connect to a MySQL database server. It covers setting up the database server object to connect to the MySQL server, configuring SQL Sync to transfer historical data from the HMI to the MySQL server, and configuring SQL Query objects to retrieve data from tables in the MySQL server and populate tags on the HMI. The document provides step-by-step instructions and screenshots to illustrate the configuration process in Easybuilder Pro.

Uploaded by

Alberto Molina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Weintek HMI to MySQL Database Server

Weintek USA, Inc. Rev. APR 28, 2020


www.WeintekUSA.com
(425) 488-1100

Weintek HMI to MySQL Database Server


Introduction: This document discusses how to configure the SQL Sync and SQL Query
features in Easybuilder Pro. The SQL Query feature in Weintek HMIs allow a user to
query a SQL database and populate tags with the queried values. Data can vary from
recipe information to other key production information. Historical data collected on an
HMI such as “Data Sampling” can also be transferred to a MySQL server. This document
was designed for those who have a basic understanding of MySQL servers and focuses
on how to program SQL functionalities in Easybuilder Pro.

Equipment & Software:

A) cMT3090 (cMT Series HMI)


B) MySQL Server X64
C) MySQL Workbench X64

Note:

1.If you download MySQL Server 8.0 or use a later version for installation,
please select “Use Legacy Authentication Method (Retain MYSQL 5.x
Compatibility)” on the Authentication Method menu during the installation.

2. The Weintek HMI requires a user credential to log in to your MySQL server. To create
a user account within MySQL server using MySQL Workbench, please follow the
steps below:

I. Log in to your MySQL Workbench with your root account.


II. Go to the Users and Privileges tab.
III. Create a user account on the Login tab. After entering the user
credentials, click on the [Apply] button.
IV. On the Administrator Roles tab, select all the roles as well as
privileges. Then click on the [Apply] button.

Page 1 of 26
Weintek HMI to MySQL Database Server

3. The Weintek HMI requires a database in your MySQL server to store data or query
the database. To create a database using MySQL Workbench, please follow the steps
below:

I. Log in to your MySQL Workbench with your root account.


II. Click the [Create a new schema in the connected server] button on the
toolbar.
III. Give a name to the database and then click on the [Apply] button.
IV. The MySQL Workbench will prompt you to review the SQL Script s. Click
the [Apply] button.
V. Click on the [Finish] button on the next dialog.

Contents:

Chapter 1. Configuration of Database Server Object..…………………………………………………………3

Chapter 2. Configuration of SQL Sync.…………………………………………………………………………………6

Chapter 3. Configuration of SQL Query Using Basic Mode……………….....................................13

Chapter 4. Configuration of SQL Query Using Advanced Mode ………………………………………….16

Appendix A………………………………………………………………………………………………………………………...22

Appendix B………………………………………………………………………………………………………………….……..24

Appendix C…………………………………………………………………………………………………………………………25

Page 2 of 26
Weintek HMI to MySQL Database Server

Chapter 1. Configuration of Database Server Object

This object allows a Weintek HMI to connect to your MySQL database server and access
the specified database. You must establish a MySQL connection before following the
steps in Chapter 2, Chapter 3, or Chapter 4.

1. Launch Easybuilder pro and open your project. Go to the [Data/History] tab »
[Database Server].

2.Click on the [New] button to add a database server.

On the [General] tab, enter the IP address, port number, and a user account for your
MySQL server. Database name depends on what database you want to use for SQL Sync
or SQL Query.

3.On the [TLS/SSL] tab, you can enable TLS/SSL encryption and server verification when
using MySQL as your server. This feature is available in Easybuilder Pro v6.04.01.250 or
greater.

Page 3 of 26
Weintek HMI to MySQL Database Server

Version: supports TLS1.0, 1.1, and 1.2.

Server verification: If selected, please import your CA certificate.

4.On the [Status/Control] tab, define the Status address to display the connection status
on the HMI screen. You can define a Control address if enabled to change the following
server parameters on the HMI screen during runtime.

Page 4 of 26
Weintek HMI to MySQL Database Server

5.Create the following objects on the editing area. These objects are used to monitor
and control the MySQL server connection.

Once the Weintek HMI succeeds in connecting to the MySQL server, the “Connected”
message will be displayed in the Status address.

Status: displays the connection status

Value Description
0 Not attempting to connect to the server
1 Failed to connect to the server
2 Connected to the server

Error: displays the error code

Value Description
0 No error
1 Unknown error
2 Failed to connect to database
3 Database blocks the unauthorized connection
4 Incorrect database name
5 Invalid domain name

Page 5 of 26
Weintek HMI to MySQL Database Server

Chapter 2. Configuration of SQL Sync

The Sync to database option will be available in the Data Sampling and the Event Log
after you finish the steps in Chapter 1.

Data Sampling

Follow these steps after you have created your data logs in Data Sampling.

1.Go to the [Data/History] tab » [Data sampling].

2. Under History file select [Enable] and then select the [Sync to database] option. Once
configured, select a database server to store your historical data.

Note: SQL sync. does NOT support “Customized file handling.” You must select “All
records in one file.”

3.You can enable a Control address to trigger the following actions by issuing the
corresponding commands. The HMI will perform auto synchronization at the specified
time interval if Auto sync. Periodically is enabled.

Command Description
Number
1 This command will clear all logged records in the HMI flash memory.
2 This command will synchronize the historical data to the MySQL server.
3 This command will synchronize the historical data to the MySQL server
and then clear all logged records in the HMI flash memory.

For more information about the Control address, please refer to the Easybuilder Pro
user manual.

Page 6 of 26
Weintek HMI to MySQL Database Server

Screen Shot of the Final Project

Page 7 of 26
Weintek HMI to MySQL Database Server

Testing – Click the [Sync] button, which is used to issue command #2 via a Set Word
object. If the sync succeeds, the following three tables will be generated in your
database.

Page 8 of 26
Weintek HMI to MySQL Database Server

Note: The HMI will transfer the original data logs to the MySQL server. Please use
SELECT statement to get a table that contains specific organized data.

Page 9 of 26
Weintek HMI to MySQL Database Server

Event Log

Configuring the SQL Sync for the Event Log is similar to the Data Sampling section.
Follow these steps after you have created your event logs in Event Log(Alarm).

1.Go to the [Data/History] tab » [Event Log].

2. Under History file select [Enable] and then select the [Sync to database] option. Once
configured, select a database server to store your historical data.

3.You can enable a Control address to trigger the following actions by issuing the
corresponding commands. The HMI will perform auto synchronization at the specified
time interval if Auto sync. Periodically is enabled.

Command Description
Number
1 This command will clear all logged records in the HMI flash memory.
2 This command will synchronize the historical data to the MySQL server.
3 This command will synchronize the historical data to the MySQL server
and then clear all logged records in the HMI flash memory.

For more information about the Control address, please refer to the Easybuilder Pro
user manual.

Page 10 of 26
Weintek HMI to MySQL Database Server

Page 11 of 26
Weintek HMI to MySQL Database Server

Note: The HMI will transfer the original event logs to the MySQL server. Please use
SELECT statement to get a table that contains specific organized data.

Event table displays all events detected by the HMI.

You can look up the event messages in the event log table.

Page 12 of 26
Weintek HMI to MySQL Database Server

Chapter 3. Configuration of SQL Query Using Basic Mode

Before you configure a SQL Query object to query your MySQL server, you will need to
finish the steps in Chapter 1.

A database may contain several tables as shown below. In this example, the HMI will
pull out of data from PRODUCTION_DATA table.

1. Go to the [Data/History] tab » [SQL Query].


2. Click on the [New] button to create a new query.
3. On the [General] tab,
Database: Select the database server created in the MySQL server.
Table name: Enter the table name created in the MySQL server.
Schema: Define a register for the Schema (column) of the table.

Click on the [New] button to add the columns of the table or click on [Import
from server] to import the column’s information from the MySQL server.

Page 13 of 26
Weintek HMI to MySQL Database Server

Based on the data format in your MySQL server, select the correct data type for
each column under the [Address format] column. If the column is string data,
enter the number of words under the [Word count] column.

4. On the [Command] tab, define a register for the Control Address. The following
parameters will populate the sequential registers. During runtime, you can query
the MySQL server by entering a Command ID into the Command ID register,
which is LW-100 in this case.
Create (Issuing Command number 1), Read (Issuing Command number 2)
Update (Issuing Command number 3), and Delete (Issuing Command number 4)

Page 14 of 26
Weintek HMI to MySQL Database Server

5. You can create another SQL query object to query other tables if needed.

6. Create four Set Word objects on the editing area to issue the Commands during
runtime.

7. Go to the [Data/History] tab and create a [SQL Query Result Viewer] object on
the editing area. Once the HMI succeeds in performing a Select command, the
result will be displayed in the SQL Query Result Viewer object.

SQL Query: Select an existing SQL Query object.

Filter enabled: Allows you to enter keywords into this object during runtime to
search for a specific record.

Page 15 of 26
Weintek HMI to MySQL Database Server

Chapter 4. Configuration of SQL Query Using Advanced Mode

Before you configure a SQL Query object to query your MySQL server, you will need to finish the
steps in Chapter 1. In advanced mode, you can write your own SQL statement to perform a
specific query.

For example, SELECT [column_no_1], [column_no_2], [column_no_3] FROM [table_name]


where [default_name_2] =20;

PK (Primary Key): column_no_1

1. Go to the [Data/History] tab » [SQL Query]. Then click on the [New] button to
create a new query.

2. The SQL Query which is set to Basic mode, like the one you created in Chapter 3,
can switch to advanced mode. Once you check the [Advanced mode] checkbox,
it cannot be undone for that SQL Query.

3. The setting dialog will be displayed as shown after being switched to advanced
mode. On the [General] tab, select a MySQL server.

Page 16 of 26
Weintek HMI to MySQL Database Server

4. On the [Command] tab, there are four SQL commands converted to the
following format.
No. of arguments: the number of data columns you want to be dynamic.
No. of outputs: the number of data columns used for the result.
Click the [New] button to create a command or click the [Settings] button to
modify the selected command.

5. How to configure a static query:


The Select command as shown is configured to be static, so there is no register
defined on the [Argument] tab. The result will populate the registers defined on
the [Output] tab.
Command ID: Specify the ID number used to issue this command.
SQL Query: Enter the SQL statements for this query.
Discard result: If checked, the result of issuing this command won’t be shown on
a SQL Query Result Viewer object.

Page 17 of 26
Weintek HMI to MySQL Database Server

How to configure a dynamic query:

The Select command as shown is configured to be dynamic. The value of Part_ID


will be determined during runtime, so ${argument number} is used in the query
to represent the value.

On [Argument] tab, specify a register for the argument. The HMI will refer to the
registers specified on this tab corresponding to the argument number enclosed
in ${ }

Page 18 of 26
Weintek HMI to MySQL Database Server

On [Result] tab, specify registers for the result. The result will populate the
specified registers.

Once completing the dynamic configuration, the value of No. of arguments will be 1.

6. You can create another SQL query to query other tables if needed.

Page 19 of 26
Weintek HMI to MySQL Database Server

7. Create four Set Word objects on the editing area to issue the commands during
runtime.

8. Go to the [Data/History] tab and create a [SQL Query Result Viewer] object on
the editing area. Once the HMI succeeds in performing a Select command, the
result will be displayed on the SQL Query Result Viewer object.

SQL Query: Select an existing SQL Query object.

Filter enabled: Allows you to enter keywords into this object during runtime to
search for a specific record.

Page 20 of 26
Weintek HMI to MySQL Database Server

Note: Up to 10 SQL queries can be created in the SQL Query object.

Page 21 of 26
Weintek HMI to MySQL Database Server

Appendix A

The SQL Sync and SQL Query features provide status registers to simplify
troubleshooting during runtime.

SQL SYNC

Database Sync. Status

Value Description
0 Disconnected from the database server
1 Connecting with the database server
2 Connected with the database server
3 Storing records into the archive. When this is done, the value returns to 2.

Database Sync. Error

Error Code Description


0 No error
1 Unknown error
2 Failed to connect with the database server
3 Access denied
4 Wrong database name
5 Inconsistent data format
6 Failed to open table
7 Failed to create table
8 Failed to write table

Page 22 of 26
Weintek HMI to MySQL Database Server

SQL Query

Status

Value Description
0 Normal
1 Query result exceeds 1000 records (rows). Use LIMIT clause to reduce number
of rows.

Error

Error Code Description


0 No error
1 Unknown error
2 Invalid command
3 Database Server is not connected yet
4 Argument cannot be read
5 Cannot write and output
6 Incorrect number of arguments
7 Error in MySQL, please read error message
8 Unsupported datatype
9 The number of columns exceeds the limit
10 The number of rows exceeds the limit
11 Unable to read local database directory
12 Name of local database does not exist
13 Internal error

Page 23 of 26
Weintek HMI to MySQL Database Server

Appendix B

Converting Datatype in SQL Query

If data type conversion cannot run properly, error code 5 will show in the specified error
register. For example, when converting MySQL’s INT into EB Pro’s 16-bit unsigned, error
code 5 will show if the value exceeds the limit of 16-bit unsigned data.

MySQL data format EasyBuilder Pro datatype


TINYINT 16/32-bit BCD
SMALLINT 16/32-bit HEX
MEDIUMINT 16/32-bit Binary
INT 16/32-bit Signed
BIGINT 16/32-bit Unsigned
BIT
FLOAT 32-bit Float
DOUBLE
DECIMAL
DATETIME String
CHAR, BINARY
VARCHAR, VARBINARY
TINYBLOB, TINYTEXT
BLOB, TEXT
MEDIUMBLOB, MEDIUMTEXT
LONGBLOB, LONGTEXT

Page 24 of 26
Weintek HMI to MySQL Database Server

Appendix C

Opening firewall port for network access

Your PC which runs the MySQL server needs to allow traffic going to the defined TCP
port to pass through. The Open Firewall port option is available during the MySQL
installation.

You can manually configure the firewall port by the following these steps.

Steps to configure Windows Firewall in Windows 10

1. In your Windows 10 PC, launch Windows Defender Firewall with Advanced


Security.
2. Right click [Inbound Rules] and then select [New Rule…].
3. On the Rule Type menu, select [Port] and click the [Next] button.
4. On the Protocol and Ports menu, select [TCP] and add the port number of your
MySQL server (Example:3306) into [Specific local ports] as below. Click the [Next]
button.
5. On the Action menu, select [Allow the connection] and click the [Next] button.
6. On the Profile menu, select the network types as you see fit your network.
• Domain
• Private
• Public
7. On the Name menu, name the rule, add a description, and click the [Finish]
button.

Page 25 of 26
Weintek HMI to MySQL Database Server

MySQL is registered trademarks of Oracle.

Other company names, product names, or trademarks in this document are the trademarks or
registered trademarks of their respective companies.

Founded in 1996, WEINTEK LABS is a global-leading HMI manufacturer


and is dedicated to the development, design, and manufacturing of practical HMI
solutions. WEINTEK LAB’s mission is to provide quality, customizable HMI-solutions that
meet the needs of all industrial automation requirements while maintaining customer
satisfaction by providing “on-demand” customer service. WEINTEK LABS brought their
innovative technology to the United States in 2016, WEINTEK USA, INC., to provide
quality and expedient solutions to the North American industrial market.

6219 NE 181s Street STE 120


Kenmore, WA 98028
425-488-1100

Page 26 of 26

You might also like