+ All Categories
Home > Documents > AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL,...

AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL,...

Date post: 05-Jun-2018
Category:
Upload: phungminh
View: 258 times
Download: 5 times
Share this document with a friend
28
abb Application Example AC500 Scalable PLC for Individual Automation AC500 Communication with MySQL Database www.infoPLC.net
Transcript
Page 1: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

abb

Application Example AC500

Scalable PLC for Individual Automation

AC500 Communication with MySQL Database

www.infoPLC.net

Page 2: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 1 - AC500/Issue: 10.2012

Content

1 Disclaimer ..................................................................................................................3

1.1 For customers domiciled outside Germany/ Für Kunden mit Sitz außerhalb Deutschlands........................................................................ 3

1.2 Nur für Kunden mit Sitz in Deutschland ........................................................................ 3

2 Introduction ...............................................................................................................4

2.1 Hardware and Software requirement ............................................................................. 4

2.2 Connections .................................................................................................................... 4

3 Server Applications...................................................................................................5

3.1 IP settings........................................................................................................................ 5

3.2 Firewall............................................................................................................................. 5

3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ...................................................... 6

3.3.1 Configure XAMPP.................................................................................................... 6

3.3.2 Configure MySQL database..................................................................................... 8

3.3.3 Create a database ................................................................................................. 10

3.4 Tools for trouble shooting............................................................................................ 12

4 PLC AC500 ...............................................................................................................13

4.1 Control Builder Plus...................................................................................................... 13

4.1.1 AC500 eCo CPU.................................................................................................... 13

4.1.2 IP settings.............................................................................................................. 14

4.1.3 rtsinfo..................................................................................................................... 15

4.2 MySQL Function Block Library .................................................................................... 16

4.2.1 Overview................................................................................................................ 16

4.2.2 Usage .................................................................................................................... 16

4.2.3 Interfaces............................................................................................................... 17

4.2.3.1 MYSQL_CONNECT_App(FB) ...................................................................................... 17

4.2.3.2 MYSQL_EXECUTE_App(FB) ....................................................................................... 17

4.2.3.3 MYSQL_GETVALUE_App(FB)..................................................................................... 18

4.2.3.4 MYSQL_DISCONNECT_App(FB) ................................................................................ 18

4.2.4 Structures .............................................................................................................. 19

4.2.4.1 zMYSQL_PROPERTIES_TYPE_App (STRUCT) ........................................................ 19

4.2.4.2 zMYSQL_OKPACKET_TYPE_App (STRUCT)............................................................ 19

www.infoPLC.net

Page 3: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 2 - AC500/Issue: 10.2012

4.2.4.3 zMYSQL_RESULTSET_TYPE_App (STRUCT) .......................................................... 19

4.2.5 Error codes ............................................................................................................ 20

4.2.5.1 MYSQL_CONNECT_App: ............................................................................................ 20

4.2.5.2 MYSQL_EXECUTE_App: ............................................................................................. 20

4.2.5.3 MYSQL_GETVALUE_App:........................................................................................... 20

4.2.5.4 MYSQL_DISCONNECT_App: ...................................................................................... 20

4.3 AC500 MySQL application example............................................................................. 21

4.3.1 Schema ................................................................................................................. 21

4.3.2 Settings in the Project ............................................................................................ 21

4.3.2.1 Required library............................................................................................................. 21

4.3.2.2 Connection settings ...................................................................................................... 21

4.3.2.3 Data types..................................................................................................................... 22

4.3.2.4 Fields in the database................................................................................................... 22

4.3.2.5 Global constants ........................................................................................................... 23

4.3.3 Usage .................................................................................................................... 24

5 Modification .............................................................................................................25

www.infoPLC.net

Page 4: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 3 - AC500/Issue: 10.2012

1 Disclaimer

1.1 For customers domiciled outside Germany/ Für Kunden mit Sitz außerhalb Deutschlands

"Warranty, Liability: The user shall be solely responsible for the use of this application example described within this file. ABB shall be under no warranty whatsoever. ABB's liability in connection with this application example or the files included within this file, irrespective of the legal ground, shall be excluded. The exclusion of liability shall not apply in the case of intention or gross negligence. The present declaration shall be governed by and construed in accordance with the laws of Switzerland under exclusion of its conflict of laws rules and of the Vienna Convention on the International Sale of Goods (CISG)." "Gewährleistung und Haftung: Der Nutzer ist allein für die Verwendung des in dieser Datei beschriebenen Anwendungsbeispiels verantwortlich. ABB unterliegt keiner Gewährleistung. Die Haftung von ABB im Zusammenhang mit diesem Anwendungsbeispiel oder den in dieser Datei enthaltenen Dateien - gleich aus welchem Rechtsgrund - ist ausgeschlossen. Dieser Ausschluß gilt nicht im Falle von Vorsatz oder grober Fahrlässigkeit. Diese Erklärung unterliegt Schweizer Recht unter Ausschluß der Verweisungsnormen und des UN-Kaufrechts (CISG)."

1.2 Nur für Kunden mit Sitz in Deutschland

"Gewährleistung und Haftung: Die in diesem Anwendungsbeispiel enthaltenen Dateien beschreiben eine mögliche Anwendung der Steuerung AC500 bzw. zeigen eine mögliche Einsatzart der Steuerung. Sie stellen nur Beispiele für Programmierungen dar, sind aber keine fertigen Lösungen. Eine Gewähr kann nicht übernommen werden. Der Nutzer ist für die ordnungsgemäße, insbesondere vollständige und fehlerfreie Programmierung der Steuerungen selbst verantwortlich. Im Falle der teilweisen oder ganzen Übernahme der Programmierbeispiele können gegen ABB keine Ansprüche geltend gemacht werden. Die Haftung von ABB, gleich aus welchem Rechtsgrund, im Zusammenhang mit den Anwendungsbeispielen oder den in dieser Datei enthaltenen Dateien wird ausgeschlossen. Der Haftungsausschluß gilt jedoch nicht in Fällen des Vorsatzes, der groben Fahrlässigkeit, bei Ansprüchen nach dem Produkthaftungsgesetz, im Falle der Verletzung des Lebens, des Körpers oder der Gesundheit oder bei schuldhafter Verletzung einer wesentlichen Vertragspflicht. Im Falle der Verletzung einer wesentlichen Vertragspflicht ist die Haftung jedoch auf den vertragstypischen, vorhersehbaren Schaden begrenzt, soweit nicht zugleich ein anderer der in Satz 2 dieses Unterabsatzes erwähnten Fälle gegeben ist. Eine Änderung der Beweislast zum Nachteil des Nutzers ist hiermit nicht verbunden. Es gilt materielles deutsches Recht unter Ausschluß des UN-Kaufrechts."

www.infoPLC.net

Page 5: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 4 - AC500/Issue: 10.2012

2 Introduction

This application example describes how it is possible to build up a communication with AC500 to the MySQL database.

2.1 Hardware and Software requirement

NOTICE

The following configuration is used in this document. The newer version of hardware and software should work, however it should be tested by the user himself.

Hardware Software AC500 CPU:PM564 ETH, FW: V2.1.5 PS501 Control Builder Plus: V2.1.0

Ethernet Switch MySQL Server or XAMPP V1.7.4 or higher

Personal Computer or Server

Ethernet cable

2.2 Connections

www.infoPLC.net

Page 6: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 5 - AC500/Issue: 10.2012

3 Server Applications

This chapter will show you all programs and settings they are required.

3.1 IP settings

The PC/Server where the MySQL database is running should be in the same network as the PLC. Change the network addresses of the Server to: IP address: 192.168.8.253

Subnet mask 255.255.240.0

Gateway: 0.0.0.0 or address from the router

3.2 Firewall

CAUTION!

The windows firewall blocks all incoming MySQL requests. Please be sure, that you have access to the port 3306 and the mysqld.exe.

There are two ways to have access to the MySQL database.

1. It’s not recommended! You can disable your windows firewall.

2. The better way is to create a rule, which allow to access to the MySQL database from an external device. In our case a PLC: Please go to your windows firewall options, choose advanced settings and create a new rule on the right side.

a) Choose program -> next, select this program path and choose the “mysqld.exe” stored in “C:/xampp/mysql/bin/” -> next, allow this connection -> next, set a cross at all three options -> next, insert a name and click on finish button.

b) Choose port -> next, select “TCP” and select “special port and insert “3306 -> next, allow this connection -> next, set a cross at all three options -> next, insert a name and click on finish button.

www.infoPLC.net

Page 7: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 6 - AC500/Issue: 10.2012

3.3 XAMPP (contains: Apache, MySQL, PHP and Perl)

3.3.1 Configure XAMPP

Please go to http://www.apachefriends.org/en/xampp.html and download XAMPP in the newest version. After this, install the software and restart your PC.

Start the web browser and insert “localhost” into the address bar. The following window will be displayed.

www.infoPLC.net

Page 8: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 7 - AC500/Issue: 10.2012

DANGER!

It’s very important that the MySQL and the XAMPP Directory has a password!

Now, we have to secure the application. Push the button “Security” on the left menu. The following window will be displayed.

Push on the link in the red marked border. The following page will be displayed.

Please insert a password for the MySQL database(1) and the XAMPP directory(2). After this, please reboot the Server to take effect.

www.infoPLC.net

Page 9: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 8 - AC500/Issue: 10.2012

3.3.2 Configure MySQL database

After we have set a password for the directory and the database, we want to login into the database. Insert “localhost/phpmyadmin” in the address bar on your browser. The following screen will appear.

Please insert the password that you set the chapter before. For the first login, the username is “root”. You can change the password, when you logged in.

When you logged in successfully you will see the following screen.

www.infoPLC.net

Page 10: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 9 - AC500/Issue: 10.2012

If you want you can add a new user with a username and a password. Please click on “Privileges” as shown in the following screen. Now, you can “Add a new User” with a password.

www.infoPLC.net

Page 11: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 10 - AC500/Issue: 10.2012

3.3.3 Create a database

NOTICE

This step is not necessary. Because the Functions blocks in the PLC will create automatically a database and a table if they not exist.

Now, we want to create a new database. At first, click on “Database” as shown in the red border.

www.infoPLC.net

Page 12: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 11 - AC500/Issue: 10.2012

The green border marked the field, where you can insert a name for the new database. Insert a name e.g. “db2” and push “Create”. The following screen will be displayed.

www.infoPLC.net

Page 13: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 12 - AC500/Issue: 10.2012

3.4 Tools for trouble shooting

It is recommended to install the actual release (version 1.4.7 or higher) of the free “Wireshark” network analyzer. Testing with different client workstations I experienced serious troubles on some machines to get a connection between PLC and the SQL connect function block and the MySQL database. The reason is that the incoming TCP connect requests are regarded as an attack and some antivirus applications and firewalls will block these requests. In “Wireshark” apply a display filter “tcp.port == 3306”(enter here the port which was configured during server setup). Wireshark has a built in SQL decoder and can be very useful identifying SQL problems Sample capture:

www.infoPLC.net

Page 14: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 13 - AC500/Issue: 10.2012

4 PLC AC500

This chapter will show how to configure the different parameters.

4.1 Control Builder Plus

The PLC program was written with the ABB Control Builder Plus PS501 V2.1.0

4.1.1 AC500 eCo CPU

Using the AC500 eCo CPU PM564-ETH V2.1

www.infoPLC.net

Page 15: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 14 - AC500/Issue: 10.2012

4.1.2 IP settings

The programming and online access to the CPU will be done over the Ethernet port. Change the IP address from the PLC to:

IP address: 192.168.8.252

Subnet mask: 255.255.240.0

Gateway: 0.0.0.0 or address from the router

Get the following window, by click “Tools” on the task bar. Then choose “IP config tool”. Now, you can search your PLC and configure a new IP address.

CAUTION!

Please do NOT set a cross at „Force IP settings”!

www.infoPLC.net

Page 16: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 15 - AC500/Issue: 10.2012

4.1.3 rtsinfo

CAUTION!

It’s very important that you use the firmware V2.1.5 or higher.

www.infoPLC.net

Page 17: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 16 - AC500/Issue: 10.2012

4.2 MySQL Function Block Library

4.2.1 Overview

MYSQL_CONNECT_App(FB) Establishes a connection to the server. MYSQL_EXECUTE_App (FB) Executes the SQL statement. MYSQL_GETVALUE_App (FB) Extracted from the result set a cell value. MYSQL_DISCONNECT_App (FB) Closed the connection.

4.2.2 Usage

To connect to the MySQL server, the MYSQL_CONNECT_App(FB) are given the IP address and port number of the server and the username and password if required. Once the function block has run without an error, the connection at the output pin CON is returned. MYSQL_EXECUTE_App(FB) now takes this connection to perform the given SQL Statement. The NonQueryStatements(INSERT, UPDATE, CREATE, ...) represent the response of the FB pin on OKPACKET. This offer information of all affected rows. SELECT statements, however fill the ResultSet pin. The values from the ResultSet can then be read by MYSQL_GETVALUE_App(FB). Once the connection is established, any number of SQL statements can be executed. If the connection is no longer needed, they should always be using MYSQL_DISCONNECT_App(FB) to close the connection.

www.infoPLC.net

Page 18: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 17 - AC500/Issue: 10.2012

4.2.3 Interfaces

4.2.3.1 MYSQL_CONNECT_App(FB)

Establishes a connection to the server

VAR_INPUT EN BOOL Enabled the FB by a rising edge. (FALSE -> TRUE)

IP STRING(15) IP address from the MySQL database

PORT WORD Port number from the MySQL database

PROPS MYSQL_PROPERIES Some properties from the server connection for example username or password

VAR_OUTPUT

DONE BOOL Signaled the end of the FB

ERR BOOL Signaled an error

ERNO WORD Error number

SQL_ERNO WORD SQL error number

CON MYSQL_CONNECTION Connection to the MySQL database. This is the input from MYSQL_EXECUTE_App

4.2.3.2 MYSQL_EXECUTE_App(FB)

Executes the given SQL statement and returns the ResultSet(Query) or the acknowledgment packet NonQuery).

VAR_INPUT EN BOOL Enabled the FB by a rising edge. (FALSE -> TRUE)

STATEMENT STRING(255) Executable SQL statement

VAR_OUTPUT

DONE BOOL Signaled the end of the FB

ERR BOOL Signaled an error

ERNO WORD Error number

SQL_ERNO WORD SQL error number

OKPACKET MYSQL_OKPACKET Response to a nonQuery statement (INSERT, UPDATE, ...)

RESULTSET MYSQL_RESULTSET Response to a SELECT statement. Can be read by MYSQL_GETVALUE_App

CAUTION!

After a complete cycle, the FB must be called once with EN:=FALSE

www.infoPLC.net

Page 19: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 18 - AC500/Issue: 10.2012

4.2.3.3 MYSQL_GETVALUE_App(FB)

Returns the required cell value (COL, ROW) from the ResultSet. ROW = 0 affords the column headers. (1, 0) returns the first column header. COL = 0 is valid.

VAR_INPUT EN BOOL Enabled the FB by a rising edge. (FALSE -> TRUE)

RESULTSET MYSQL_RESULTSET Response to a SELECT

COL DWORD Requested column. Always >= 1

ROW DWORD Requested line. 0 returns the column headers

VAR_OUTPUT

DONE BOOL Signaled the end of the FB

ERR BOOL Signaled an error

ERNO WORD Error number

VALUE STRING(255) Requested cell value

NULL BOOL cell value = NULL

CAUTION!

After a complete cycle, the FB must be called once with EN:=FALSE

4.2.3.4 MYSQL_DISCONNECT_App(FB)

Closes a connection

VAR_INPUT EN BOOL Enabled the FB by a rising edge. (FALSE -> TRUE)

CON MYSQL_CONNECTION Connection to the MySQL server

VAR_OUTPUT

DONE BOOL Signaled the end of the FB

ERR BOOL Signaled an error

ERNO WORD Error number

www.infoPLC.net

Page 20: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 19 - AC500/Issue: 10.2012

4.2.4 Structures

4.2.4.1 zMYSQL_PROPERTIES_TYPE_App (STRUCT)

Properties of the connection sUser STRING(50) User is logged on to the database

sPassword STRING(250) Password from the user

sDatabase STRING(50) Database name

sTable STRING(50) Table name

dwMaxPacketSize DWORD Maximum number of bytes of a packet. Default: 0xFFFFFF

byCharsetNumber BYTE Character set. List of all fonts SHOW COLLATION LIKE '%'. Default: 33 (UTF-8)

4.2.4.2 zMYSQL_OKPACKET_TYPE_App (STRUCT)

Response to a nonQuery statement (INSERT, UPDATE, ...) dwAffectedRows DWORD Number of affected rows

dwInsertId DWORD Generated if an AUTO_INCREMENT number was used otherwise 0

wServerStatus WORD To check whether the statement was executed within a transaction

wWarningCount WORD Number of warnings

sMessage STRING(255) Information in the format string

4.2.4.3 zMYSQL_RESULTSET_TYPE_App (STRUCT)

Response to a SELECT statement. iFieldCount INT Number of columns

iRowCount INT Number of rows

www.infoPLC.net

Page 21: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 20 - AC500/Issue: 10.2012

4.2.5 Error codes

4.2.5.1 MYSQL_CONNECT_App:

0x4040 Username is missing 0x4030 Invalid port number or port is < 1024 0x301A Socket could not be created 0x4020 Invalid IP address 0x3017 - Internal Buffer too small for the reading packet

- Response (ClientAuthenticationPacket) is too large for the output buffer 0x5003 MySQL error:

SQL_ERNO query pin. List of MySQL errors: http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html

0x3014 Invalid packet header. Packet length =0 SysSockLibErr - The connection could not be opened

- Error in reading - Sending has failed

4.2.5.2 MYSQL_EXECUTE_App:

0x3028 - Error when freeing memory - Not enough free memory

0x4021 SQLStatement is not specified 0x3005 Connection is not available for SQL statements 0x3017 - Internal Buffer too small for the reading packet

- Response (ClientAuthenticationPacket) is too large for the output buffer 0x5003 MySQL error:

SQL_ERNO query pin. List of MySQL errors: http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html

0x3014 Invalid packet header. Packet length =0 0x3026 Errors in calculating the length of strings 0x3027 Cell value is too large SysSockLibErr - Error in reading

- Sending has failed

4.2.5.3 MYSQL_GETVALUE_App:

0x4020 Invalid ResultSet 0x4030 Requested column outside the result set 0x4040 Requested row outside the result set

4.2.5.4 MYSQL_DISCONNECT_App:

0x4020 Invalid socket

www.infoPLC.net

Page 22: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 21 - AC500/Issue: 10.2012

4.3 AC500 MySQL application example

4.3.1 Schema

4.3.2 Settings in the Project

CAUTION!

Before you use this application example, it’s important that you have read this manual at first. Please adapt the settings in the CoDeSys program.

4.3.2.1 Required library

Please include the SysLibSockets.lib in your project. This library is stored in “C:\Program Files\Common Files\CAA-Targets\ABB_AC500\AC500_V12\Library\syslibs”. When you forget to include this library you will receive an error during compiling your project.

4.3.2.2 Connection settings

sServer_IP_Address STRING(15) Server address from the database wServer_Port WORD Server port from the database sUser STRUCT Please see chapter Structures sPassword STRUCT Please see chapter Structures sDatabase STRUCT Please see chapter Structures sTable STRUCT Please see chapter Structures

www.infoPLC.net

Page 23: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 22 - AC500/Issue: 10.2012

4.3.2.3 Data types

Here is a list off all data types you can use in your program. Please take a look at MySQL data types.xls

4.3.2.4 Fields in the database

NOTICE

It’s very important that you know how many fields are required in the database. The first field should always contain a continuous number.

In our case we have named the first field “ID”. This column contains a continuous number, it’s important for the SELECT statement. Also important, when you will create a field in a table the name, data type and optional parameter must be inserted in the statement. Here are some examples: arFields_Datatypes[x,1] This is always the name from the field arFields_Datatypes[x,2] This is always the data type and some optional parameters from the field

arFields_Datatypes[x,3] This is always value from the field! Be careful the first field(ID) do not have a

value! Insert a continuosly number arFields_Datatypes[1,1:= 'ID'; Name of the 1. field in the

database arFields_Datatypes[1,2] := 'INT PRIMARY KEY AUTO_INCREMENT';

Data type and some parameters that a continuously number is generated

Insert a small Integer: arFields_Datatypes[2,1] := 'value_smallint';

Name of the 2. field in the database

arFields_Datatypes[2,2] := 'SMALLINT (4)';

Data type of the 2. Field in the database in this case “'SMALLINT”. Please see Data types for more information.

arFields_Datatypes[2,3] := '111';

Value which will be insert.

Insert a String: arFields_Datatypes[3,1] := 'value_varchar';

Name of the 3. field in the database

arFields_Datatypes[3,2] := 'VARCHAR (32)';

Data type of the 3. Field in the database in this case “VARCHAR”. Please see Data types for more information.

arFields_Datatypes[3,3] := '$'www.abb.com/plc$'';

Value which will be insert. ATTENTION: Every string must have a separator “$'” at the start and the end.

Insert a Real: arFields_Datatypes[4,1] := 'value_real';

Name of the 4. field in the database

arFields_Datatypes[4,2] := 'REAL';

Data type of the 4. Field in the database in this case “REAL”. Please see Data types for more information.

arFields_Datatypes[4,3] := '10.23';

Value which will be insert. ATTENTION: Please use a dot and not a comma

www.infoPLC.net

Page 24: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 23 - AC500/Issue: 10.2012

Insert a Double: arFields_Datatypes[5,1] := 'value_double';

Name of the 5. field in the database

arFields_Datatypes[5,2] := 'DOUBLE'; Data type of the 5. Field in the database in this case “DOUBLE”. Please see Data types for more information.

arFields_Datatypes[5,3] := '77.23'; Value which will be insert. ATTENTION: Please use a dot and not a comma

Insert a Datetime: arFields_Datatypes[6,1] := 'value_datetime';

Name of the 6. field in the database

arFields_Datatypes[6,2] := 'DATETIME'; Data type of the 6. Field in the database in this case “DATETIME'. Please see Data types for more information.

arFields_Datatypes[6,3] := 'NOW()'; Value which will be insert. You can insert a datetime manually or with the SQL command “NOW()). This command inserts the current date and time in the SQL database.

Insert a Date: arFields_Datatypes[7,1] := 'value_date';

Name of the 7. field in the database

arFields_Datatypes[7,2] := 'DATE'; Data type of the 7. Field in the database in this case “DATE”. Please see Data types for more information.

arFields_Datatypes[7,3] := 'CURDATE()'; Value which will be insert. You can insert a date manually or with the SQL command “'CURDATE()). This command inserts the current time in the SQL database.

Insert a Time: arFields_Datatypes[8,1] := 'value_time';

Name of the 8. field in the database

arFields_Datatypes[8,2] := 'TIME'; Data type of the 8. Field in the database in this case “TIME”. Please see Data types for more information.

arFields_Datatypes[8,3] := 'CURTIME()'; Value which will be insert. You can insert a time manually or with the SQL command “'CURDATE()). This command inserts the current time in the SQL database.

4.3.2.5 Global constants

When you have set all your names, data types and so on please check that the variable “MYSQL_MAX_COLUMNS_App” in the global variable list contains the number from all fields. For example you have 8 columns like our application example, it’s very important that the variable looks so: MYSQL_MAX_COLUMNS_App: INT := 8;

NOTICE

Please adapt this variable. When you have more or less fields, you will receive an error message when you try to compile your project.

www.infoPLC.net

Page 25: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 24 - AC500/Issue: 10.2012

4.3.3 Usage

When you have set all you settings, compiled your project and downloaded to your PLC then you can enable the variable “pulse” with a rising edge. This variable triggers all function blocks. A connection is established, the database generated if they not exists. The table will be created if it doesn’t exist. The values will be written into the database. One measurement will be read. The selection is the following: row_id = 1

ID(row) you want to read from the database

column_id = 3

Column you want read from your selected row_id(ID)

NOTICE

The 1st parameter is in column 2! Please see: MYSQL_GETVALUE_App(FB)

Example: When you use this application example without any changes, you will see this table in your database and SELECT(read) the following dataset with row_id = 1 and column_id = 3

ID value_ smallint

value_ varchar

value_ real

value_ double

value_ datetime

value_ date

value_ time

1 111 www.abb.com/plc

10.23 77.23 2012-07-09 10:50:11

2012-07-09 10:50:11

This value will be read, when you set row_id = 1 and column_id = 3

COLUMN 1

ROW 0

COLUMN 2 ….

COLUMN 3

ROW 1

www.infoPLC.net

Page 26: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 25 - AC500/Issue: 10.2012

5 Modification

Version Chapter Modification Date V1.0 First version 2012-07-16 V1.0.1 All Changed all pictures from German to English language 2012-07-18

www.infoPLC.net

Page 27: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

Application Example - 26 - AC500/Issue: 10.2012

www.infoPLC.net

Page 28: AC500 Communication with MySQL Database - infoplc.net€¦ · 3.3 XAMPP (contains: Apache, MySQL, PHP and Perl) ... The better way is to create a rule, which allow to access to the

abb

ABB Automation Products GmbH Wallstadter Str. 59 D-68526 Ladenburg Tel. : +49 62 21 / 701-1444 Fax : +49 62 21 / 701-1382 E-Mail : [email protected] www.abb.com/plc

oc. kind: No. o. p.:

Helpline document 26

Title: Lang.:

AC500 ommunication with MySQL Database EN

Man

ual N

o. 3

AD

R 0

25 0

061

M02

01

www.infoPLC.net


Recommended