Read

This method reads a specified number of records from a database table with the standard table structure specified by Beckhoff. The standard table structure is used in AutoLog mode and in the FB_DBWriteEvt function block, for example.

Syntax

METHOD Read : BOOL
VAR_INPUT
    hDBID: UDINT;
    sTableName: T_MaxString;
    sDBSymbolName: T_MaxString;
    eOrderBy: E_OrderColumn := E_OrderColumn.eColumnID;
    eOrderType: E_OrderType := E_OrderType.eOrder_ASC;
    nStartIndex: UDINT;
    nRecordCount: UDINT;
    pData: POINTER TO ST_StandardRecord;
    cbData: UDINT;
END_VAR

Read 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.

sDBSymbolName

T_MaxString

Symbol name to be read from the standard table structure.

eOrderBy

E_OrderColumn.eColumnID

Sorting column (ID, timestamp, name or value)

eOrderType

E_OrderType.eOrder_ASC

Sorting direction (ASC or DESC)

nStartIndex

UDINT

Indicates the index of the first record to be read.

nRecordCount

UDINT

Indicates the number of records to be read.

pData

POINTER TO ST_StandardRecord

Address of the structure array into which the records are to be written.

cbData

UDINT

Indicates the size of the structure array in bytes.

Read 2: Return value

Name

Type

Description

Read

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
    fbPLCDBRead    : FB_PLCDBReadEvt (sNetID := '', tTimeout := T#5S);
    ReadStruct     : ST_StandardRecord;
    tcMessage      : I_TcMessage;
END_VAR
IF fbPLCDBRead.Read(
    hDBID:= 1, 
    sTableName:= 'MyTable_WithLReal', 
    sDBSymbolName:= 'MyValue', 
    eOrderBy:= E_OrderColumn.ID, 
    eOrderType:= E_OrderType.DESC, 
    nStartIndex:= 0, 
    nRecordCount:= 1, 
    pData:= ADR(ReadStruct), 
    cbData:= SIZEOF(ReadStruct))
THEN
    IF fbPLCDBRead.bError THEN
        tcMessage := fbPLCDBRead.ipTcResult;
        nState := 255; 
    ELSE
        nState := 0;
    END_IF
END_IF

Result in the PLC:

Read 3: