12
MsSQL Library for TIA Portal V13 SP1 User guide V1.0.0.0 Author: Tom´ s Krajcar am. M´ ıru 1205/9 767 01 Kromˇ ıˇ z Czech Republic www.plc2sql.com mail: [email protected] Last revision: September 2016 Copyright c byTom´aˇ s Krajcar 2016 All rights reserved

MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

  • Upload
    ngodieu

  • View
    281

  • Download
    6

Embed Size (px)

Citation preview

Page 1: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

MsSQL Library for TIA Portal V13 SP1

User guide

V1.0.0.0

Author:Tomas Krajcar

nam. Mıru 1205/9

767 01 KromerızCzech Republic

www.plc2sql.com

mail: [email protected]

Last revision: September 2016

Copyright c© by Tomas Krajcar 2016All rights reserved

Page 2: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

Contents

1 Product description 21.1 Range of function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2 Supported datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3 Function blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.3.1 fbMsSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.4.1 fcGetBOOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.4.2 fcGetDINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.4.3 fcGetSTRING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.4.4 fcGetREAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.5 Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.6 Licensing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2 Installation 62.1 Installation of Microsoft SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 Installation MsSQL library to TIA Portal . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

3 Example application 83.1 Example commands for SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3.1.1 tblTestPLC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4 ChangeLog 11

1

Page 3: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

Chapter 1

Product description

This library allows you to connect your PLC Siemens S7-1200 or S7-1500 application to Microsoft SQLdatabase. With this library you are able to store and read process data. Read recipes from ERP, savebreakdown report and etc. No more OPC servers and other middleware.

Basic requirement for this library is TIA Portal V13 and Microsoft SQL Server (2005-2014).

Microsoft SQL Server 2014 Express is there: https://www.microsoft.com/en-us/download/details.aspx?id=42299

1.1 Range of function

This library allows to the user connect to Microsoft SQL Server from 2005 to 2014. This library use forcommunication with server TDS protocol.

Supported commands:

• SELECT

• INSERT

• UPDATE

• DELETE

• Execute stored procedures

1.2 Supported datatypes

Other datatypes, which are not in the table below, will cause xExecuteSQLError Unsupporteddatatype. Strikethrough datatypes are not currently supported, but they will be available in the fu-ture.

Datatype SQL datatype PLC datatype ID of datatypeboolean bit BOOL 16#32 or 16#68string nvarchar(n) STRING(255) 16#E7

int int DINT 16#26 or 16#38bigInt bigint DINT 16#7Ffloat float REAL 16#6Dreal real LREAL 16#3E

datetime datetime DATETIME(DT) 16#3D or 16#6F

2

Page 4: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

1.3 Function blocks

1.3.1 fbMsSQL

FB for complete connecting and executing commands with Microsoft SQL from 2005 to 2014.Author: krajcartV1.0.0.0

Table 1.1: fbMsSQL

Scope Name Type Inital Comment

Input

usiIP1 USINT 1st octet of IP AddressusiIP2 USINT 2nd octet of IP AddressusiIP3 USINT 3rd octet of IP AddressusiIP4 USINT 4th octet of IP AddressuiPort UINT 1433 port of MsSQL serveruiID CONN CONN OUC 12 unique ID of TCP communication in SimatictTimeout TIME T#1s timeoutdbNumber DB ANY address of db MsSQL InternalsActivationNumber String activation number receivede after purchase

Output

xConnectSucessfully Bool indication of sucessfull conection to SQLxConnTestOK Bool indication of sucessfull conection to SQL testxLoginFailed Bool login to SQL failedxExecuteSQLError Bool execution of SQL command failedxCommandExecutedOK Bool execution of SQL command was sucessfullwRowDoneCnt Word no. of rows donedwError DWord error identifiersErrorMessage String error messagesStatus String status messagexLicenseValid Bool info about license

InOut

xConnectSQL Bool trigger for login,to SQLxDisconnectSQL Bool trigger for logout from SQLxExecuteSQL Bool trigger to execute SQL commang executingxTryConnSQL Bool trigger for testing if connection with SQL serversqlLogin sqlLogin structure for login informationquery stQuery structure for stQuerystSqlResponse stSqlResponse structure for SQL Response

3

Page 5: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

1.4 Functions

1.4.1 fcGetBOOL

FC for converting raw SQL data to datatype BOOL.allowed data types: 16#32 or 16#68Author: krajcartV1.0.0.0

Table 1.2: fcGetBOOL

Scope Name Type Inital Comment

InputiCol Int index of selected columniRow Int index of selected row

InOutstSqlResponse stSqlResponse response structureeError Word error variablexValue Bool return value

1.4.2 fcGetDINT

FC for converting raw SQL data to datatype DINT.allowed data types: 16#26 or 16#38 or 16#7F(bigint)Author: krajcartV1.0.0.0

Table 1.3: fcGetDINT

Scope Name Type Inital Comment

InputiCol Int index of selected columniRow Int index of selected rowstResultAddress stResultAddress address where to store DINT variable

InOutstSqlResponse stSqlResponse response structureeError Word error variable

1.4.3 fcGetSTRING

FC for converting raw SQL data to datatype STRING.allowed data types: 16#E7Author: krajcartV1.0.0.0

Table 1.4: fcGetSTRING

Scope Name Type Inital Comment

Input

iCol Int index of selected columniRow Int index of selected rowstResultAddress stResultAddress address where to store DINT variabledbNumber DB ANY address of db MsSQL Internal

InOutstSqlResponse stSqlResponse response structureeError Word error variableuiLen UINT length of string variable

4

Page 6: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

1.4.4 fcGetREAL

FC for converting raw SQL data to datatype REAL(4 bytes) and LREAL(8 bytes).allowed data types: 16#6D(REAL) or 16#3E(LREAL)Author: krajcartV1.0.0.0

Table 1.5: fcGetREAL

Scope Name Type Inital Comment

Input

iCol Int index of selected columniRow Int index of selected rowstResultAddressReal stResultAddress address where to store REAL variablestResutlAddressLReal stResultAddress address where to store LREAL variable

InOutstSqlResponse stSqlResponse response structureeError Word error variable

1.5 Errors

List of errors stored in value dwError as output from fbMsSql.

Table 1.6: Error table

Code Error message Advice

16#400000 No error.

16#400001 Timeout destination server is unreachable.Remote server unreachable, tryfbPing and firewall.

16#400002 Login failed.Wrong login or security settingson server side.

16#400003 Command failed. Executed command failed.

16#400004 SQL error ocurred. Read the description of error.

16#400005 Query has unsupported data type.Use supported datatype accord-ing 1.2 Supported datatypes.

16#400006 Error data row affected. MS SQL error.

16#400007 Wrong flag on received row affected. MS SQL error.

16#400008 Wrong row done. MS SQL error.

16#400009 No command to execute. Write some SQL command.

16#400010 More columns than are defined in gc iNoOfColumns.Increase gc iNoOfColumns con-stant in global parameters.

16#400011 More rows than are defined in gc iNoOfRows.Increase gc iNoOfRows constantin global parameters

16#400012 More raw data than are defined in gc iLengthOfDataArray.Increase gc iLengthOfDataArrayconstant in global parameters.

16#400014 License is not valid! Demo expired. Buy the license.

1.6 Licensing

MsSQL library for TIA Portal V13 is licensed per runtime license. Each license is binded to SN of PLC.Price for one runtime license is 200e without VAT. Without valid license library works only 2 hoursafter startup.

5

Page 7: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

Chapter 2

Installation

2.1 Installation of Microsoft SQL Server

How to install Microsoft SQL Server is shown on this video: https://www.youtube.com/watch?v=

QFyetK805bo

2.2 Installation MsSQL library to TIA Portal

Open example project for TIA Portal. Copy these block into your TIA Portal projects1 :

Function Blocks

• fbMsSQL

Functions

• fcGetBOOL

• fcGetDINT

• fcGetSTRING

• fcGetREAL

Data Blocks

• dbMsSQLInternal - no. of this DB has to be referenced as input of fbMsSQL

PLC data types

• astColData

• astRowDet

• stColumn

• stLogin

• stQuery

• stResultAddress

• stSqlResponse

1Numbers of fb, fc and db can be arbitrary, but dbMsSQLInternal is referenced as input of fbMsSQL

6

Page 8: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

This library package contains:

• Example project S7-1214C AC/DC/Rly

• Example project S7-1515-2 PN

• Example Visualization project TP1900 Comfort

• User guide

Figure 2.1: Project view TIA Portal V13

7

Page 9: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

Chapter 3

Example application

On the picture 3.1 is main program in OB1 with fbMsSQL and function block. Example has HMIvisualization These layout are predefined as faceplates in project library.

Figure 3.1: fbMsSQL call in OB1

8

Page 10: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

Figure 3.2: Example visualisation screen

3.1 Example commands for SQL Server

3.1.1 tblTestPLC

In this table we have 6 collumns:

• Bools [bit]

• String [nvarchar(50)]

• ID [int]

• Real [float]

• DoubleInt [bigint]

Table 3.1: Example of values, which you can add to your tblTestPLC table

[rows] Bools String ID Real DoubleInt1 0 Test 12 456 13.2 4455682 1 Hello youtube 78964 0.4 44556

9

Page 11: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

/****** This command is for db test ******/

USE [test]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[tblTestPLC](

[Bools] [bit] NULL,

[String] [nvarchar](50) NULL,

[ID] [int] NULL,

[Real] [float] NULL,

[DoubleInt] [bigint] NULL

) ON [PRIMARY]

GO

Figure 3.3: Create tblTestPLC

SELECT [Bools]

,[String]

,[ID]

,[Real]

,[DoubleInt]

FROM [test].[dbo].[tblTestPLC]

Figure 3.4: SELECT from tblTestPLC

10

Page 12: MsSQL Library for TIA Portal V13 SP1 - Simple data store · uiID CONN CONN OUC 12 unique ID of TCP communication in Simatic ... MsSQL library for TIA Portal V13 is licensed per runtime

Chapter 4

ChangeLog

V 1.0.0.0

• Released

11