AddJsonKeyPropertiesFromSymbol

AddJsonKeyPropertiesFromSymbol 1:

With the aid of this method, metadata can be added via PLC attributes to the JSON representation of a PLC data structure on an FB_JsonSaxWriter object. The method receives as its input parameters the instance of the FB_JsonSaxWriter function block, the desired name of the JSON property that is to contain the metadata, the data type name of the structure and a string variable sProperties, which contains a list of the PLC attributes to be extracted, separated by a cross bar.

Syntax

METHOD AddJsonValueFromSymbol : BOOL
VAR_IN_OUT
  fbWriter    : FB_JsonSaxWriter;
END_VAR
VAR_IN_OUT CONSTANT
  sKey        : STRING;
  sDatatype   : STRING;
  sProperties : STRING;
END_VAR
VAR_OUTPUT
  hrErrorCode : HRESULT;
END_VAR

AddJsonKeyPropertiesFromSymbol 2: Return value

Name

Type

AddJsonValueFromSymbol

BOOL

AddJsonKeyPropertiesFromSymbol 3:/AddJsonKeyPropertiesFromSymbol 4: Inputs/Outputs

Name

Type

fbWriter

FB_JsonSaxWriter

sKey

STRING

sDatatype

STRING

sProperties

STRING

AddJsonKeyPropertiesFromSymbol 5: Outputs

Name

Type

hrErrorCode

HRESULT

The PLC attributes can be specified in the following form on the structure elements:

{attribute 'Unit'        := 'm/s'}
{attribute 'DisplayName' := 'Speed'}
Sensor1                  : REAL;

A complete sample of how to use this method can be found in section Tc3JsonXmlSampleJsonDataType.

Sample call:

fbJsonSaxWriter.ResetDocument()
fbJsonDataType.AddJsonKeyPropertiesFromSymbol(fbJsonSaxWriter, 'MetaData','ST_Values','Unit|DisplayName');