Starting / stopping, cyclic logging
This sample illustrates the starting and stopping of cyclic logging from the PLC.
Download: TcDBSrv_InfoSysSamples.zip

Database type used | MS Compact SQL |
Compatible database types | ASCII, MS SQL, MS Compact SQL, MS Access, MySQL, PostgreSQL, DB2, Oracle, InterBase/Firebird, XML |
Function blocks used | FB_DBCyclicRdWrt |
Libraries to be integrated | Tc2_Database, Tc2_System, Tc2_Standard |
Download file list | TcDBSrv_InfoSysSamples.tszip, CurrentConfigDataBase.xml, TestDB_Cyclic.sdf |
In this sample the cyclic log function is started or stopped by toggling the bStartStop variable.
The cyclic log process begins in response to a positive edge at the bExecute input.
A negative edge will end the process again.
Variable declaration (PRG data types)
PROGRAM DataTypes
VAR
DBSrv_DT_INT : INT;
DBSrv_DT_UINT : UINT;
DBSrv_DT_DINT : DINT;
DBSrv_DT_UDINT : UDINT;
DBSrv_DT_REAL : REAL;
DBSrv_DT_LREAL : LREAL;
DBSrv_DT_BYTE : BYTE := 16#A1;
DBSrv_DT_BOOL : BOOL;
DBSrv_DT_MYSTRUCT: ST_MyStruct;
DBSrv_DT_ARRAY : ARRAY [0..19] OF UDINT;
DBSrv_DT_WORD : WORD;
DBSrv_DT_DWORD : DWORD;
END_VAR
ST_MyStruct structure
TYPE ST_MyStruct :
STRUCT
iValue1 : INT;
iValue2 : UINT;
iValue3 : BOOL;
iValue4 : REAL;
END_STRUCT
END_TYPE
Variable Declaration
PROGRAM MAIN
VAR
fbDBCyclicRdWrt1: FB_DBCyclicRdWrt;
bCyclic : BOOL :=TRUE;
bBusy_Cyclic : BOOL;
bErr : BOOL;
nErrID : UDINT;
sSQLState : ST_DBSQLError;
END_VAR
PLC program
DataTypes;
fbDBCyclicRdWrt(
sNetID := ,
bExecute := bCyclic,
tTimeout := t#15s,
bBusy => bBusy_Cyclic,
bError => bErr,
nErrID => nErrID,
sSQLState => sSQLState);
In order to use this sample, you only need to transfer the NetID of the ADS device (on which the TwinCAT Database Server is installed) to the sNetID input.
When you run the program and set the bCyclic variable to TRUE, all the variables that are declared in the symbol group of the XML configuration file are logged.
![]() | TwinCAT Database Server All Microsoft SQL Compact databases, which are declared in the XML configuration file, must exist. They are not generated automatically. The declared ASCII files, on the other hand, are generated automatically if they do not exist. |
Requirements
Development environment |
Target platform |
PLC libraries to be linked |
---|---|---|
TwinCAT v3.0.0 |
PC or CX (x86) |
Tc2_Database |