WriteBySymbol

This method reads the value of a specified ADS symbol and saves it in the standard table structure specified by Beckhoff. ADS symbols from other ADS devices can also be read.

Syntax

METHOD WriteBySymbol : BOOL
VAR_INPUT
    hDBID: UDINT;
    sTableName: T_MaxString;
    stADSDevice: ST_ADSDevice;
    stSymbol: ST_Symbol;
    eDBWriteMode: E_WriteMode := E_WriteMode.eADS_TO_DB_Append;
    nRingBuffParameter: UDINT;
END_VAR

WriteBySymbol 1: Inputs

Name

Type

Description

hDBID

UDINT

Indicates the ID of the database to be used.

sTableName

T_MaxString

Name of the table that is to be read.

stADSDevice

ST_ADSDevice

ADS device from which a symbol is to be logged in the standard table structure.

stSymbol

ST_Symbol

Symbol name of the variable to be written

eDBWriteMode

E_WriteMode

Indicates the write mode. (append, update, ring buffer)

nRingBuffParameter

UDINT

Additional parameter(s) for the "ring buffer" write mode

WriteBySymbol 2: Return value

Name

Type

Description

WriteBySymbol

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

This sample shows how to use the FB_PLCDBWriteEvt.WriteBySymbol method:

VAR
    fbPLCDBWrite    :  FB_PLCDBWriteEvt(sNetID := '', tTimeout := T#5S);
    myValue         :  LREAL := 43.23;
    myAdsDevice     :  ST_ADSDevice;
    mySymbol        :  ST_Symbol;
    tcMessage       :  I_TcMessage;
END_VAR
// Set ADSDevice Information
myAdsDevice.sDevNetID     := '127.0.0.1.1.1';
myAdsDevice.nDevPort      := 851;
myAdsDevice.eADSRdWrtMode := E_ADSRdWrtMode.bySymbolName; 
myAdsDevice.tTimeout      := T#5S; 

// Set Symbol Information
mySymbol.eDataType        := E_PLCDataType.eType_LREAL;
mySymbol.sDBSymbolName    := 'MySymbol';
mySymbol.sSymbolName      := 'MAIN.myValue';
mySymbol.nBitSize         := 8;

// Call Functionblock
IF fbPLCDBWrite.WriteBySymbol(
    hDBID:= 1, 
    sTableName:= 'myTable_WithLReal', 
    stADSDevice:= myAdsDevice, 
    stSymbol:= mySymbol, 
    eDBWriteMode:= E_WriteMode.eADS_TO_DB_Append, 
    nRingBuffParameter:= 1) 
THEN
    IF fbPLCDBWrite.bError THEN
        tcMessage := fbPLCDBWrite.ipTcResult;
        nState := 255; 
    ELSE
        nState := 0;
    END_IF
END_IF

Result in the database:

ID

Timestamp

Name

Value

28

'2018-01-30 14:04:19'

'MyValue'

41.23

29

'2018-01-30 14:04:29'

'MyValue'

42.23

30

'2018-01-30 14:04:39'

'MyValue'

43.23

31

'2018-01-30 14:06:12’

‘MySymbol’

86.2