NoSql Expert Mode

NoSQL

NoSQL databases (not only Sequel) differ from conventional relational data storage.

Document-based databases:

Records are stored as documents in the database. This offers the advantage of being able to archive data in a more flexible and hierarchical manner.

NoSql Expert Mode 1:

If a record consists of more than one flat structure of basic data types, it can no longer be mapped directly via a relational database. NoSQL databases offer this flexibility. Changes in the program code and the corresponding structures can also be easily adopted without having to create a new table.

Document-based databases usually save the data as JSON-formatted records. The records can all be different.

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.

NoSql Expert Mode 2:

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.

NoSql Expert Mode 3:

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

NoSql Expert Mode 4:

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

NoSql Expert Mode 5:

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

NoSql Expert Mode 6:

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.

NoSql Expert Mode 7:

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

NoSql Expert Mode 8:

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. CHECK can be used to check the connection to the database.

NoSQL databases can also be selected from the target databases. If you activate the project with a NoSQL database, a NoSQL tab is enabled in the SQL query editor to facilitate the use of NoSQL-specific functions.

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.

NoSql Expert Mode 9:

MongoDB in PLC Expert/Configure mode

PLC Expert and Configure mode use the predefined database schema in their processes. Normally, the schema of the structures used will not change during operation. In order to nevertheless be able to use the function blocks, the TwinCAT 3 Database Server requires a description of the table schema. For MongoDB a table is therefore simulated.
In the SQL Query Editor, use the SQL tab and the CREATE TABLE subcategory to create a table, or in this case a collection. In addition, unlike for relational databases, an entry is created in a metadata collection. Information on the table schema for the TwinCAT 3 Database Server is stored here.

In order to use advanced functionality, e.g. structures of any hierarchy or flexible records, we recommend using the NoSQL function blocks.

InformationLog View for diagnostics

The InformationLog View is available for troubleshooting.

InformationLog View is a tool for reading log files from the TwinCAT Database Server. Recorded information is displayed with a timestamp, IDs and error messages in plain text.

The log files can not only be viewed or emptied via direct file access, but also directly via the target. This is particularly advantageous with distributed Database Servers in a network, for quick and easy access to the log file. For this access a route to the target device must exist.

NoSql Expert Mode 10: