FB_DBWrite
The FB_DBWrite function block can be used to write the values of individual variables into databases.
The table structure must contain the columns "Timestamp", "Name", and "Value" (see "SQL Compact database"). In order to be able to use the function block, the database that is to be used for write access and the ADS device, from which the variables are to be read, must be declared in the XML configuration file.
VAR_INPUT
VAR_INPUT
sNetID : T_AmsNetID;
hDBID : UDINT;
hAdsID : UDINT;
sVarName : T_MaxString;
nIGroup : UDINT;
nIOffset : UDINT;
nVarSize : UDINT;
sVarType : T_MaxString;
sDBVarName : T_MaxString;
eDBWriteMode : E_DBWriteModes;
tRingBufferTime : TIME;
nRingBufferCount: UDINT;
bExecute : BOOL;
tTimeout : TIME;
END_VAR
sNetID: String containing the AMS network ID of the target device, at which the ADS command is directed.
hDBID: ID of the database to be used.
hAdsID: ID of the ADS device to be used.
sVarName: Provides the name of the variable.
nIGroup: Index group of the variable (optional, only on the BC9000).
nIOffset: Index offset of the variable (optional, only on the BC9000).
nVarSize: Size of the variable in bytes (optional, only on the BC9000).
sVarType: Data type of the variable (optional, only on the BC9000).
Possible variable data types: "BOOL" / "LREAL" / "REAL" / "INT16" / "DINT" / "USINT" / "BYTE" / "UDINT" / "DWORD" / "UINT16" / "WORD" / "SINT"
sDBVarName: Variable name to be used in the database.
eDBWriteMode: Indicates whether the values are to be appended in new records or whether the existing records are to be updated.
tRingBufferTime: Indicates the maximum age of records in a table (only for Ringbuffer_WriteMode).
nRingBufferCount: Indicates the maximum number of records in a table (only for Ringbuffer_WriteMode).
bExecute: The command is executed with a rising edge.
tTimeout: Indicates the time before the function is cancelled.
VAR_OUTPUT
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrID : UDINT;
sSQLState: ST_DBSQLError;
END_VAR
bBusy: The command is in the process of being transmitted by ADS. No new command will be accepted as long as bBusy remains TRUE.
bError: Becomes TRUE, as soon as an error occurs.
nErrID: Returns the ADS error code or TcDatabaseSrv_Error_Codes if the bError output is set.
sSQLState: Returns the SQL error code of the corresponding database type
Log values of ADS devices (except BC9000) | Log values of BC9000 |
---|---|
FB_DBWrite1( | FB_DBWrite1( sNetID:= , hDBID:= 1, hAdsID:= 1, sVarName:= 'MAIN.TestVar', nIGroup:= 16448, nIOffset:= 0, nVarSize:= 16, sVarType:= 'REAL', sDBVarName:= 'DBTestVar', eDBWriteMode:= eDBWriteMode_Append, bExecute:= TRUE, tTimeout:= T#15s, bBusy=> busy, bError=> err, nErrID=> errid, sSQLState=> sqlstate); |
Requirements
Development environment |
Target system type |
PLC libraries to be linked |
---|---|---|
TwinCAT v3.0.0 |
PC or CX (x86) |
Tc2_Database |