PLC Expert mode

This chapter is a compilation of all the information required for using the PLC Expert mode of the TwinCAT Database Server. In contrast to the Configure mode, in this mode data are not written or read based on cycles or events, but at specific times within the program sequence. This requires knowledge of the SQL language.

PLC Expert mode

In PLC Expert mode only the database configuration is set in the configurator. Further functionalities are implemented in the PLC code of the application. With the function block FB_PLCDBCreate it is possible to dispense with the configurator and even configure the database itself from the PLC. Function blocks for reading and writing are available, if required. The function block FB_PLCDBCmd forms the transition between PLC Expert mode and SQL Expert mode. Here, table structures can easily be mapped as PLC structures, and an SQL command with placeholders for the current structure values can be transferred to the TwinCAT Database Server. The TwinCAT Database Server then inserts all values automatically and sends the command to the database.

Build Project

The TwinCAT Connectivity extension for Visual Studio provides a new project template. When a new project is created, the TwinCAT Connectivity Project category appears as an option.

To create a new TwinCAT Connectivity project, select Empty TwinCAT Connectivity Project, specify the project name and the storage location and click OK to add it to the solution. In this way, TwinCAT Connectivity projects or TwinCAT Database Server projects can conveniently be created in parallel with TwinCAT or other Visual Studio projects.

PLC Expert mode 1:

A new project node appears in the solution. Below the Connectivity project node you can add subprojects for the supported connectivity functions.

Use Add to add a new TwinCAT Database Server project to the TwinCAT Connectivity project. The TwinCAT Database Server project can be found in the list of existing Item Templates.

PLC Expert mode 2:

A new TwinCAT Database Server project is created under the TwinCAT Connectivity node.

PLC Expert mode 3:

This is now used as the basis for the pending configuration of a TwinCAT Database Server. The document can be edited either via the Properties window or via an editor.

A Connectivity project can be associated with any number of TwinCAT Database Server projects or other projects, and it may therefore contain several configurations.

Editor for server settings

PLC Expert mode 4:

The Server Settings editor can be used to edit the settings for the TwinCAT Database Server. These are general settings relating to the corresponding server. In the drop-down menu (1) you can select the target system via the Ams NetID. To this end you have to create a route to the target system via TwinCAT. When a finished configuration is transferred, the settings are stored in the TwinCAT Database Server for this target system.

The settings for logging faults or errors can be configured under Log settings. In the event of a fault or error, the Database Server generates a detailed entry in a log file. The log file can be read with the Information Log Viewer. Under Log Settings you can specify a path to the file location and the maximum file size. You can also influence the accuracy of the log. For performance reasons we recommend that logging is deactivated again after the error analysis, once it is no longer required.

For network access to file-based databases such as Access or SQL Compact, the Impersonate option must be set, so that the TwinCAT Database Server can connect to this network drive. This feature is currently not supported in Windows CE.

Further configuration settings are available to control the read process from the database. These settings refer to the TwinCAT Database Server on the target system:

MaxStringLength

Maximum string length of the variables in the PLC

MaxByteArrayLength

Maximum byte array length of the variables in the PLC

DBNullAllowed

Indicates whether ZERO values are accepted in the TwinCAT Database Server.

DBConnectionTimeout

Indicates the time after which the TwinCAT Database Server assumes a connection error while attempts are made to establish a connection.

DBCommandTimeout

Indicates the time after which the TwinCAT Database Server assumes a connection fault when a command was sent. If large data quantities are involved, processing of a command may take quite some time, depending on the database and the infrastructure.

Supported database types

PLC Expert mode 5:

The installed database types can be selected in the server settings. All installed databases are selected by default. The TwinCAT 3 Database Server will load the corresponding database interfaces. In this way, unused databases on the target system can be deselected.

Adding a database configuration

A new database configuration can be added via the command Add New Database in the context menu of a Database Server project or via the corresponding command in the toolbar.

PLC Expert mode 6:

A new database configuration is added in the form of a file in the project folder and integrated in the project. As with all Visual Studio projects, the information on the new files is stored in the Connectivity project.

Editor for database configurations

PLC Expert mode 7:

The database ID, which is required for some function blocks in the PLC, is shown in the upper part of the editor (1). The database types of the target database can be selected from the drop-down menu (2). Another option is the ODBC interface for a database, although this is not yet supported. Note that not all functions of the TwinCAT Database Server can be guaranteed, depending on the database.

As a further option you can select a so-called failover database (3), which is triggered when an error is encountered in Configure mode. In the event of a network disconnection, this feature can automatically ensure that data are stored elsewhere and not lost.

For each database additional adjustable parameters are available. Depending on the database a connection string (5) is created, which describes the connection to the database. The intention is to make the parameters you have set more transparent.

The CREATE (4) button can be used to create a new database. This function is only displayed if the respective database supports it.

PLC Expert mode 8:

Unknown databases can be configured via an ODBC interface. In the ODBC Type drop-down list select "Unknown Database" and add parameters via the commands in the context menu. They may contain passwords, which are stored in encrypted form. The required connection string can be assembled from these parameters. Note that only limited functions of the TwinCAT Database Server can be used. Only the explicit function blocks of the SQL Expert mode are supported.

No additional AutoLog group configuration is required in this mode, since writing and reading between the database and the PLC is called manually by the PLC programmer. The configuration part is now complete.

Activating a project

To activate a configured project on the TwinCAT Database Server, use the command Activate Configuration in the context menu of the TwinCAT Database Server project.

PLC Expert mode 9:

Once the project has been activated, the can be used for further development steps, such as creating databases or tables, generating structures for the PLC, which match the corresponding table structure of the database, or testing connections to the database with the implemented information.

The PLC programmer can use the available PLC API function blocks to communicate with the TwinCAT Database Server.