Quick Start

 

The following PDF-Document contains the handout from a workshop with the topic TwinCAT Database Server.

This handout explain in detail how to work with the XML-configuration file editor and shows the function of several function blocks out of the PLC.

Download as PDF: Sample 9 "Workshop Handout" databaseserver_introduction.pdf

Technical Workshop

Topic: TwinCAT Database Server

Step by step introduction for hands on with TwinCAT Database Server.

1. Foreword

There are two possibilities to configure the TwinCAT Database Server - on the one hand out of the PLC Control and on the other hand with TwinCAT Database Server XML Configuration File Editor. Today we discuss a small example for the configuration with XML Editor, but there is also an instruction for the second way for testing yourself.

2. DataBaseServer Configuration with XML Editor

Open the Editor under Start -> All Programs -> TwinCAT System -> TwinCAT DataBase Server -> XML Configuration File Editor

Quick Start 1:

At first you have to add a new database. Right click on Database as it is shown in the picture or by the symbols in the tool bar.

Quick Start 2:

In the next step you must configure your database. Not everybody has got the great databases on his system, that’s why we choose the ASCII database.
You can find the declaration of all different database types, which we support, in the Information System.

mk:@MSITStore:tcdbserver.chm/html/tcdbserver_dbdeclaration.htm

Choose the DBType ASCII. If you only will log alphanumeric data types and Boolean choose “Double” for DBValueType. Otherwise select “Bytes” for the log of structures and strings too.

Quick Start 3:

For an ASCII database you must indicate only the database URL, like it is shown in the next picture. You still need the Database ID (DBID) later on and also the AdsID which you can see on the next page.

Quick Start 4:

Add an AdsDevice and insert your AdsNetID, also your AdsPort. If you use the local system, you don’t need to type your NetID.

Quick Start 5:

If you create a configuration for a remote system, you have the possibility to choose your target in the table on the right side. Now you can insert a Symbolgroup with variables from your PLC project.

Quick Start 6:

Before you configure your Symbol group, you have to “Build” your PLC project. Open TwinCAT PLC Control with PLCVariableSample.pro file and then Project -> Build. This is important for the generation of the tpy file. You can search for variables about the “Import Symbols” button in the Database Editor.

Quick Start 7:
Quick Start 8:

For example, you choose the first five variables of the Symbol collection. You can change the Log Mode for each variable, like it is shown in the next picture. You must set the AdsID and the DBID, which you know from the sides before.

Quick Start 9:
Quick Start 10:

You have the possibility to choose the communication direction. In this case ADS_to_DB_APPEND is selected.

ADS_to_DB_APPEND:
This option appends the new data entries to the old in the database.

ADS_to_DB_UPDATE:
This option updates the available entries in the database.

ADS_to_DB_RINGBUFFER:
With this write mode you can limit the count or the age of datasets at databasetables.

DB_to_ADS:
This communication direction describes the reading of values from the database into the PLC.

If the Database Server should be used without the PLC (only logging from PLC variables), the option AutoStart must be set. So the Database Server immediately starts creating the connections to the declared database and ADS-devices after a TwinCAT start. Therefore you have to create a Bootproject from PLCVariableSample.pro. Finally you have to save your DB configuration in the Editor under C:\TwinCAT\Boot.

Quick Start 11:


4. Configuration test

Go to PLC Control and start the PLC, after that create a Bootproject and make a TwinCAT restart. Look for the test database “TestDB” under C:\TwinCAT\TcDatabaseSrv\Samples.

This was a small introduction for the Beckhoff Database Server. Have fun with it. Questions? Then write me an email! For professionals follows a small instruction for the configuration of the Database Server from the PLC.

5. DataBaseServer Configuration from the PLC

Task:
Create a Microsoft Compact SQL database from the PLC Control, add a database connection and insert a new table in your database. Finally use the write function block with the ring buffer mode “RingBuffer_Count” to write 100 times a variable into the table of your database.

At first insert a R_TRIG function block to start your program with a rising edge. After that create a state machine for the call of your database function blocks, like it is shown in the picture below.

Quick Start 12:

Now declare all other variables that you need. Especially the structure of the table. You can find a description how to do this for Microsoft Compact SQL in the Information System:

An AutoID is generated in the “ID” column. The value in this column is always increased by 1. The “Timestamp” column stores the time at which the data record was saved. And the name of the variable is stored in the third column. Under “Value” you find the values of the variables.

You can take the remaining variables from the next picture.

Quick Start 13:


The next steps.

FB_DBCreate:

Quick Start 14:

In state number one you have to insert the FB_DBCreate. The path of the database must be given to this function block. But you must provide that this database does not exist yet. Otherwise, there is an error message. In state 11 you must wait until the function block is not busy.

FB_DBConnectionAdd:

Quick Start 15:

In this function block you have to set the DBType and the DBValueType (Bytes or Double). And you already have to give your table a name. The other settings for Compact SQL databases are in the Information System

FB_DBTableCreate:

Quick Start 16:

One of the inputs of this function block is “hDBID”. You give over the value which you get from the FB_DBConnectionAdd. Furthermore you give over the size and the address of your table structure.

FB_DBWrite:

Quick Start 17:

With the FB_DBWrite you can write the current values of the variable “iLogVariable” into the database all the time. But there will be stored only 100 values of the variable, if you set the nRingBufferCount to 100.

At the end of the program code, you can see the variable which is increasing by1 every PLC cycle.

Important: If you test the sample program take care that the database does not exist!