ReadAsString
This method reads a specified number of records from the result data cached in the TwinCAT Database Server. An array of strings is specified into which this data is to be copied as JSON.
Syntax
METHOD ReadAsString : BOOL
VAR_INPUT
nStartIndex: UDINT := 0;
nRecordCount: UDINT := 1;
pData: POINTER TO BYTE;
cbData: UDINT;
nMaxDocumentSize : UDINT;
bDataRelease: BOOL := TRUE;
END_VAR
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 | Indicates the address of the string array into which the records are to be written. |
cbData | UDINT | Indicates the size of the string array in bytes. |
nMaxDocumentSize | UDINT | Indicates the maximum size of a single JSON document from pData. |
bDataRelease | BOOL | Releases the cached data. |
Return value
Name | Type | Description |
---|---|---|
ReadAsString | 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_Json : ARRAY[0..2] OF STRING(1000);
TcMessage : I_TcMessage;
END_VAR
IF fbNoSqlResult.ReadAsString(
nStartIndex:= 0,
nRecordCount:= 3,
pData:= ADR(aRead_Json),
cbData:= SIZEOF(aRead_Json),
MaxDocumentSize:= SIZEOF(aRead_Json[0]),
bDataRelease:= TRUE)
THEN
IF fbNoSqlResult.bError THEN
TcMessage := fbNoSqlResult.ipTcResult;
nstate := 255;
ELSE
nstate := nstate+1;
END_IF
END_IF