51
https://support.industry.siemens.com/cs/ww/en/view/109479140 Application description 08/2015 Connection of an SQL database to an S7-1500 Software Controller SIMATIC ODK 1500S-SQL-driver V1.0

Application description 08/2015 Connection of an SQL ... · PDF fileApplication description 08/2015 Connection of an SQL ... Entry-ID: 109479140, V1.0 ... Siemens provides products

Embed Size (px)

Citation preview

https://support.industry.siemens.com/cs/ww/en/view/109479140

Application description 08/2015

Connection of an SQL database to an S7-1500 Software Controller SIMATIC ODK 1500S-SQL-driver V1.0

Warranty and liability

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 2

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Warranty and liability

Note The Application Examples are not binding and do not claim to be complete regarding the circuits shown, equipping and any eventuality. The Application Examples do not represent customer-specific solutions. They are only intended to provide support for typical applications. You are responsible for ensuring that the described products are used correctly. These application examples do not relieve you of the responsibility to use safe practices in application, installation, operation and maintenance. When using these Application Examples, you recognize that we cannot be made liable for any damage/claims beyond the liability clause described. We reserve the right to make changes to these Application Examples at any time without prior notice. If there are any deviations between the recommendations provided in these application examples and other Siemens publications – e.g. Catalogs – the contents of the other documents have priority.

We do not accept any liability for the information contained in this document.

Any claims against us – based on whatever legal reason – resulting from the use of the examples, information, programs, engineering and performance data etc., described in this Application Example shall be excluded. Such an exclusion shall not apply in the case of mandatory liability, e.g. under the German Product Liability Act (“Produkthaftungsgesetz”), in case of intent, gross negligence, or injury of life, body or health, guarantee for the quality of a product, fraudulent concealment of a deficiency or breach of a condition which goes to the root of the contract (“wesentliche Vertragspflichten”). The damages for a breach of a substantial contractual obligation are, however, limited to the foreseeable damage, typical for the type of contract, except in the event of intent or gross negligence or injury to life, body or health. The above provisions do not imply a change of the burden of proof to your detriment.

Any form of duplication or distribution of these Application Examples or excerpts hereof is prohibited without the expressed consent of the Siemens AG.

Security informa-tion

Siemens provides products and solutions with industrial security functions that support the secure operation of plants, solutions, machines, equipment and/or networks. They are important components in a holistic industrial security concept. With this in mind, Siemens’ products and solutions undergo continuous development. Siemens recommends strongly that you regularly check for product updates.

For the secure operation of Siemens products and solutions, it is necessary to take suitable preventive action (e.g. cell protection concept) and integrate each component into a holistic, state-of-the-art industrial security concept. Third-party products that may be in use should also be considered. For more information about industrial security, visit http://www.siemens.com/industrialsecurity.

To stay informed about product updates as they occur, sign up for a product-specific newsletter. For more information, visit http://support.industry.siemens.com.

Table of contents

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 3

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Table of contents Warranty and liability ................................................................................................... 2

1 Introduction ........................................................................................................ 5

2 Task ..................................................................................................................... 6

2.1 Overview............................................................................................... 6

3 Solution............................................................................................................... 7

3.1 Overview............................................................................................... 7 3.2 Description of the core functions .......................................................... 7 3.3 Hardware and software components ................................................... 7 3.3.1 Validity .................................................................................................. 7 3.3.2 Used components ................................................................................ 7

4 Function mechanisms ....................................................................................... 9

4.1 Overview............................................................................................... 9 4.2 Description of the function blocks ...................................................... 11 4.2.1 ODK1500S_SQL_Load ...................................................................... 11 4.2.2 ODK1500S_SQL_Connect................................................................. 11 4.2.3 ODK1500S_SQL_SetStatement ........................................................ 13 4.2.4 ODK1500S_SQL_GetData................................................................. 16 4.2.5 ODK1500S_SQL_GetBlob ................................................................. 19 4.2.6 ODK1500S_SQL_Disconnect ............................................................ 22 4.2.7 ODK1500S_SQL_Unload................................................................... 23

5 Installation and commissioning ..................................................................... 24

5.1 Installation and commissioning of the MSSQL demo database......... 24 5.1.1 Installation MSSQL Server 2014 Express .......................................... 24 5.1.2 Configuration of the SQL server ......................................................... 27 5.1.3 Restoration of the sample scheme ..................................................... 28 5.1.4 Generation of a login to the SQL server ............................................. 29 5.2 Installation and commissioning of the SQL driver on the runtime

PC ....................................................................................................... 31 5.2.1 Installation of the SQL driver DLL ...................................................... 31 5.2.2 Parameterization of the ODBC driver ................................................. 31

6 Operation of the application ........................................................................... 35

6.1 Use of the example application .......................................................... 35 6.1.1 Structure of the STEP 7 example project ........................................... 36 6.1.2 Loading of SQL driver DLL ................................................................. 38 6.1.3 Establish the connection to the database .......................................... 38 6.1.4 Transmission of SQL statements ....................................................... 38 6.1.5 Disconnect the connection to the database ....................................... 39 6.1.6 Unload SQL driver DLL ...................................................................... 39 6.1.7 Error analysis ..................................................................................... 39 6.2 Adaption of the example application to own requirements ................ 40 6.2.1 Adaption of the ODBC-Login data ...................................................... 40 6.2.2 Adaption of the SQL statements ........................................................ 40

7 Error codes ....................................................................................................... 41

7.1 Overview............................................................................................. 41 7.2 Error Codes ODK1500S ..................................................................... 42 7.3 Error Codes ODK1500S SQL driver .................................................. 43 7.3.1 Function Error Codes ......................................................................... 43 7.3.2 ODBC Function Number .................................................................... 44 7.3.3 ODBC Function Error Code................................................................ 45

Table of contents

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 4

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

7.3.4 SQL Error Codes ................................................................................ 45

8 Commissioning Tool „SQLViewer“ ............................................................... 49

9 Related literature ............................................................................................. 51

10 History............................................................................................................... 51

1 Introduction

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 5

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

1 Introduction This document describes the connection of an SQL-database to an S7-1500 Software Controller with ODK1500S-SQL-driver.

Among others, you will find a description of how to send SQL-statements to and how to call data from the SQL server by means of the driver.

2 Task

2.1 Overview

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 6

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

2 Task

2.1 Overview

Introduction

In the field of the automation technology, there is a great number of applications for a database.

Databases permit a central, fast, structured and reliable data storage.

Programmable logic controllers, such as S7-1500 controllers, are used for the control of machines and production plants but, however, are hardly suitable to store large amounts of data that occur or are required during the production.

Thus, a connection of a database to a programmable logic controller offers a lot of advantages and use cases.

For example, you can use databases to log machine data or messages during the production. In this case, the controller transmits data to the database.

Another use case is that the controller reads out parameters, which are required for the production of a certain product series, from a central database.

Overview of the automation task

The following figure gives an overview of a possible automation task.

Figure 2-1: Example automation task

3 Solution

3.1 Overview

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 7

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

3 Solution

3.1 Overview

The on-board equipment is not sufficient to connect a database to an S7-1500 controller.

To solve this problem, an SQL driver for the S7-1500 software controller has been developed with the 1500S ODK (Open Development Kit). You can use the SQL driver to transmit data from an S7-1500 software controller to an SQL database or to read out data from an SQL database.

In general, the driver can be used for databases with an ODBC driver.

The ODK 1500S-SQL driver consists of function blocks for the S7-user program as well as of a Windows-DLL.

Required knowledge

Basic knowledge concerning SQL databases and STEP 7 V13 is assumed.

3.2 Description of the core functions

The following SQL database functions are supported by means of the driver:

Transmission of SQL statements with flexible arguments. Possible statements:

– SELECT

– INSERT

– UPDATE

– DELETE

Reception of read data from an SQL database

Reception of read BLOB data types from an SQL database

Note Officially, the SQL driver only supports the four mentioned SQL statements. These statements have been tested and released. In addition to these statements, there are generally further SQL statements that function, too (e.g. execute statements for stored procedures), as the SQL driver transmits the SQL strings and SQL arguments, which have been transferred by the software controller, directly to the SQL database.

3.3 Hardware and software components

3.3.1 Validity

The application example is valid for

STEP 7 from V13 SP1 on

S7-1500 Software Controller

Microsoft SQL Server

3.3.2 Used components

This application has been generated and checked with the following components:

3 Solution

3.3 Hardware and software components

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 8

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Hardware components

Table 3-1

Component No. Order number Note

1515SP PC 1 6ES7 677-2AAxx-0xx0 ET 200SP Open Controller

Software components

Table 3-2

Component No. Order number Note

STEP 7 Professional V13 SP1

1 6ES7 822-1AA03-0YA5

Microsoft SQL 2014 Server Express Edition

1 https://www.microsoft.com/en-US/download/details.aspx?id=42299

As an alternative, Microsoft SQL 2008 R2 Server Express Edition, for example, can be used as well

CPU 1505S FW 1.7 1 6ES7 672-5AC00-0YA0 As an alternative, each available S7-1500 Software Controller can be used.

SQL-driver-DLL 1 Windows-DLL

Sample files and projects

The following list includes all files and projects being used in this application example.

Table 3-3

Component Note

109479140_ODK1500S-SQL-Driver_CODE_V10.zip

This zip file includes the STEP 7 project, the SQL driver DLL, the demo database and the SQL viewer.

109479140_ODK1500S-SQL-Driver_DOCU_V10_en.pdf

This document

4 Function mechanisms

4.1 Overview

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 9

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

4 Function mechanisms This chapter describes the function blocks for the establishment of the connection to the SQL server as well as for the SQL statements. Furthermore, we go into details concerning the establishment of the connection to the SQL data server and the possible functions.

For the application of an SQL database with an S7-1500 software controller, there are in total seven function blocks available. These function blocks make it possible to:

load the driver DLL

establish the connection to the SQL server

transmit SQL statements

read data from the database

close the connection to the database

unload the driver DLL

4.1 Overview

The following table gives an overview of the function blocks belonging to the SQL driver as well as their function.

Table 4-1: Overview function blocks SQL driver

Image Module name Function

ODK1500S_Load Load SQL driver DLL

ODK1500S_SQL_Connect Establish the connection to the SQL-Server

4 Function mechanisms

4.1 Overview

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 10

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Image Module name Function

ODK1500S_SQL_SetStatement Transmit SQL-statement

ODK1500S_SQL_GetData Write returned data of an SQL-Select statement to a data block

ODK1500S_SQL_GetBlob Write returned BLOB-data of an SQL-Select statement to a data block

ODK1500S_SQL_Disconnect Disconnect connection to the SQL-Server

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 11

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Image Module name Function

ODK1500S_SQL_Unload Manual unloading of DLL, e.g. for the exchange of DLL

4.2 Description of the function blocks

4.2.1 ODK1500S_SQL_Load

Before using the SQL driver, it is necessary to load the supplied DLL with the ODK_Load block.

By changing the edge (from 0 to 1) at the input parameter "REQ", the function is started.

Figure 4-1: ODK1500S_SQL_Load block

Block parameters

Table 4-2: Parameter ODK1500S_SQL_Load

Type Name Data type

Description

Input REQ BOOL A rising edge activates the loading of the SQL driver DLL.

Output DONE BOOL Indicates that the instruction to load the SQL driver DLL has been terminated successfully.

Output BUSY BOOL Indicates that the SQL driver DLL is still being loaded.

Output ERROR BOOL Indicates that an error has occurred while loading the SQL driver DLL. STATUS shows further information on the possible cause of the error.

Output STATUS INT Gives information on possible sources of the error if an error has occurred while loading the SQL driver DLL.

4.2.2 ODK1500S_SQL_Connect

The ODK1500S_SQL_Connect block establishes a connection to an SQL server by a rising edge at the input "REQ" via the ODBC interface. This block has to be called only once. To establish a connection to an SQL server, the login data for system DSN, user name and password have to be entered. The block is executed asynchronously to the running PLC cycle.

Note Only one SQL database connection is supported. In case of another establishment of the connection, an error message is indicated.

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 12

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Figure 4-2: ODK1500S_SQL_Connect block

Module parameter

Table 4-3: Parameter ODK1500S_SQL_Connect

Type Name Data type Description

Input REQ BOOL A rising edge of this input value activates the execution of the ODK function.

Input odbcSystDSN STRING ODBC Data Source Name

Input username STRING User name for the login to the SQL database

Input password STRING Password for the login to the SQL database

Input enableDebug BOOL Activates the commissioning mode which can be used to output expanded diagnostics information by means of the SQL viewer tool.

Output DONE BOOL This output value indicates that the instruction to execute the ODK function has been terminated successfully.

Output BUSY BOOL This output value indicates that the ODK function is still being executed.

Output ERROR BOOL This output value indicates that an error has occurred during the execution of the ODK function. The output value STATUS shows further information on this matter.

Output STATUS INT This output value gives information on possible sources of the error if an error has occurred during the execution of the ODK function.

Output fctError BOOL This output value indicates that an error has occurred during the execution of an SQL driver function. The status values at the outputs FctErCode, odbcFctErCode, odbcFctNr, sqlErCodes give further information on this matter.

Output fctWarning BOOL This output value indicates that a warning message has been shown during the execution of an SQL driver function. The status values at the outputs FctErCode, odbcFctErCode, odbcFctNr, sqlErCodes give further information on this matter.

Output debugActive BOOL This output value indicates if the commissioning mode is active.

Output fctErCode DWORD Error code of the SQL driver: error code of the SQL driver function

Output odbcFctNr DWORD Error code of the SQL driver: Number of the called ODBC

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 13

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Type Name Data type Description

function where the error has occurred

Output odbcFctErCode DWORD Error code of the SQL driver: Error code of the ODBC interface

Output sqlErCodes ARRAY[0..9] OF STRING

Error codes of the SQL driver: Error code from SQL server

4.2.3 ODK1500S_SQL_SetStatement

The block ODK1500S_SQL_SetStatement assumes all functions which are necessary for sending the SQL statements and receiving the possibly requested data. After a successful connection to the SQL database, the ODK1500S_SQL_Statement block can be executed to operate the database. This block can be called as often as desired to execute SELECT-, UPDATE-, INSERT- or DELETE statements. An instruction is operated asynchronously. Several PLC-OB cycles are run to process and finish the ODK1500S_SQL_SetStatement.

Figure 4-3: ODK1500S_SQL_SetStatement block

The SQL statements of the application consist of two parts:

SQL string: contains the SQL statement including dummies for the SQL arguments

SQL argument: here, the real data are defined

The block joins SQL string and SQL arguments again and transmits the complete SQL statement to the database.

Example SQL string:

SELECT year, test

FROM %s

WHERE titleid < %d

Whereat “%s“ and “%d“ are the dummies for the incoming arguments:

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 14

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

%s => “titles”

%d => 5

The full statement for the database would then be interpreted as follows:

SELECT year, test

FROM titles

WHERE titleid < 5

The arguments are entered for the corresponding dummies, but the length of the single arguments is limited to the according data type. In the special case of STRING, it is possible to use up to 254 characters for each argument. Please consider with the arguments that they are in the same order as the dummies. Errors are indicated as soon as the data type does not correspond to the dummy. The following table shows the corresponding dummies and data types.

Table 4-4: corresponding data types and dummies

Data types Place holders PLC data type

INTEGER %d ODK1500S_SQL_DataTypeInteger

SMALLINT %d ODK1500S_SQL_DataTypeSmallInteger

REAL %f ODK1500S_SQL_DataTypeReal

CHAR

(STRING) %s ODK1500S_SQL_DataTypeChar

The number of the dummies has to correspond to that of the arguments as well. To achieve conformity, it is necessary to use the four pre-defined PLC data types which correspond to the above mentioned data types. As the first information, the PLC data types contain the data type as a defined number, where „1“ stands for INTEGER, „2“ for SMALLINT, “4“ for REAL and “5“ for CHAR (STRING). The SQL data type DOUBLE with 64 Bit is changed into STEP 7 REAL data type with 32 Bit. As the second information, the value of the argument is stored in the corresponding data format. The following figure shows the SQL-PLC data type STRING.

Figure 4-4: PLC data type String

ATTENTION In STEP 7, strings are marked with '. However, SQL requires ' as well. Thus, to be able to represent a string in SQL, you have to put ‘ before and after the $’: ('$'String$'').

An SQL statement is transmitted with a rising edge at the input „REQ“. In case of a SELECT statement, the data requested from the database are read in addition.

Module parameter

Table 4-5: Parameter ODK1500S_SQL_SetStatement

Type Name Data type Description

Input REQ BOOL A rising edge of this input value activates the execution of the ODK function.

Input sqlString WSTRING SQL string, contains the SQL statement with the defined

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 15

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Type Name Data type Description

dummies for Integer, Small-Integer, Real and Char. The maximum length of the string is 4000 characters.

InOut sqlArgument VARIANT SQL argument: At this place, the data block has to be connected to the structure for the according SQL statement. This structure contains the data for the dummy from the SQL string.

Output DONE BOOL This output value indicates that the instruction has successfully terminated the execution of the ODK function.

Output BUSY BOOL This output value indicates that the instruction is still executing the ODK function.

Output ERROR BOOL This output value indicates that an error has occurred during the execution of the ODK function. The output value STATUS gives further information on this matter.

Output STATUS INT This output value gives information on possible error sources in case that an error has occurred during the execution of the ODK function.

Output fctError BOOL This output value indicates that an error has occurred during the execution of an SQL driver function. The status values at the outputs FctErCode, odbcFctErCode, odbcFctNr, sqlErCodes give further information on this matter.

Output fctWarning BOOL This output value indicates that a warning message has been shown during the execution of an SQL driver function. The status values at the outputs FctErCode, odbcFctErCode, odbcFctNr, sqlErCodes give further information on this matter.

Output debugActive BOOL This output value indicates if the commissioning mode is active.

Output fctErCode DWORD Error code of the SQL driver: error code of the SQL driver function

Output odbcFctNr DWORD Error code of the SQL driver: number of the called ODBC-function where an error has occurred

Output odbcFctErCode DWORD Error code of the SQL driver: Error code of the ODBC interface

Output sqlErCodes ARRAY[0..9] OF STRING

Error codes of the SQL driver: Error code from SQL server

ATTENTION The maximum SQL statement length is limited to 8000 characters. For example: 600 characters are used in SQL string and all the characters of the arguments are added. If the data type Char with a length of 40 characters is used in the argument, the total length is 640 characters for the SQL statement.

The following figure shows a data block with SQL strings for the four possible SQL statements. One string can be connected to the input „SQL string“.

Figure 4-5: Data block with SQL strings

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 16

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

The following figure shows a data block with SQL arguments for the four possible SQL statements. These ones can be connected to the input “SQL argument“.

Figure 4-6: data blocks with SQL arguments

ATTENTION The data block, which is connected to the input parameter SQL ARGUMENT, must not have the attribute „optimized block access“!

4.2.4 ODK1500S_SQL_GetData

The block “ODK1500S_SQL_GetData” writes the data, which have been requested by a previous SQL select statement, from the database to a data block. To be able to write data to a data block, it is necessary to have successfully executed the block “ODK1500S_SQL_SetStatement” by a select statement before.

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 17

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Figure 4-7: ODK1500S_SQL_GetData block

The returned data are arranged in a sequence. For example:

SELECT year, test1, test2

FROM %s

WHERE titleid < %d

Table 4-6: Example: Returned data sequence

year test1 test2

(1.)1982 (2.)string1 (3.)WinAC

(4.)2011 (5.)string2 (6.)WinAC

The PLC data types in the receiver block have to be available in the same sequence as the data made available from the function block. Otherwise, an error code will be indicated. If too little or too many PLC data types are made available, an error code will be indicated as well. The following SQL data types are supported by this application:

Table 4-7: supported SQL data types

SQL Data type PLC data types STEP 7

sample project Place holder

SQL CHAR ODK1500S_SQL_DataTypeChar %s

SQL NUMERIC ODK1500S_SQL_DataTypeChar %s

SQL DECIMAL ODK1500S_SQL_DataTypeChar %s

SQL VARCHAR ODK1500S_SQL_DataTypeChar %s

SQL INTEGER ODK1500S_SQL_DataTypeInteger %d

SQL SMALLINT ODK1500S_SQL_DataTypeSmallInteger %d

SQL FLOAT ODK1500S_SQL_DataTypeReal %f

SQL REAL ODK1500S_SQL_DataTypeReal %f

SQL DOUBLE ODK1500S_SQL_DataTypeReal

!avoid as far as possible! %f

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 18

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

ATTENTION The SQL data types DOUBLE and REAL are 64Bit data types. The SQL driver changes them into STEP 7 real data type with 32Bit. Due to the change of a 64Bit value into a 32Bit value, this one loses accuracy.

Module parameter

Table 4-8: Parameter ODK1500S_SQL_GetData

Type Name Data type Description

Input REQ BOOL A rising edge of this input value activates the execution of the ODK function.

InOut sqlReceivedData

VARIANT At this place, a data block with the structure for the returned data has to be connected.

Output DONE BOOL This output value indicates that the instruction to execute the ODK function has been terminated successfully.

Output BUSY BOOL This output value indicates that the ODK function is still being executed.

Output ERROR BOOL This output value indicates that an error has occurred during the execution of the ODK function. The output value STATUS shows further information on this matter.

Output STATUS INT This output value gives information on possible sources of the error if an error has occurred during the execution of the ODK function.

Output fctError BOOL This output value indicates that an error has occurred during the execution of an SQL driver function. The status values at the outputs FctErCode give further information on this matter.

Output fctWarning BOOL This output value indicates that a warning message has been shown during the execution of an SQL driver function. The status values at the outputs FctErCode give further information on this matter.

Output fctErCode DWORD Error code of the SQL driver: error code of the SQL driver function

The following figure shows a data block with a possible structure for returned data. This one can be connected to the parameter „sqlReceivedData“.

Figure 4-8: Data block for returned data

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 19

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

ATTENTION The data block which is connected to the input parameter sqlReceivedData must not have the attribute „optimized block access“!

The maximum quantity of values which can be returned in a request is limited by the maximum size of a non-optimized data block (64 Kbyte) and by a maximum number of 1000 values.

4.2.5 ODK1500S_SQL_GetBlob

If the return values of a SELECT statement contain a BLOB value, the returned data can be output by means of the ODK1500S_SQL_GetBlob at the parameter „sqlReceivedBlob“. It is necessary to connect a data block which contains an according Blob-PLC data type. Exception is made for the data type CHAR (S7 STRING). The data type STRING in combination with a BLOB value is not supported. The PLC data types contained in the data block have to be present in the same order as the data of the binary BLOP stream are made available. If the order is not the same or if the data type is different, the values separated from the BLOP stream will not be correct. In one BLOB stream, for example, 25 integer values (each one with 4 byte) are transmitted. However, in the belonging data block for the BLOB values, small integer values (each one with 2 byte) are made available. After that, the BLOB stream is divided up into values of 2 byte each, with the result that the separated data represent wrong values. If integer values are used with 4 byte, the represented values are correct. At the end of each listed BLOB stream in the data block, the PLC data type „END_OF_BLOB” has to be used.

Figure 4-9: ODK1500S_SQL_GetBlob block

ATTENTION At the end of each listed BLOB stream in the data block, the PLC data type END_OF_BLOB has to be used.

The data type string is not supported in combination with the BLOB values.

A binary BLOB stream is read by the ODK1500S_SQL_GetBlob and then separately written to a data block. How the binary BLOB stream is separated depends on the PLC data type which is used in the data block as well as on the PLC data type END_OF_BLOB at the end of each BLOB stream.

If a SELECT statement contains a BLOB stream and standard data types, the following order is expected:

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 20

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

SELECT titleid, test1, BLOB1, test2, BLOB2, test3

FROM table

WHERE titleid < 100

The order of the received standard data types at the interface SQL_RECEIVED_DATA is as follows:

titleid, test1, test2, test3

The received BLOB data are available in the following order at the interface SQL_RECEIVED_BLOB:

BLOB1, BLOB2

At the end of BLOB1 and BLOB2, the PLC data type END_OF_BLOB has always to be used.

The returned BLOB values are provided in a certain order, e.g.:

Table 4-9: Example: returned BLOB value order

BLOB1 BLOB2

(1.)separated STREAM1

END_OF_BLOB

(2.) separated STREAM2

END_OF_BLOB

An SQL database supports several types of BLOB values. The following table gives an overview of the types that are supported by this application.

Table 4-10: BLOB_Types supported by SQL driver

SQL BLOB-TYPEN MySQL

SQL_BINARY Binary

SQL_VARBINARY Varbinary

SQL_LONGVARBINARY

tinyblob

blob

mediumblob

longblob

ATTENTION The maximum quantity of data which can be used in a complete stream (e.g. BLOB1 and BLOB2) is limited by the maximum quantity of data (64Kbyte) which is available in a non-optimized data block and by the maximum number of 30000 values being available. If the stream exceeds 64Kbytes, the data will not be transmitted (BLOB values and standard values) from the database.

Module parameter

Table 4-11: Parameter ODK1500S_SQL_GetBlob

Type Name Data type Description

Input REQ BOOL A rising edge of this input value activates the execution of the ODK function.

InOut sqlReceivedBlob VARIANT At this place, a data block with the structure for the returned data has to be connected.

Output DONE BOOL This output value indicates that the instruction to execute the ODK function has been terminated successfully.

Output BUSY BOOL This output value indicates that the ODK function is still being

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 21

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Type Name Data type Description

executed.

Output ERROR BOOL This output value indicates that an error has occurred during the execution of the ODK function. The output value STATUS shows further information on this matter.

Output STATUS INT This output value gives information on possible sources of the error if an error has occurred during the execution of the ODK function.

Output fctError BOOL This output value indicates that an error has occurred during the execution of an SQL driver function. The status values at the outputs FctErCode give further information on this matter.

Output fctWarning BOOL This output value indicates that a warning message has been shown during the execution of an SQL driver function. The status values at the outputs FctErCode give further information on this matter.

Output fctErCode DWORD Error code of the SQL driver: error code of the SQL driver function

The following figure shows a data block with a possible structure for a returned BLOB stream. This one can be connected to the parameter „sqlReceivedBlob“.

Figure 4-10: Data block for returned BLOB data

ATTENTION The data block, which is connected to the input parameter sqlReceivedBlob, must not have the attribute „optimized block access“!!

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 22

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

4.2.6 ODK1500S_SQL_Disconnect

With a rising edge at the input „REQ“ of the block ODK1500S_SQL_Disconnect, the connection to the database is disconnected and the commissioning mode is terminated, if necessary.

If a connection to an SQL database is not required anymore, it has to be closed again. If the connection is not closed again, the established connections in the SQL server will not be terminated. This can lead to errors during the establishment of new connections.

Figure 4-11: ODK1500S_SQL_Disconnect block

Module parameter

Table 4-12: Parameter ODK1500S_SQL_Disconnect

Type Name Data type Description

Input REQ BOOL A rising edge of this input value activates the execution of the ODK function

Output DONE BOOL This output value indicates that the instruction to execute the ODK function has been terminated successfully

Output BUSY BOOL This output value indicates that the ODK function is still being executed.

Output ERROR BOOL This output value indicates that an error has occurred during the execution of the ODK function. The output value STATUS shows further information on this matter.

Output STATUS INT This output value gives information on possible sources of the error if an error has occurred during the execution of the ODK function.

Output fctError BOOL This output value indicates that an error has occurred during the execution of an SQL driver function. The status values at the outputs FctErCode, odbcFctErCode, odbcFctNr, sqlErCodes give further information on this matter.

Output fctWarning BOOL This output value indicates that a warning message has been shown during the execution of an SQL driver function. The status values at the outputs FctErCode, odbcFctErCode, odbcFctNr, sqlErCodes give further information on this matter.

Output fctErCode DWORD Error code of the SQL driver: error code of the SQL driver function

Output odbcFctNr DWORD Error code of the SQL driver: Number of the called ODBC-function where an error has occurred

Output odbcFctErCode DWORD Error code of the SQL driver: Error code of the ODBC

4 Function mechanisms

4.2 Description of the function blocks

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 23

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Type Name Data type Description

interface

Output sqlErCodes ARRAY[0..9] OF STRING

Error codes of the SQL driver: Error code from SQL server

4.2.7 ODK1500S_SQL_Unload

This block makes it possible to manually unload the SQL driver DLL. Normally, this is not necessary. Exception: If a new version of the SQL driver DLL shall be installed, it has to be unloaded before.

Figure 4-12: ODK1500S_SQL_Unload

Module parameter

Table 4-13: Parameter ODK1500S_SQL_Unload

Type Name Data type

Description

Input REQ BOOL A rising edge activates the loading of the SQL driver DLL.

Output DONE BOOL Indicates that the instruction to load the SQL driver DLL has been terminated successfully.

Output BUSY BOOL Indicates that the SQL driver DLL is still being loaded.

Output ERROR BOOL Indicates that an error has occurred while loading the SQL driver DLL. STATUS shows further information on the possible cause of the error.

Output STATUS INT Gives information on possible sources of the error if an error has occurred while loading the SQL driver DLL.

5 Installation and commissioning

5.1 Installation and commissioning of the MSSQL demo database

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 24

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

5 Installation and commissioning This chapter describes the installation and commissioning of the ODK1500S-SQL driver as well as the installation of the MSSQL database which belongs to the S7-sample project.

5.1 Installation and commissioning of the MSSQL demo database

The following installation instructions help to configure the demo database being supplied with the ODK1500S_SQL driver as well as to install an MS-SQL server.

5.1.1 Installation MSSQL Server 2014 Express

The database system “Microsoft SQL 2014 Server Express“ is installed on the database server. As an alternative, „MSSQL 2008 R2 Server Express“ can be used as well. To install the database, the file „SQLEXPRWT_x64_ENU“ is executed. Under the item installation a „New SQL Server stand-alone installation“ is selected:

Figure 5-1: Installation center

The next steps are self-explanatory. Here, the license conditions have to be accepted and you have to click continue until the item “feature selection”.

As demonstrated in the following figure, at least the following components have to be selected:

5 Installation and commissioning

5.1 Installation and commissioning of the MSSQL demo database

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 25

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Figure 5-2: Feature Selection

The named instance is kept for the sample project:

Figure 5-3: Named instance

With the server configuration, the network service is selected. For the sample project, the SQL server service is sufficient:

5 Installation and commissioning

5.1 Installation and commissioning of the MSSQL demo database

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 26

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Figure 5-4: Server Configuration

Making a Windows and a server login possible, you have to select the mixed service in the following figure during the configuration of the data blocks. Furthermore, a server password as well as a server administration has to be defined. The settings for errors and administration reports, which will be available in the next window, are not used for this example. After the summary, the SQL server is installed by pushing the key “install”.

Figure 5-5: Database Engine Configuration

5 Installation and commissioning

5.1 Installation and commissioning of the MSSQL demo database

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 27

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

5.1.2 Configuration of the SQL server

After the SQL server has been installed, the communication to the runtime PC (S7-Software Controller) has to be configured. For this, the SQL server configuration manager has to be opened first. This is done via StartProgram Microsoft SQL Server 2014 configuration tools SQL Server configuration. After that, you can see under the menu item SQL server services which services are executed. Doing so, please consider that the SQL server service is active:

Figure 5-6: SQL server services

Then, the TCP/IP connection is activated and configured. Via SQL server network configuration -> protocols for SQLEXPRESS -> TCP/IP -> right mouse key -> properties, this step can be executed. Under the tab protocol, the TCP/IP communication can be activated. Under IP addresses, a static IP address as well as the Port 2301 has to be entered. After that, the service hast to be started again.

Figure 5-7: TCP/IP settings

Note The settings only become effective when the according service has been started again.

5 Installation and commissioning

5.1 Installation and commissioning of the MSSQL demo database

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 28

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

5.1.3 Restoration of the sample scheme

To restore the supplied demo database, the SQL Server Management Studio has to be started. Then, the Windows authentication has to be selected to log in. A password is not necessary in this case. Click the right mouse key on “database” to select the option for restoration:

Figure 5-8 Restoration of the demo database 1

After the name as well as the path indication of the archived database has been selected, the restoration can be confirmed by pushing „OK“. The following figure shows the setting options.

Figure 5-9: Recovery of the demo database 2

5 Installation and commissioning

5.1 Installation and commissioning of the MSSQL demo database

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 29

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

5.1.4 Generation of a login to the SQL server

The connection to the SQL server can be realized via the Windows authentication or via an SQL server authentication. For a remote connection via TCP/IP, the SQL server authentication is required. For this, a user login has to be generated. To generate a login, you have to open the SQL Server Management Studio and select the Windows authentication for the login:

Figure 5-10: Login with Windows authentication

Then, open the folder Security in the left part of the window. Click with the right mouse key on Login -> new Login and generate a new login.

In the open window, you have to select the SQL server authentication. Then, the login name and the password are defined. As the standard database, the restored database is selected in the example application (DEMO_MSSQL_DATABASE):

5 Installation and commissioning

5.1 Installation and commissioning of the MSSQL demo database

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 30

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Figure 5-11: Generation of a new login

Under the menu item „User Mapping“, please activate the following settings:

5 Installation and commissioning

5.2 Installation and commissioning of the SQL driver on the runtime PC

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 31

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Figure 5-12: Settings of the user mapping

After the new login has been defined, you can choose between the Windows and the SQL server authentication with the next establishment of the connection.

5.2 Installation and commissioning of the SQL driver on the runtime PC

In the following you can find a description of the installation of the ODK1500S-SQL driver on the runtime PC (S7-1500 Software Controller).

5.2.1 Installation of the SQL driver DLL

The installation of the SQL driver for the SQL database connection is limited to the execution of the DLL-Install.bat file. During the installation, the DLL has to be located in the same directory as the Install.bat file.

5.2.2 Parameterization of the ODBC driver

The ODBC driver is used to establish the connection to the SQL database.

This one has to be configured once. Doing so, you have to consider whether the SQL server is running on a 64-Bit operating system or on a 32-Bit operating system. We recommend executing the parameterization of the ODBC only after having generated the SQL database.

In general, the ODBC driver is installed on the runtime PC under ControlPanel->System and Security->Administrative Tools->Data Sources (ODBC). Depending

5 Installation and commissioning

5.2 Installation and commissioning of the SQL driver on the runtime PC

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 32

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

on the configuration of the operating system of the runtime PC, the 32-Bit or 64-Bit application is shown as a shortcut here.

To execute the correct application of the ODBC configuration, we recommend proceeding as follows:

SQL Server runs on a 32-Bit system:

Execute Windows->system32->odbcad32.exe

SQL Server runs on a 64-Bit system:

Execute Windows->SysWOW64->odbcad32.exe

Now, you can generate a new interface under the tab “System DSN“:

Figure 5-13: ODBC driver configuration 1

After having pushed the „Add“ button, you can select a new SQL server data source:

Figure 5-14: ODBC driver configuration 2

Now, the actual configuration follows. In the first dialog, you select the DSN name, a description as well as the SQL server. For the demo database, the system DSN name should be defined as follows:

5 Installation and commissioning

5.2 Installation and commissioning of the SQL driver on the runtime PC

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 33

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Figure 5-15: ODBC driver configuration 3

After that, the SQL server authentication has to be selected and the login data for the demo database have to be indicated. For this, the preset user name „winacsql“ and the password „1234“ have to be selected:

Figure 5-16: ODBC driver configuration 4

ATTENTION To access to the SQL database via TCP/IP, it is necessary to define a user in the database management studio before.

Via the button „Client Configuration“, you have to check the settings which should have already been set to TCP/IP before and the previously selected SQL server should be indicated:

5 Installation and commissioning

5.2 Installation and commissioning of the SQL driver on the runtime PC

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 34

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Figure 5-17: ODBC driver configuration 5

The next step can be skipped by „Next“ and then you can finish the configuration by pushing the button „Finish“:

Figure 5-18: ODBC driver configuration 6

After having finished the parameterization, a summary of the ODBC configurations is indicated where the connection to the SQL Server can be checked by pushing the button „Test Data Source…“. With a successful configuration, the following message appears:

Figure 5-19: ODBC driver configuration 7

6 Operation of the application

6.1 Use of the example application

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 35

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

6 Operation of the application

6.1 Use of the example application

With the ODK1500S-SQL driver, a tested example application is supplied.

This one consists of the following components:

STEP 7 V13 SP1 professional sample project

MSSQL demo database „DEMO_MSSQL_DATABASE“

First, install and configure the demo database and the SQL driver as described in chapter Installation and commissioning.

Dearchive the supplied STEP 7 sample project and adapt the hardware configuration to your applied components and settings, if necessary. After that, load the project to your controller.

6 Operation of the application

6.1 Use of the example application

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 36

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

6.1.1 Structure of the STEP 7 example project

Figure 6-1: Structure of the example project

6 Operation of the application

6.1 Use of the example application

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 37

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

The sample project consists of the ODK1500S_SQL- function blocks, PLC-data types as well as interface data blocks where, among others, the SQL strings and SQL arguments can be stored. In the following you can find a description of the single components:

Organization blocks

Main (OB1): Call of FB_SQL_CALL

Diagnostic error interrupt (OB82): Sets the request bit for the automatic loading of the SQL driver DLL after, for example, Windows has been restarted.

Function blocks

FB_SQL_CALL: Multi instance call of the ODK1500S-SQL function blocks

ODK1500S_SQL_Load, ODK1500S_SQL_Connect, ODK1500S_SQL_SetStatement, ODK1500S_SQL_GetData, ODK1500S_SQL_GetBlob, ODK1500S_SQL_Disconnect, ODK1500S_SQL_Unload: ODK1500S-SQL function blocks (see chapter 4.2)

Data blocks

FB_SQL_Call_DB: Instance of the FB_SQL_CALL

ODK1500S_Startup_DB: contains trigger bit for the automatic loading of the SQL driver DLL

ODBC_LOGIN_DATA: Here, the login data for the ODBC interface is indicated

SQL_ARGUMENTS: Here, the SQL arguments are indicated

SQL_STRINGS: Here, the SQL strings for the SQL statements are indicated

SQL_SELECT_DB_DATA: Here, the data of the database, which are returned by an SQL select statement, are stored

SQL_FETCHED_BLOB_INT: Here, the Blob data of the database, which are returned by an SQL select statement, are stored

SQL_CONROL_DB: central control and watch data block in the example application

PLC data types

ODK1500S_SQL_DataTypeChar, ODK1500S_SQL_DataTypeInteger, ODK1500S_SQL_DataTypeReal, ODK1500S_SQL_DataTypeSmallInteger, ODK1500S_SQL_ENDBLOB: SQL data types (these ones have to be used in the block SQL_ARGUMENTS)

ODK1500S_SQL_ErrorStruct, ODK1500S_SQL_ErrorStructSmall: Error structure - contains error information on the ODK1500S-SQL function blocks

Watch table

ODK1500S_ControlTable: Watch table to control the example application (contains variable from the SQL_CONTROL_DB)

6 Operation of the application

6.1 Use of the example application

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 38

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

6.1.2 Loading of SQL driver DLL

Before you can use the ODK1500S-SQL driver, it is necessary to load the SQL driver DLL from the software controller.

The SQL driver DLL is automatically loaded in the sample project as soon as there is a connection between the software controller and Windows. The trigger for this is set in OB82 and reset by the block ODK1500S_SQL_Load after the DLL has been loaded.

Only when the SQL driver DLL shall be exchanged by a new version it might become necessary to unload the loaded DLL, to install the new version of the DLL and then manually load the new version.

To manually load the DLL, please proceed as follows:

Open the watch table ODK1500S_ControlTable

Modify the bit "SQL_CONTROL_DB.ODK1500S_SQL_Load.REQ“ to 1

The function block ODK1500S_SQL_Load is called in the FB_SQL_Call.

6.1.3 Establish the connection to the database

Before transmitting the SQL statements to the database, you have to establish once a connection to the database or to the SQL server.

Doing so, please proceed as follows:

Open the watch table ODK1500S_ControlTable

Modify the bit "SQL_CONTROL_DB.ODK1500S_SQL_Connect.REQ“ to 1

The function block ODK1500S_SQL_Connect is called in the FB_SQL_Call.

6.1.4 Transmission of SQL statements

The general proceeding to transmit SQL statements consists of two steps:

1. Select the desired SQL statement

2. Select the request bit of the SetStatement function

For this, please open the watch table ODK1500S_ControlTable first:

Figure 6-2: Watch table „ODK1500S_ControlTable“

For the example application, the SQL statements being defined in the data blocks SQL_STRINGS and SQL_ARGUMENTS are used.

Note For the correct functioning of the example application, please ensure that only one SQL statement is selected!

6 Operation of the application

6.1 Use of the example application

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 39

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Transmission of an SQL SELECT statement

If necessary, reset the selection of a different SQL statement

Modify the bit "SQL_CONTROL_DB.SQL_Select_Data“ (or "SQL_CONTROL_DB.SQL_Select_Blob“) to 1

Modify the bit "SQL_CONTROL_DB.ODK1500S_SQL_SetStatement.REQ“ to 1

The blocks ODK1500S_SQL_SetStatement and ODK1500S_SQL_GetData or ODK1500S_SQL_GetBlob are called in the FB_SQL_Call.

After the successful execution, the bit "SQL_CONTROL_DB.ODK1500S_SQL_SetStatement.REQ“ is reset again and the data, which have been requested and returned by the database, are stored in the data block SQL_SELECT_DB_DATA or in the data block SQL_FETCHED_BLOB_INT.

Transmission of an SQL UPDATE, INSERT or DELETE statement

If necessary, reset the selection of a different SQL statement

According to the desired SQL statement, modify the bit "SQL_CONTROL_DB.SQL_Insert“ or "SQL_CONTROL_DB.SQL_Update“ or "SQL_CONTROL_DB.SQL_Delete“ to 1

Modify the bit "SQL_CONTROL_DB.ODK1500S_SQL_SetStatement.REQ“ to 1

The function block ODK1500S_SQL_SetStatement is called in the FB_SQL_Call. After the successful execution, the bit "SQL_CONTROL_DB.ODK1500S_SQL_SetStatement.REQ“ is reset again.

6.1.5 Disconnect the connection to the database

Open the watch table ODK1500S_ControlTable

Modify the bit "SQL_CONTROL_DB.ODK1500S_SQL_Disconnect.REQ“ to 1

The function block ODK1500S_SQL_Disconnect is called in the FB_SQL_Call. After the successful execution, the bit "SQL_CONTROL_DB.ODK1500S_SQL_Disconnect.REQ“ is reset again.

6.1.6 Unload SQL driver DLL

A manual unloading is only necessary in case of exchanging the DLL. Doing so, please proceed as follows:

Open the watch table ODK1500S_ControlTable

Modify the bit "SQL_CONTROL_DB.ODK1500S_SQL_Unload.REQ“ to 1

The function block ODK1500S_SQL_Unload is called in the FB_SQL_Call.

6.1.7 Error analysis

If the execution of an SQL function block was not successful, the error codes which are returned by the blocks, can be monitored online in the data block SQL_CONTROL_DB.

For detailed information concerning the error codes, please refer to chapter 7.

6 Operation of the application

6.2 Adaption of the example application to own requirements

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 40

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

6.2 Adaption of the example application to own requirements

We recommend using the STEP 7 sample project at first and then adapt it to your own requirements.

In the following you can find a description of the necessary steps:

6.2.1 Adaption of the ODBC-Login data

For this, please enter in the data blocks ODBC_LOGIN_DATA the login data you have defined for the connection to you database.

Note The login data have to correspond to those ones you have entered with the parameterization of the ODBC driver. Please refer to chapter 5.2.2.

6.2.2 Adaption of the SQL statements

As described in chapter 4.2.3, SQL statements consist of two parts:

SQL string: contains the SQL statement including dummies for the SQL arguments

SQL argument: here, the data are defined

Please enter in the data block SQL_STRINGS your SQL statements including the dummies for the arguments.

ATTENTION In STEP 7, strings are marked with '. However, SQL requires ' as well. Thus, to be able to represent a string in SQL, you have to put ‘ before and after the $’: ('$'String$'').

In the data block SQL_ARGUMENTS you define the SQL data in the same order as in the SQL string. Doing so, you have to use the pre-defined PLC data types for each SQL data type.

Both data block are transmitted to the block ODK1500S_SQL_SetStatement.

ATTENTION The maximum SQL statement length is limited to 8000 characters. For example: 600 characters are used in SQL string and all the characters of the arguments are added. If the data type Char with a length of 40 characters is used in the argument, the total length is 640 characters for the SQL statement.

If you use the SQL select statements, please adapt accordingly the order and the structure of the data in the data block SQL_SELECTDB_DATA or SQL_FETCHED_BLOB_INT.

7 Error codes

7.1 Overview

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 41

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

7 Error codes

7.1 Overview

The ODK1500S-SQL driver provides different types of error codes:

ODK error codes according to ODK 1500S

Error codes of the ODK1500S-SQL driver

Table 7-1: Overview of error types for ODK1500S-SQL driver

Error type Error table Error source

ODK Error Codes Table 7-2: ODK Error Codes ODK-DLL: 1500S ODK

SQL Error Codes Table 7-6: SQL Error Codes ODBC/SQL server

ODBC Function Error Code Table 7-5: ODBC Function

Error Codes ODK-DLL: ODBC class

ODBC Function Number Table 7-4: ODBC Function

Number ODK-DLL: ODBC class

Function Error Code Table 7-3: Function Error

Codes ODK DLL: ODK function

Figure 7-1: Flowchart error codes

7 Error codes

7.2 Error Codes ODK1500S

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 42

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

7.2 Error Codes ODK1500S

The ODK1500S-SQL driver has been developed with the ODK1500S (Open Development Kit). The ODK can also generate error codes which are returned to the function blocks at the output „STATUS“.

Table 7-2: ODK Error Codes

Error Code (HEX)

Description

0 Success

0x8090

(Un)Load the ODK driver

ODK application could not be (un)loaded. An error occurred during execution of the "OnLoad()" / "OnUnload()" function.

Execute the ODK driver

ODK application could not be executed. An error occurred during execution.

0x8092 ODK application could not be loaded because the library name is invalid.

0x8093 ODK application could not be loaded because the ODK application could not be found. Check the file name and path of the file.

0x8094 ODK application could not be loaded. The ODK application was created for the Windows user context, but no user is logged on.

0x8095

ODK application could not be loaded due to the following reasons:

• The DLL file not an ODK application

• An attempt has been made to load 64-bit application into a 32-bit system

• Dependencies on other Windows DLL files could not be resolved (ensure that the release build of the ODK application is used.

0x8096

Execute the ODK driver

ODK application could not be executed because the ODK application was not loaded or unloading is not yet finished.

Unload the ODK driver

ODK application could not be unloaded because the ODK application was not loaded or unloading is not yet finished.

0x8097 ODK application is already loaded.

0x8098

Load the ODK driver

ODK application could not be loaded because the ODK application is currently being unloaded.

Execute the ODK driver

ODK application could not be executed because the function is not supported.

0x8099 ODK application could not be executed because the maximum amount of input data (declarations with "In" and "InOut") was exceeded

0x809A ODK application could not be executed because the maximum amount of input data (declarations with "Out" and "InOut") was exceeded

0x809B The function returns an invalid value (a value between 0001 and 6FFF is allowed)

0x809C

Function uses an invalid data type:

• IN_DATA

• INOUT_DATA

• OUT_DATA

0x80A4

Load the ODK driver

ODK application could not be loaded.

Start the ODK service manually or restart Windows.

Execute the ODK driver

7 Error codes

7.3 Error Codes ODK1500S SQL driver

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 43

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Error Code (HEX)

Description

ODK application could not be executed for the following reasons:

• The "<STEP7Prefix>_Unload" instruction was executed during a function execution. The function execution was aborted at the CPU end. Windows terminates the execution of the function normally. No return value is sent to the CPU.

Wait until the "<STEP7Prefix>_Unload" instruction has ended. Then load the ODK application again.

• Windows is not available

• ODK service is not running

Start the ODK service manually or restart Windows.

Unload the ODK driver

ODK application could not be unloaded for the following reasons:

• Windows is not available

• ODK service is not running

Start the ODK service manually or restart Windows.

0x80C2 ODK application could not be (un)loaded. There is currently not enough memory available at the Windows end.

0x80C3 ODK application could not be (un)loaded. The CPU currently does not have enough memory.

7.3 Error Codes ODK1500S SQL driver

7.3.1 Function Error Codes

These codes describe errors of the ODK functions of the SQL driver. For example, if a data type in a data block does not correspond to the read value of the database.

Table 7-3: Function Error Codes

Error-Code

Description

9500 Wrong format specification in STRING for ARGUMENT

9502 Buffer Overflow in ARGUMENT read

9503 Read S7 ARGUMENT TYPE failed

9504 Read S7 ARGUMENT failed by INT

9505 Read S7 ARGUMENT failed by SMINT

9506 Read S7 ARGUMENT failed by DOUBLE

9507 Read S7 ARGUMENT failed by REAL

9508 Read S7 ARGUMENT failed by STRING

9509 Wrong S7 ARGUMENT TYPE not defined

9510 No PRINTF ARGUMENT in STRING for reserved ARGUMENT

9520 BUFFEROVERFLOW in value write

9521 READ S7 VALUETYPE failed

9522 Write S7 VALUE failed by INT

9523 Write S7 VALUE failed by SMINT

9524 Write S7 VALUE failed by DOUBLE

9525 Write S7 VALUE failed by REAL

7 Error codes

7.3 Error Codes ODK1500S SQL driver

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 44

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Error-Code

Description

9526 Write S7 VALUE failed by STRING

9527 Wrong S7 VALUE TYPE not defined

9528 No S7 VALUETYPE for SQLVALUETYPE available

9529 Non-conforming VALUETYPE from SQLSERVER to S7 DATABLOCK, expected INT

9530 Non-conforming VALUETYPE from SQLSERVER to S7 DATABLOCK, expected SMINT

9531 Non-conforming VALUETYPE from SQLSERVER to S7 DATABLOCK, expected DOUBLE

9532 Non-conforming VALUETYPE from SQLSERVER to S7 DATABLOCK, expected REAL

9533 Non-conforming VALUETYPE from SQLSERVER to S7 DATABLOCK, expected STRING

9555 Not defined PRINTF ARGUMENT in STRING

9559 Cant verify query the value

9561 Buffer overflow at fetched BLOB columns

9562 Can’t get the length of string at BLOB separating

9563 Buffer overflow in BLOB data block

9564 Read S7 value type failed BLOB

9565 Write S7 value failed by INT BLOB

9566 Write S7 value failed by SMINT BLOB

9567 Write S7 value failed by DOUBLE BLOB

9568 Write S7 value failed by REAL BLOB

9569 Wrong S7 value type, not defined at BLOB data block

9570 Buffer overflow at write value in one BLOB stream

9571 Zero pointer in BLOB stream

7.3.2 ODBC Function Number

Description of the ODBC function called by SQL driver in case of an error.

Table 7-4: ODBC Function Number

Function code Function description

9000 SQL ALLOC ENVIRONMENT HANDLE

9001 ODBC VERSION ENVIRONMENT ATTRIBUTE

9002 SQL ALLOC CONNECTION HANDLE

9003 CONNECT DATA SOURCE

9004 SQL ALLOC ARGUMENT HANDLE

9005 BUILT SQL STRING

9006 COUNT OF COL

9007 DESCRIBE COL TYPE

9008 BIND COLUMN WHITH VALUETYPE

9009 FETCH ARGUMENT

9010 FREEING ARGUMENT HANDLE

9011 CLOSE CONECTION

9012 FREEING CONNECTION HANDLE

7 Error codes

7.3 Error Codes ODK1500S SQL driver

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 45

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Function code Function description

9013 FREEING ENVIRONMENT HANDLE

7.3.3 ODBC Function Error Code

These codes describe errors when using the ODBC class. The ODBC class is the interface between SQL driver and database.

Table 7-5: ODBC Function Error Codes

Status Description

0000 ODBC FUNCTIONRET ok

8501 ODBC SQL OBJECT CALL initialization failed

8502 ODBC SQL OBJECT call execution failed

8503 ODBC SQL OBJECT call FETCH failed

8504 ODBC SQL OBJECT call CLOSE DATABASE failed

8505 ODBC FETCH ODK buffer Overflow

8506 undefined sql value type during create column type

8507 Sql unknown database column type

8508 Something wrong by sql database in character set

8509 No data existing

8510 Error in SQLGETDIAGREC

8511 To long STRING CHAR in SQL DB

8512 Database already connected

8513 BLOB size too big for data block in STEP 7

8514 Undefine SQL value type during fetch BLOB SQL data

8550 Success with info

8551 No data

8552 Still executing

8553 Need data

7.3.4 SQL Error Codes

These codes describe errors and notes sent by the SQL server or ODBC driver. These codes are only read by the SQL driver.

Table 7-6: SQL Error Codes

Status Description

01000 General warning

01001 Cursor operation conflict

01002 Disconnect error

01003 NULL value eliminated in set function

01004 String data, right truncated

01006 Privilege not revoked

01007 Privilege not granted

01S00 Invalid connection string attribute

01S01 Error in row

01S02 Option value changed

7 Error codes

7.3 Error Codes ODK1500S SQL driver

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 46

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Status Description

01S06 Attempt to fetch before the result set returned the first rowset

01S07 Fractional truncation

01S08 Error saving File DSN

01S09 Invalid keyword

07001 Wrong number of parameters

07002 COUNT field incorrect

07005 Prepared statement not a cursor-specification

07006 Restricted data type attribute violation

07009 Invalid descriptor index

07S01 Invalid use of default parameter

08001 Client unable to establish connection

08002 Connection name in use

08003 Connection does not exist

08004 Server rejected the connection

08007 Connection failure during transaction

08S01 Communication link failure

21S01 Insert value list does not match column list

21S02 Degree of derived table does not match column list

22001 String data, right truncated

22002 Indicator variable required but not supplied

22003 Numeric value out of range

22007 Invalid date time format

22008 Date time field overflow

22012 Division by zero

22015 Interval field overflow

22018 Invalid character value for cast specification

22019 Invalid escape character

22025 Invalid escape sequence

22026 String data, length mismatch

23000 Integrity constraint violation

24000 Invalid cursor state

25000 Invalid transaction state

25S01 Transaction state

25S02 Transaction is still active

25S03 Transaction is rolled back

28000 Invalid authorization specification

34000 Invalid cursor name

3C000 Duplicate cursor name

3D000 Invalid catalog name

3F000 Invalid schema name

40001 Serialization failure

40002 Integrity constraint violation

40003 Statement completion unknown

7 Error codes

7.3 Error Codes ODK1500S SQL driver

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 47

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Status Description

42000 Syntax error or access violation

42S01 Base table or view already exists

42S02 Base table or view not found

42S11 Index already exists

42S12 Index not found

42S21 Column already exists

42S22 Column not found

44000 WITH CHECK OPTION violation

HY000 General error

HY001 Memory allocation error

HY003 Invalid application buffer type

HY004 Invalid SQL data type

HY007 Associated statement is not prepared

HY008 Operation canceled

HY009 Invalid use of null pointer

HY010 Function sequence error

HY011 Attribute cannot be set now

HY012 Invalid transaction operation code

HY013 Memory management error

HY014 Limit on the number of handles exceeded

HY015 No cursor name available

HY016 Cannot modify an implementation row descriptor

HY017 Invalid use of an automatically allocated descriptor handle

HY018 Server declined cancel request

HY019 Non-character and non-binary data sent in pieces

HY020 Attempt to concatenate a null value

HY021 Inconsistent descriptor information

HY024 Invalid attribute value

HY090 Invalid string or buffer length

HY091 Invalid descriptor field identifier

HY092 Invalid attribute/option identifier

HY095 Function type out of range

HY096 Invalid information type

HY097 Column type out of range

HY098 Scope type out of range

HY099 Nullable type out of range

HY100 Uniqueness option type out of range

HY101 Accuracy option type out of range

HY103 Invalid retrieval code

HY104 Invalid precision or scale value

HY105 Invalid parameter type

HY106 Fetch type out of range

HY107 Row value out of range

7 Error codes

7.3 Error Codes ODK1500S SQL driver

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 48

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Status Description

HY109 Invalid cursor position

HY110 Invalid driver completion

HY111 Invalid bookmark value

HYC00 Optional feature not implemented

HYT00 Timeout expired

HYT01 Connection timeout expired

IM001 Driver does not support this function

IM002 Data source name not found and no default driver specified

IM003 Specified driver could not be loaded

IM004 Driver’s SQLAllocHandle on SQL_HANDLE_ENV failed

IM005 Driver’s SQLAllocHandle on SQL_HANDLE_DBC failed

IM006 Driver’s SQLSetConnectAttr failed

IM007 No data source or driver specified; dialog prohibited

IM008 Dialog failed

IM009 Unable to load translation DLL

IM010 Data source name too long

IM011 Driver name too long

IM012 DRIVER keyword syntax error

IM013 Trace file error

IM014 Invalid name of File DSN

IM015 Corrupt file data source

8 Commissioning Tool „SQLViewer“

8.1

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 49

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

8 Commissioning Tool „SQLViewer“

Purpose of the tool

The commissioning tool SQLViewer supports the configuration of the SQL statements and the control of the message being transmitted and received by the driver. Furthermore, it indicates possible error codes and offers the possibility to export the indicated messages as a file.

User interface

The upper area of the user interface of the tool shows the status of the connection to the SQL driver. If the tool detects an S7-1500 software controller with a loaded SQL driver and activated commissioning mode, this is indicated in the field „Viewer“.

The middle area shows the textual output of the read messages.

In the lower area, you can find two buttons. With the „Clear“ button, you can clear the view provided that there is no connection to the controller. The „Save Log“ button permits to save the current content of the text field as TXT file.

Figure 8-1: User interface of the SQL viewer

8 Commissioning Tool „SQLViewer“

8.1

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 50

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

Operation

The tool has to be run on the same PC as the S7-1500 software controller.

To start the tool, just double-click on SQLViewer.exe.

The moment of time when the tool is started is unimportant.

To be able to use the tool, the SQL driver must be set to „commissioning modes“ which can be activated by establishing a connection to the SQL database (ODK1500S_SQL_Connect) with set „enableDebug“. If you want to deactivate the commissioning mode again, just disconnect the connection (ODK1500S_SQL_Disconnect).

After having started, no further operation is necessary. The tool connects itself automatically when there is a running S7-1500 software controller with loaded SQL driver and activated commissioning mode on the same PC. Then, the tool immediately indicates all logged messages.

Mode of functioning

The messages are read via a shared memory. The SQL driver writes the messages to this memory and the tool can read this at any time. The size of this memory area is limited. If this size is exceeded, the memory will be cleared again (ring buffer). In this case, the indicated text in the SQL viewer will disappear as well.

9 Related literature

ODK 1500S-SQL-driver Entry-ID: 109479140, V1.0, 08/2015 51

S

iem

en

s A

G 2

01

5 A

ll ri

gh

ts r

ese

rve

d

9 Related literature Table 9-1

Topic Title / Link

\1\ Siemens Industry Online Support

http://support.industry.siemens.com

\2\ Download page of this entry

https://support.industry.siemens.com/cs/ww/en/view/109479140

10 History Table 10-1

Version Date Modifications

V1.0 08/2015 First version