User Guide MySQL Library For TIA Portal
User Guide MySQL Library For TIA Portal
Newer
User guide
V1.0.0.0
Author:
Tomáš Krajcar
nám. Mı́ru 1205/9
767 01 Kroměřı́ž
Czech Republic
www.plc2sql.com
mail: [email protected]
1 Product description 2
1.1 Range of function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Supported datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Function blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.1 fbMySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4.1 fcGetValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4.2 fcDtlToString . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4.3 fcStringToDtl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6 Licensing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Installation 8
2.1 Installation MySQL library to TIA Portal . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 Example application 11
3.1 Example commands for SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.1.1 tblTestPLC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Installation of MySQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4 Change Log 14
1
Chapter 1
Product description
This library allows you to connect your PLC Siemens S7-1200 or S7-1500 application to MySQL database
or MariaDB. With this library you are able to store and read process data. Read recipes from ERP, save
breakdown report and etc. No more OPC servers and other middleware.
Basic requirement for this library is TIA Portal V13 or higher and MySQL Server (V5 or higher).
• DELETE
• Execute stored procedures
2
1.3 Function blocks
1.3.1 fbMySQL
FB for complete connecting and executing commands with Microsoft SQL from 2005 to 2017.
Author: krajcart
V1.0.0.0
Structure stConnectData
3
1.4 Functions
1.4.1 fcGetValue
FC for converting raw SQL data to datatype STRING. Not supported type will be notified.
Allowed data types: TINY,DECIMAL, SHORT, LONG, INT24, LONGLONG, VAR STRING, STRING,
VARCHAR, DECIMAL, NEWDECIMAL, FLOAT, DOUBLE, DATETIME, TIMESTAMP, DATE,
TIME.
Author: krajcart
V1.0.0.0
"dbSQL_data".diValue := STRING_TO_DINT("dbSQL_data".sValue);
"dbSQL_data".rValue := STRING_TO_REAL("dbSQL_data".sValue);
"dbSQL_data".xValue := INT_TO_BOOL(STRING_TO_INT("dbSQL_data".sValue));
1.4.2 fcDtlToString
FC for converting datetime to string for inserting to SQL.
Allowed data types: DTL
Author: krajcart
V1.0.0.0
4
1.4.3 fcStringToDtl
FC for converting string to DTL.
Allowed data types: STRING
Author: krajcart
V1.0.0.0
5
1.5 Errors
List of errors stored in value dwError as output from fbMySql.
6
Table 1.7: Error table convert functions
1.6 Licensing
MySQL library for TIA Portal V13, V14, V15, V15.1, V16 is licensed per runtime license. Each license
is binded to SN of PLC. Price for one runtime license is 149e without VAT. Without valid license
library works only 2 hours after startup. Link for purchase: https://www.plc2sql.com/products/
mysql-library-for-tia-portal-v13-newer/#license
7
Chapter 2
Installation
Function Blocks
• fbMySQL (S7-1200 & S7-1500)
Functions
• fcGetValue (S7-1200 & S7-1500)
• stConnectData
• stQuery
• stSqlResponse
Recommended FW
• S7-1200 from FW4.2 and higher is recommended
• S7-1500 from FW2.0 and higher is recommeded
8
This library package contains:
9
Limits of data to read from SQL
fbMySQL has internally setup array bound for data able to read from MySQL. Because this is about
definition of arrays and memory in PLC. In default you are able to read max 10 collumn, 10 rows and
each row can contain max 300 bytes of data.
10
Chapter 3
Example application
On the picture 3.1 is main program in OB1 with fbMySQL and function block. All example files are in
Global Library. Master copies S7-1200 or S7-1500.
11
3.1 Example commands for SQL Server
3.1.1 tblTestPLC
In this table we have 6 collumns:
• Bools [bit]
• String [nvarchar(50)]
• ID [int]
• Real [float]
• DoubleInt [bigint]
• dateTime [datetime]
Table 3.1: Example of values, which you can add to your tblTestPLC table
Note If you insert STRING, DATETIME and other datatypes from PLC to SQL you have to put
Dollar Sign($) before Apostrofe(´).
12
3.2 Installation of MySQL Server
Here is video how to install MariaDB: https://www.youtube.com/watch?v=Nvt7S9XVeXg
13
Chapter 4
Change Log
V 1.0.0.0
• Released
14