Read

This method reads a specified number of records from the result data cached in the TwinCAT Database Server.

Syntax

METHOD Read : BOOL
VAR_INPUT
    nStartIndex: UDINT := 0;
    nRecordCount: UDINT := 1;
    pData: POINTER TO BYTE;
    cbData: UDINT;
    bWithVerifying: BOOL := FALSE;
    bDataRelease: BOOL := TRUE;
END_VAR

Read 1: Inputs

Name

Type

Description

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 BYTE

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

cbData

UDINT

Indicates the size of the structure array in bytes.

bWithVerifying

BOOL

Return data are compared with the pData structure array and adjusted if necessary.

bDataRelease

BOOL

Releases the cached data.

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
    fbSqlResult : FB_SQLResultEvt(sNetID:='', tTimeout := T#5S); 
    aReadStruct : ARRAY[1..5] OF ST_StandardRecord;
END_VAR
// get values from internal tc db srv storage 
IF fbSqlResult.Read(2, 3, ADR(aReadStruct), SIZEOF(aReadStruct), FALSE, TRUE) THEN
    IF fbSqlResult.bError THEN
        nState := 255; 
    ELSE
        nState := nState+1; 
    END_IF
END_IF

Result in the PLC:

Read 3: