ReadAsStruct

This method reads a specified number of records from the buffered result data. A structure or an array of a structure is specified in which the data is to be written. The data type schema of this structure should correspond as closely as possible to that of the read data. The variable names are compared with those of the record. A validation makes it possible to detect deviations and respond to them.

If there is a requirement to use different names in the database and in the PLC, the names can be described in the structure with the attribute 'ElementName' with the assigned name from the database.

Syntax

METHOD ReadAsStruct: BOOL
VAR_INPUT
    nStartIndex: UDINT := 0;
    nRecordCount: UDINT := 1;
    pData: POINTER TO BYTE;
    cbData: UDINT;
    bValidate: BOOL := FALSE;
    pNoSQLValidation : POINTER TO FB_NoSQLValidationEvt;
    bDataRelease: BOOL := TRUE;
END_VAR

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

bValidate

BOOL

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

pNoSQLValidation

POINTER TO FB_NoSQLValidationEvt

Address of the function block FB_NoSQLValidationEvt that provides further information for validating the call.

bDataRelease

BOOL

Releases the cached data.

ReadAsStruct 2: Return value

Name

Type

Description

ReadAsStruct

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
    fbNoSQLResult: FB_NoSQLResultEvt(sNetID := '', tTimeout := T#5S);
    aRead : ARRAY[0..2] OF ST_MyDataStruct;
    fbNoSQLValidation : FB_NoSQLValidationEvt(sNetID := '', tTimeout := #5S);
END_VAR
IF fbNoSQLResult.ReadAsStruct(
    nStartIndex:= 0,
    nRecordCount:= 3,
    pData:= ADR(aRead),
    cbData:= SIZEOF(aRead),
    bValidate:= TRUE,
    pNoSQLValidation:= ADR(fbNoSQLValidation),
    bDataRelease:= TRUE)
THEN
    IF fbNoSQLResult.bError THEN
        TcMessage := fbNoSQLResult.ipTcResult;
        nstate := 255;
    ELSE
        nstate := nstate+1;
    END_IF
END_IF