As there are flatbuffer (no standard data types) used in the PLC using the get text function via the Data Layer nodes looks like this:
Declaration:
PROGRAM PROG_common_log_diagnosis_fbs_GetMainDiagnosisText
VAR
//Data for creating values to send in the request
fbs_GetMainDiagnosisText: common_log_diagnosis_fbs_GetMainDiagnosisText;
fbs_GetDetailedDiagnosisText: common_log_diagnosis_fbs_GetDetailedDiagnosisText;
fbBuilder: flatbuffers.FlatBufferBuilder;
udiStringMain: UDINT;
udiStringDetail: UDINT;
//Data Layer pathes
NodePathMain: STRING(255) := 'diagnosis/get/text/main';
NodePathDetail: STRING(255) := 'diagnosis/get/text/detailed';
//Diagnosis numbers
strMainDiag: STRING := '090A0000';
strDetailDiag : STRING := '0C550145';
//Reading function
fb_DL_ReadNodeValueType02: DL_ReadNodeValueType02;
bExecute: BOOL;
bDone: BOOL;
bActive: BOOL;
bError: BOOL;
ErrorID: CXA_Datalayer.ERROR_CODE;
ErrorIdent: CXA_Datalayer.ERROR_STRUCT;
NodePath: STRING(255);
DataReadOut: CXA_Datalayer.DL_NodeValue;
fb_R_TRIG: R_TRIG;
bMain: BOOL;
bDetail: BOOL;
fb_DL_ReadNode: DL_ReadNode;
DataReadIn: CXA_Datalayer.DL_NodeValue;
pData: POINTER TO STRING;
//Read text
strDiagText: STRING;
END_VAR
Implementation:
IF bMain THEN
bMain := FALSE;
bExecute := TRUE;
fbBuilder(forceDefaults := TRUE);
udiStringMain := fbBuilder.createString(strMainDiag);
fbs_GetMainDiagnosisText.startGetMainDiagnosisText(fbBuilder);
fbs_GetMainDiagnosisText.addMainDiagnosisNumber(udiStringMain);
fbBuilder.finish(fbs_GetMainDiagnosisText.endGetMainDiagnosisText());
DataReadIn.SetFlatbuffer(fbBuilder);
NodePath := NodePathMain;
ELSIF bDetail THEN
bDetail := FALSE;
bExecute := TRUE;
fbBuilder(forceDefaults := TRUE);
udiStringMain := fbBuilder.createString(strMainDiag);
udiStringDetail := fbBuilder.createString(strDetailDiag);
fbs_GetDetailedDiagnosisText.startGetDetailedDiagnosisText(fbBuilder);
fbs_GetDetailedDiagnosisText.addRelatedMainDiagnosisNumber(udiStringMain);
fbs_GetDetailedDiagnosisText.addDetailedDiagnosisNumber(udiStringDetail);
fbBuilder.finish(fbs_GetDetailedDiagnosisText.endGetDetailedDiagnosisText());
DataReadIn.SetFlatbuffer(fbBuilder);
NodePath := NodePathDetail;
END_IF
fb_DL_ReadNodeValueType02(
Execute:= bExecute,
Done=> bDone,
Active=> bActive,
Error=> bError,
ErrorID=> ErrorID,
ErrorIdent=> ErrorIdent,
ClientId:= ,
NodeName:= NodePath,
NodeValueIn:= DataReadIn,
NodeValueOut:= DataReadOut);
fb_R_TRIG(CLK:= bDone, Q=> );
IF fb_R_TRIG.Q THEN
bExecute := FALSE;
DataReadOut.GetValueString(Value=>pData);
strDiagText := pData^;
END_IF
In the Data Layer viewer it works as you can see here:
For main diagnosis number send object '{"mainDiagnosisNumber": "090A0000"}':
Data Layer viewer get main diagnosis text
For detail diagnosis number send object '{"detailedDiagnosisNumber": "0C550145", "relatedMainDiagnosisNumber": "090A0000"}':
Data Layer viewer get detailed diagnosis text
... View more