Database

This method creates a new database. Optionally you can specify whether the created database should also be used for the configuration of the TwinCAT Database Server.

Syntax

METHOD Database : BOOL
VAR_INPUT
    pDatabaseConfig: POINTER TO BYTE;
    cbDatabaseConfig: UDINT;
    bCreateXMLConfig: BOOL;
    pDBID: POINTER TO UDINT;
END_VAR

Database 1: Inputs

Name

Type

Description

pDatabaseConfig

POINTER TO BYTE

Address of the database configuration structure

cbDatabaseConfig

UDINT

Length of the database configuration structure

bCreateXMLConfig

BOOL

Indicates whether the newly created database should be entered as new configuration entry in the XML file.

pDBID

UDINT

Returns the hDBID if/when a new configuration entry was created.

Database 2: Return value

Name

Type

Description

Database

BOOL

Displays the status of the method. Returns TRUE as soon as the method execution is finished, even in the event of an error.

Sample

VAR
    fbPLCDBCreate : FB_PLCDBCreateEvt(sNetID := '', tTimeout := T#5S);
    stConfigDB    : T_DBConfig_MsCompactSQL;
    hDBID         : UDINT;
    tcMessage     : I_TcMessage;
END_VAR
stConfigDB.bAuthentification := FALSE;
stConfigDB.sServer := 'C:\Test.sdf';

IF fbPLCDBCreate.Database(
    pDatabaseConfig:= ADR(stConfigDB),
    cbDatabaseConfig := SIZEOF(stConfigDB),
    bCreateXMLConfig := TRUE,
    pDBID := ADR(hDBID))
THEN
    IF fbPLCDBCreate.bError THEN
        tcMessage := fbPLCDBCreate.ipTcResult;
        nState := 255;
    ELSE
        nState := 0;
    END_IF
END_IF