Wagoappjson: Release 1.1.0.11

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

WagoAppJSON

Release 1.1.0.11

Oct 23, 2020


Contents

1 Description 1

2 10 Documentation 3
2.1 doc10_SystemProperties (FB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3 20 Program Organization Units 4


3.1 10 Main . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.1.1 FbWrite_ToIEC_ByRule (FB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.1.2 Fb_JSON_ParseAndModify (FB) . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Fb_JSON_ParseAndModify.GetValueByPath (METH) . . . . . . . . . . . . . . 7
Fb_JSON_ParseAndModify.SetValueByPath (METH) . . . . . . . . . . . . . . 8
3.1.3 Fb_JSON_Writer_01 (FB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 20 Advanced . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2.1 FbJson_Advanced (FB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Datentypen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
BaseDataMethods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
FbJson_Advanced.aArrayBool (METH) . . . . . . . . . . . . . . . . . . 11
FbJson_Advanced.aArrayByte (METH) . . . . . . . . . . . . . . . . . . 11
FbJson_Advanced.aArrayDword (METH) . . . . . . . . . . . . . . . . . . 11
FbJson_Advanced.aArrayInt (METH) . . . . . . . . . . . . . . . . . . . 12
FbJson_Advanced.aArrayReal (METH) . . . . . . . . . . . . . . . . . . 12
FbJson_Advanced.aArrayString (METH) . . . . . . . . . . . . . . . . . 12
FbJson_Advanced.aArrayWord (METH) . . . . . . . . . . . . . . . . . . 12
FbJson_Advanced.aArray_ArrayBool (METH) . . . . . . . . . . . . . . 12
FbJson_Advanced.aArray_ArrayByte (METH) . . . . . . . . . . . . . . 12
FbJson_Advanced.aArray_ArrayDword (METH) . . . . . . . . . . . . . 12
FbJson_Advanced.aArray_ArrayREAL (METH) . . . . . . . . . . . . . . 13
FbJson_Advanced.aArray_ArrayString (METH) . . . . . . . . . . . . 13
FbJson_Advanced.aArray_ArrayWord (METH) . . . . . . . . . . . . . . 13
FbJson_Advanced.MyFileClose (METH) . . . . . . . . . . . . . . . . . . . . . . 13
3.3 30 Sax_Parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.3.1 FbJSON_Handler (FB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
FbJSON_Handler.JSON_ArrayClosed (METH) . . . . . . . . . . . . . . . . . . 13
FbJSON_Handler.JSON_ArrayDetected (METH) . . . . . . . . . . . . . . . . . 14
FbJSON_Handler.JSON_DataFinished (METH) . . . . . . . . . . . . . . . . . . 14
FbJSON_Handler.JSON_KeyDetected (METH) . . . . . . . . . . . . . . . . . . 14
FbJSON_Handler.JSON_NullDetected (METH) . . . . . . . . . . . . . . . . . . 15
FbJSON_Handler.JSON_ObjectClosed (METH) . . . . . . . . . . . . . . . . . . 15
FbJSON_Handler.JSON_ObjectDetected (METH) . . . . . . . . . . . . . . . . 15
FbJSON_Handler.JSON_ValueDetected (METH) . . . . . . . . . . . . . . . . . 16
3.3.2 FbJSON_Sax_Parser (FB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

i
FbJSON_Sax_Parser.RegisterParserListener (METH) . . . . . . . . . . . 17

4 29 Data types 19
4.1 eJsonRuleType (ENUM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2 eType (ENUM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.3 typAuxiliaries (STRUCT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.4 typJSON_Pointer (STRUCT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.5 typRuleBase (STRUCT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

5 80 Status 21
5.1 Status (GVL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.2 eStatus (ENUM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

6 ParameterList (PARAMS) 24

7 VersionHistory (GVL) 25

8 Library Reference 26
8.1 SysMem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
8.1.1 Library Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
8.1.2 Library Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
8.2 WagoAppFileDir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
8.2.1 Library Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
8.2.2 Library Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
8.2.3 Library Parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.3 WagoAppString . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.3.1 Library Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.3.2 Library Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.4 WagoSysErrorBase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.4.1 Library Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.4.2 Library Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.4.3 Library Parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
8.5 WagoSysFileDir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.5.1 Library Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.5.2 Library Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.6 WagoSysStandard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.6.1 Library Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.6.2 Library Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.7 WagoSysVersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.7.1 Library Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.7.2 Library Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.8 WagoTypesErrorBase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.8.1 Library Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.8.2 Library Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

ii
CHAPTER 1

Description

This document is automatically generated. Because of this, the chapter 30 Visualization is not shown in this
document. If you are interested in getting to know more about visualization, we refer to the library manager of
e!Cockpit.
Subject to Changes
WAGO Kontakttechnik GmbH & Co. KG reserves the right to provide for any alterations or modifications. WAGO
Kontakttechnik GmbH & Co. KG owns all rights arising from the granting of patents or from the legal protection
of utility patents. Third-party products are always mentioned without any reference to patent rights. Thus, the
existence of such rights cannot be excluded.
Personnel Qualification
All tasks that are carried out with libraries made for the e!COCKPIT software must only be performed by qualified
electrical specialists instructed in PLC programming according to IEC 61131-3.
All tasks that have an effect on the properties or the behavior of automation hardware or software products must
only be performed by qualified employees with a thorough knowledge of handling the products concerned.
Intended Use of e!COCKPIT Libraries
Libraries created for the e!COCKPIT software are used to simplify the development of application projects in the
IEC 61131-3 programming languages.
For automation tasks, WAGO offers programmable logic controllers in a wide variety of performance classes.
In combination with a wide range of I/O modules, the controllers can process standard types of field signals.
Controllers can be implemented centrally or in decentralized configurations. The controllers offer interfaces for
the most commonly used fieldbuses for use in decentralized configurations. Fieldbus independent I/O modules
are then linked via fieldbus couplers. WAGO controllers offer a runtime environment for user programs called
e!RUNTIME. Software projects for implementation in e!RUNTIME environments can be created in e!COCKPIT.
The programming environment in e!COCKPIT is based on the established CODESYS 3 industrial standard. Users
with a previous knowledge of CODESYS 3 will thus find this environment largely familiar. The following pro-
gramming languages of the IEC 61131-3 standard are available:
• Structured Text (ST)
• Ladder Diagram (LD)
• Function Block Diagram (FBD)
• Instruction List (IL)
• Sequential Function Chart (SFC)

1
WagoAppJSON, Release 1.1.0.11

• Continuous Function Chart (CFC)


The individual programming languages can also be combined as required during the development of the software.
A portfolio of prepared libraries can be accessed for many frequently used functions in order to make software
development more efficient. This document provides an overview of the WagoAppJSON that WAGO offers for
e!COCKPIT.
Function block supporting JSON data handling1
Further library information are summerized here:
Company WAGO
Title WagoAppJSON
Version 1.1.0.11
Categories WAGO FunctionalView; WAGO FunctionalView|Connectivity; WAGO LayerView|App;
Application
Author WAGO / u010663
Placeholder WagoAppJSON

Based on WagoAppJSON.library, last modified 23.10.2020, 13:43:56. LibDoc 3.5.15.30

2
CHAPTER 2

10 Documentation

2.1 doc10_SystemProperties (FB)


Please check the Wago homepage for an application note a2019003 providing additional documentation.

3
CHAPTER 3

20 Program Organization Units

3.1 10 Main
3.1.1 FbWrite_ToIEC_ByRule (FB)
Interface variables

Scope Name Type Comment


sPathBase STRING Token name of the array element within the
JSON source. Must start with “/”, e.g.
/Data_Objects/
Input pDataIn POINTER TO ARRAY Pointer to the JSON source
[0..JSON_MAX_DATA_LENGTH]
OF BYTE
udiSizeDataIn
UDINT Size of the JSON source
aRule ARRAY An array containing the rule
[0..MAX_ARRAY_ELEMENTS_CUSTOM]
OF typRuleBase
pIecVariablePOINTER TO ARRAY [0..3] Adr(MyData) -> MyData:ARRAY[0..1] OF
OF BYTE typCustomData;
iArraySizeIecVariable
INT Number of elements in the array, e.g. 2 ->
MyData:ARRAY[0..1] OF typCustomData;
udiSizeIecVariable
UDINT Number of bytes in the Iec variable,
sizeof(MyData) -> MyData:ARRAY[0..1]
OF typCustomData;
xError BOOL Error occured
Output
iActualArrayRow
INT Actual processed row
Inout xTrigger BOOL Start conversion. Will be reset by the
function block
Function
Write a JSON string to a variable defind by the user within the IEC-61131 program
Graphical Illustration

4
WagoAppJSON, Release 1.1.0.11

Fig. 3.1: Graphical Interface of FbWrite_ToIEC_ByRule

Function Description
This function block imports JSON data, which is stored as an array, to a codesys variable.
JSON data may look like:

{
“Data_Objects”:[
{ “t1”: 15199355, “chan”: 5, “rx”: 1.9, “payload”:”567”},
{ “t1”: 1519935777, “chan”: 2, “rx”: 5.1, “payload”: “110a000f00551001”}
]
}

Therefore a variable may be defined as:

VAR
MyJsonData:ARRAY[0..1] OF typCustomData;
END_VAR

with

{attribute 'pack_mode' := '0'}


TYPE typCustomData :
STRUCT
t1 :UINT;
chan :BYTE;
rx :REAL;
payload :STRING;
END_STRUCT
END_TYPE

To allow the conversion, a rule must be defind:


bTestRule:ARRAY[0..MAX_ARRAY_ELEMENTS_CUSTOM] OF typRuleBase:=[

(sPath:=’t1’,iConvertType:=eUint),
(sPath:=’chan’,iConvertType:=eByte),
(sPath:=’rx’,iConvertType:=eReal),
(sPath:=’payload’,iConvertType:=eString)
];

Supported data types:

3.1. 10 Main 5
WagoAppJSON, Release 1.1.0.11

eWORD := 0,
eBYTE:=1,
eBool:=2,
eReal:=3,
eString:=4,
eInt:=5,
eTime:=6,
eUint:=7,

Example

VAR
MyJson_string: STRING(5000):='
{
"Data_Objects":[
{ "tmst": 1519935596, "chan": 5, "rfch": 1, "freq": 869525,
˓→ "stat": 1, "modu": "LORA", "datr": "SF8BW125", "payload":"567"},

{ "tmst": 1519935777, "chan": 2, "rfch": 5, "freq": 49,


˓→"stat": 3, "modu": "RART", "datr": "SF8BW126", "payload": "110a000f00551001"},

{ "tmst": 1519935779, "chan": 4, "rfch": 99, "freq": 9,


˓→"stat": 099, "modu": "R23", "datr": "SF8BW126", "payload": "000f00551444"}

]
}';

MyRule:ARRAY[0..MAX_ARRAY_ELEMENTS_CUSTOM] OF typRuleBase:=[
(sPath:='tmst',iConvertType:=eUint),
(sPath:='chan',iConvertType:=eByte),
(sPath:='rfch',iConvertType:=eByte),
(sPath:='freq',iConvertType:=eUint),
(sPath:='stat',iConvertType:=eByte),
(sPath:='modu',iConvertType:=eString),
(sPath:='datr',iConvertType:=eString),
(sPath:='payload',iConvertType:=eString)
];

MyJsonData:ARRAY[0..2] OF typMyCustomData;

END_VAR

{attribute 'pack_mode' := '0'}


TYPE typMyCustomData :
STRUCT
tmst :UINT;
chan :BYTE;
rfch :BYTE;
freq :UINT;
stat :BYTE;
modu :STRING;
datr :STRING;
payload :STRING;
END_STRUCT
END_TYPE

3.1.2 Fb_JSON_ParseAndModify (FB)


Interface variables

3.1. 10 Main 6
WagoAppJSON, Release 1.1.0.11

Scope Name Type Comment


pData POINTER TO ARRAY Use ADR(myJSONData), with the variable
Input
[0..JSON_MAX_DATA_LENGTH] “myJSONData” containing the JSON data
OF BYTE
udiSizeDataUDINT Size of variable pointed by input pData.
oStatus WagoSysErrorBase. Status details
FbResult
Output
xError BOOL Error occured
xDone BOOL Done without error
diToken DINT Number of generated tokens
Inout xTrigger BOOL Start parsing the data. Will be reset by
function block
Function
Parse a JSON string and allow reading and modifying JSON values
Graphical Illustration

Fig. 3.2: Graphical Interface of Fb_JSON_ParseAndModify

Function Description
Using this block, needs at least one time running the build up process by using input xTrigger. The method
GetValueByPath allows reading a JSON value. The method SetValueByPath allows writing a JSON
value.

Fb_JSON_ParseAndModify.GetValueByPath (METH)
Interface variables

Scope Name Type Comment


Return GetValueByPath typJSON_Pointer
Input sPointer STRING(SIZE_JSON_POINTER) String that contains the JSON
Pointer
Inout xTrigger BOOL Activate methode
Function
This method allows reading a JSON value identified by sPointer according to JSON pointer syntax (RFC6901):
Graphical Illustration

3.1. 10 Main 7
WagoAppJSON, Release 1.1.0.11

Fig. 3.3: Graphical Interface of Fb_JSON_ParseAndModify.GetValueByPath

Function Description
Example JSON string:
json_string2: STRING(400):='{
"Vendor" : "WAGO",}
"VendorID": null,
"Product" : [
{"Ordernumber": "750-8204", "CpuMHz": 600,"Fieldbus": ["CanOpen
˓→","Modbus"],"SdCard": true},

{"Ordernumber": "750-8206", "CpuMHz": 600,"Fieldbus": [


˓→"Profibus","CanOpen","Modbus"],"SdCard": true}

]
}';

Pointer examples and corresponding return values:


sPointer sValue eType eReturn
/Vendor ‘WAGO’ JSON_STRING JSON_SUCCESS
/VendorID ‘null’ JSON_NULL JSON_SUCCESS
/Product/0/CpuMHz ‘600’ JSON_NUMBER JSON_SUCCESS
/Product/0/SdCard ‘true’ JSON_BOOL JSON_SUCCESS
/Prod- ‘Modbus’ JSON_STRING JSON_SUCCESS
uct/0/Fieldbus/1
/Prod- ‘Profibus’ JSON_STRING JSON_SUCCESS
uct/0/Fieldbus/0
/Prod- ‘CanOpen’ JSON_STRING JSON_SUCCESS
uct/1/Fieldbus/1
/Prod- ‘Modbus’ JSON_STRING JSON_SUCCESS
uct/1/Fieldbus/0
/ ‘ERROR:..’ JSON_INVALID JSON_ERROR_INVALIDPOINTER
/Prod- ‘ERROR:..’ JSON_INVALID JSON_ERROR_BOUND
uct/99/CpuMHz

Fb_JSON_ParseAndModify.SetValueByPath (METH)
Interface variables

Scope Name Type Comment


Return SetValueByPath typJSON_Pointer
sPointer STRING(SIZE_JSON_POINTER) String that contains the JSON
Input
Pointer
sValue STRING Value, already converted to string
Inout xTrigger BOOL Activate methode
Function
This method allows writing a JSON value identified by sPointer according to JSON pointer syntax (RFC6901):
Graphical Illustration

3.1. 10 Main 8
WagoAppJSON, Release 1.1.0.11

Fig. 3.4: Graphical Interface of Fb_JSON_ParseAndModify.SetValueByPath

3.1.3 Fb_JSON_Writer_01 (FB)


Interface variables

Scope Name Type Comment


Input sJSON_BaseFrame String containing the general JSON data
STRING(JSON_MAX_STRING)
oStatus WagoSysErrorBase. Status details
Output FbResult
xError BOOL Error occured
xDone BOOL JSON data generated without error
Input POINTER TO STRING
aParameterValues An array containing the variable JSON values, start
index must be 0 e.g. [0..9]
xTrigger BOOL Activate the build process
Inout
sOutput Result string
STRING(JSON_MAX_STRING)
Function
Generate a JSON string from a base template and an array with appropriate JSON values
Graphical Illustration

Fig. 3.5: Graphical Interface of Fb_JSON_Writer_01

Function Description
This function block generates a JSON string sOutput.
All variable values must be replaced by #Parameter to allow inserting the actual values from the input
aParameterValues.
Note For each #Parameter a appropriate value must exist within the aParameterValues input.
Example
The following JSON string should be generated:
{“Menu”:

3.1. 10 Main 9
WagoAppJSON, Release 1.1.0.11

{“id”: “CountryCode”,
“value”: “DE”,
“popup”: {“menuitem”:
[{“value”: “4.1”,”onclick”: “down1”},
{“value”: “4.2”,”onclick”: “down2”},
{“value”: “4.3”,”onclick”: “down3”}]
}
}
}

//Define a template string, which contains ``#Parameter`` wherever a variable


˓→value should be inserted.

VAR
MyTemplateString:String(JSON_MAX_STRING):='
{"Menu": {"id": "#Parameter","value": "#Parameter","popup": {"menuitem": [{
˓→"value": "#Parameter","onclick": "#Parameter"},{"value": "#Parameter","onclick":

˓→"#Parameter"},

{"value": "#Parameter","onclick": "#Parameter"}]}}}


';
// Define a second variable from type array which contains the variable values
˓→already converted to a string.

MyValueArray:ARRAY[0..7] OF STRING:=['CountryCode','DE','4.1','down1','4.2',
˓→'down2','4.3','down3'];

END_VAR

3.2 20 Advanced
3.2.1 FbJson_Advanced (FB)
Interface variables

Scope Name Type Comment


sFilename STRING
Input xRead BOOL Import JSON data to Iec variable
xWrite BOOL Export JSON data from Iec variable
xTrigger BOOL Activate method
Inout
sJSONData STRING(MAX_JSON_FILE_SIZE) JSON data
xBusy BOOL Method active
Output xError BOOL Error occured
sStatus STRING Status information
Function
This function block provides the base methods which are needed by the WagoJSON.py python script.
WagoJSON.py will automatically generate a function block FbUserJson to read and write a JSON string into or
from an IEC variable.
Graphical Illustration

3.2. 20 Advanced 10
WagoAppJSON, Release 1.1.0.11

Fig. 3.6: Graphical Interface of FbJson_Advanced

Function Description
An IEC variable must be defined by the user. The variable must be of typMain.
e.g.:

TYPE typMain:
STRUCT
EDL_DataBase: typElement;
END_STRUCT
END_TYPE

Note A type definition is only allowed in derived types or as a basic type but not in both ways at the same time.
Example
Refere to chapter 10 Documentation

Datentypen
BaseDataMethods

FbJson_Advanced.aArrayBool (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING
Input
aBool POINTER TO BOOL Array muss bei Null anfangen

FbJson_Advanced.aArrayByte (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING
Input
aByte POINTER TO BYTE ARRAY muss bei Null anfangen

FbJson_Advanced.aArrayDword (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING
Input
aDword POINTER TO DWORD ARRAY muss bei Null anfangen

3.2. 20 Advanced 11
WagoAppJSON, Release 1.1.0.11

FbJson_Advanced.aArrayInt (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING
Input
aInt POINTER TO ?????? besser mit * arbeiten, Array muss bei Null
INT anfangen

FbJson_Advanced.aArrayReal (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING
Input
aReal POINTER TO ?????? besser mit * arbeiten, Array muss bei Null
REAL anfangen

FbJson_Advanced.aArrayString (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING(JSON_MAX_STRING_RESULT)
Input
aString POINTER TO ARRAY muss bei Null
STRING(JSON_MAX_STRING_RESULT) anfangen

FbJson_Advanced.aArrayWord (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING
Input
aWord POINTER TO WORD ARRAY muss bei Null anfangen

FbJson_Advanced.aArray_ArrayBool (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING
Input
aBOOL POINTER TO BOOL ARRAY muss bei Null anfangen

FbJson_Advanced.aArray_ArrayByte (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING
Input
aByte POINTER TO BYTE ARRAY muss bei Null anfangen

FbJson_Advanced.aArray_ArrayDword (METH)

Interface variables

3.2. 20 Advanced 12
WagoAppJSON, Release 1.1.0.11

Scope Name Type Comment


sArrayName STRING
Input
aDword POINTER TO DWORD ARRAY muss bei Null anfangen

FbJson_Advanced.aArray_ArrayREAL (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING
Input
aREAL POINTER TO REAL ARRAY muss bei Null anfangen

FbJson_Advanced.aArray_ArrayString (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING(JSON_MAX_STRING_RESULT)
Input
aString POINTER TO ARRAY muss bei Null
STRING(JSON_MAX_STRING_RESULT) anfangen

FbJson_Advanced.aArray_ArrayWord (METH)

Interface variables

Scope Name Type Comment


sArrayName STRING
Input
aWord POINTER TO WORD ARRAY muss bei Null anfangen

FbJson_Advanced.MyFileClose (METH)

3.3 30 Sax_Parser
3.3.1 FbJSON_Handler (FB)
Function
This function block must be extended by an own function block. The different methods may be used according to
the special needs of each application.
Graphical Illustration

Fig. 3.7: Graphical Interface of FbJSON_Handler

FbJSON_Handler.JSON_ArrayClosed (METH)
Function
Called each time an array close “]” has been evaluated
Graphical Illustration

3.3. 30 Sax_Parser 13
WagoAppJSON, Release 1.1.0.11

Fig. 3.8: Graphical Interface of FbJSON_Handler.JSON_ArrayClosed

FbJSON_Handler.JSON_ArrayDetected (METH)
Function
Called each time an array open “[” has been evaluated
Graphical Illustration

Fig. 3.9: Graphical Interface of FbJSON_Handler.JSON_ArrayDetected

FbJSON_Handler.JSON_DataFinished (METH)
Function
This method is called after the last byte has been detected
Graphical Illustration

Fig. 3.10: Graphical Interface of FbJSON_Handler.JSON_DataFinished

FbJSON_Handler.JSON_KeyDetected (METH)
Interface variables

Scope Name Type Comment


Input sJSON_Object STRING JSON key
Function
Called each time a JSON key has been evaluated
Graphical Illustration

3.3. 30 Sax_Parser 14
WagoAppJSON, Release 1.1.0.11

Fig. 3.11: Graphical Interface of FbJSON_Handler.JSON_KeyDetected

FbJSON_Handler.JSON_NullDetected (METH)
Function
Graphical Illustration

Fig. 3.12: Graphical Interface of FbJSON_Handler.JSON_NullDetected

FbJSON_Handler.JSON_ObjectClosed (METH)
Function
Called each time an object close “}” has been evaluated
Graphical Illustration

Fig. 3.13: Graphical Interface of FbJSON_Handler.JSON_ObjectClosed

FbJSON_Handler.JSON_ObjectDetected (METH)
Interface variables

Scope Name Type Comment


Input udiJSON_ObjectCounter UDINT JSON object counter
Function
Called each time an object open “{” has been evaluated
Graphical Illustration

Fig. 3.14: Graphical Interface of FbJSON_Handler.JSON_ObjectDetected

3.3. 30 Sax_Parser 15
WagoAppJSON, Release 1.1.0.11

FbJSON_Handler.JSON_ValueDetected (METH)
Interface variables

Scope Name Type Comment


Input sJSON_Value STRING(JSON_MAX_STRING_SAX) JSON value
Function
Called each time a JSON value has been evaluated
Graphical Illustration

Fig. 3.15: Graphical Interface of FbJSON_Handler.JSON_ValueDetected

3.3.2 FbJSON_Sax_Parser (FB)


Interface variables

Scope Name Type Comment


pData POINTER TO ARRAY Use ADR(myJSONData), with the variable
Input [0..JSON_MAX_DATA_LENGTH] “myJSONData” containing the JSON data
OF BYTE
udiSizeDataUDINT Size of variable pointed by input pData.
sFileName STRING Name of a file containing the JSON data
Inout xTrigger BOOL Start parsing process
oStatus WagoSysErrorBase. Status details
FbResult
Output xDone BOOL Done
xError BOOL Error occured
udiValueCount
UDINT Counter for detected key value pairs
iChunksCompleted
INT Chunk counter
Function
This function block parses the JSON data.
Graphical Illustration

Fig. 3.16: Graphical Interface of FbJSON_Sax_Parser

3.3. 30 Sax_Parser 16
WagoAppJSON, Release 1.1.0.11

Description
This function block allows parsing JSON data either from input pData or from a file assigned to input
sFileName. An appropriate JSON handler function block must be programmed to take care of the data.
Use method RegisterParserListener to assign an appropriate JSON handler.
File handling maybe controlled by the parameter JSON_SAX_CHUNK_SIZE.

VAR
FbMyJSON_Handler_0 : FbMyJSON_Handler;
myData : typMyData;
FbJSON_Sax_Parser_0 : FbJSON_Sax_Parser(FbMyJSON_Handler_0);

sTest_2 : STRING(255):=
'{
"id":"2ab06eaa-6417-41c8-beca-
˓→ 3d2bb92cdd98",
"source":"mockup",
"specversion":"0.2",
"relation":"noData"
}';

go1 : BOOL;
myValueCount : UDINT;
END_VAR

An example may look like:

IF go1 THEN
FbJSON_Sax_Parser_0.RegisterParserListener(FbMyJSON_Handler_0);
FbMyJSON_Handler_0(typMyData:=MyData); //the handler must be called before the
˓→parser is activated, input ``typMyData`` must be assigned

FbJSON_Sax_Parser_0(
pData:=ADR(sTest_2) ,
udiSizeData:=SIZEOF(sTest_2) ,
sFileName:= ,
xTrigger:=go1 ,
oStatus=> ,
xDone=> ,
xError=> ,
udiValueCount=>myValueCount ,
iChunksCompleted=> );
END_IF

FbJSON_Sax_Parser.RegisterParserListener (METH)
Interface variables

Scope Name Type Comment


Input I_ParserListener A function block extended from FbJSON_Handler
I_ParserListener
must be assigned to this input
Function
This method registers a JSON handler to this parser.
Graphical Illustration

3.3. 30 Sax_Parser 17
WagoAppJSON, Release 1.1.0.11

Fig. 3.17: Graphical Interface of FbJSON_Sax_Parser.RegisterParserListener

3.3. 30 Sax_Parser 18
CHAPTER 4

29 Data types

4.1 eJsonRuleType (ENUM)


Name Initial
0
eWORD
1
eBYTE
2
eBool
3
eReal
InOut: 4
eString
5
eInt
6
eTime
7
eUint
100
eString10

4.2 eType (ENUM)


Name Initial
-1
JSON_INVALID
0
JSON_UNDEFINED
1
JSON_OBJECT
2
InOut: JSON_ARRAY
3
JSON_STRING
4
JSON_NUMBER
5
JSON_BOOL
6
JSON_NULL

19
WagoAppJSON, Release 1.1.0.11

4.3 typAuxiliaries (STRUCT)


Name Type
aWerte ARRAY [0..JSON_MAX_STRING_SAX] OF BYTE
n INT
SkipNextComma BOOL
InOut: auxValueInWork BOOL
auxReverseSolidusDetected BOOL
auxJSONString BOOL
udiValueCount UDINT
udiJSON_ObjectCounter UDINT

4.4 typJSON_Pointer (STRUCT)


Name Type Comment
eReturn eResult 0 = Values are valid, <0 = Values invalid
eType eType Type of sValue: JSON_STRING, JSON_NUMBER,
InOut:
JSON_BOOL, JSON_NULL or JSON_INVALID in case of
error
sValue Value or Error message
STRING(JSON_POINTER_RESULT)

4.5 typRuleBase (STRUCT)


Name Type
InOut: sPath STRING(255)
iConvertType eJsonRuleType

4.3. typAuxiliaries (STRUCT) 20


CHAPTER 5

80 Status

5.1 Status (GVL)


Description Status information

21
WagoAppJSON, Release 1.1.0.11

Value Level Description


eStatus.OK WagoSysError- ‘OK’
Base.WagoTypes.eSeverity.info
eSta- WagoSysError- ‘Not enough tokens were
tus.JSON_ERROR_NOMEM Base.WagoTypes.eSeverity.error
provided’
eSta- WagoSysError- ‘Invalid character inside JSON
tus.JSON_ERROR_INVAL Base.WagoTypes.eSeverity.error
String’
eStatus.JSON_ERROR_PART WagoSysError- ‘The string is not a full JSON
Base.WagoTypes.eSeverity.error
packet
eSta- WagoSysError- ‘Invalid input parameter’
tus.JSON_ERROR_PARAMETERBase.WagoTypes.eSeverity.error
eSta- WagoSysError- ‘JSON pointer should start with
tus.JSON_ERROR_START Base.WagoTypes.eSeverity.error
/’
eSta- WagoSysError- ‘Invalid JSON pointer syntax’
tus.JSON_ERROR_SYNTAX Base.WagoTypes.eSeverity.error
eSta- WagoSysError- ‘JSON pointer should reference
tus.JSON_ERROR_INVALIDPOINTER
Base.WagoTypes.eSeverity.error
an existing JSON value’
eSta- WagoSysError- ‘Array index should not contain
tus.JSON_ERROR_LEADINGZERO
Base.WagoTypes.eSeverity.error
leading zeros’
eSta- WagoSysError- ‘Function supports a maximum
tus.JSON_ERROR_MAXINDEX Base.WagoTypes.eSeverity.error
of 65535 array indexes’
eSta- WagoSysError- ‘Array index exceeds upper
tus.JSON_ERROR_BOUND Base.WagoTypes.eSeverity.error
bound! Valid indexes: 0..MAX’
eSta- WagoSysError- ‘JSON pointer should reference a
tus.JSON_ERROR_NOSINGLE Base.WagoTypes.eSeverity.error
single JSON value’
eSta- WagoSysError- ‘Something went completely
tus.JSON_ERROR_FATAL Base.WagoTypes.eSeverity.error
wrong’
eSta- WagoSysError- ‘Parser not yet initialized’
tus.JSON_ERROR_PARSER Base.WagoTypes.eSeverity.error
eSta- WagoSysError- ‘Constant
tus.JSON_ERROR_ARRAY_PATHBase.WagoTypes.eSeverity.error
JSON_MAX_ARRAY_SIZE too
small’
eSta- WagoSysError- ‘File close failed’
tus.JSON_ERROR_FILE_CLOSEBase.WagoTypes.eSeverity.error
eSta- WagoSysError- ‘File open failed’
tus.JSON_ERROR_FILE_OPEN Base.WagoTypes.eSeverity.error
eSta- WagoSysError- ‘No parser registered
tus.JSON_ERROR_NO_PARSER_REGISTERED
Base.WagoTypes.eSeverity.error

5.2 eStatus (ENUM)


Attributes:
qualified_only

5.2. eStatus (ENUM) 22


WagoAppJSON, Release 1.1.0.11

Name Initial Comment


0 Operation successfully executed
OK
1 ERROR: Not enough tokens were provided
JSON_ERROR_NOMEM
2 ERROR: Invalid character inside JSON String
JSON_ERROR_INVAL
3 ERROR: The string is not a full JSON packet, more
JSON_ERROR_PART
bytes expected
4 ERROR: Invalid input parameter!
JSON_ERROR_PARAMETER
5 ERROR: JSON pointer should start with /
JSON_ERROR_START
6 ERROR: Invalid JSON pointer syntax!
JSON_ERROR_SYNTAX
7 ERROR: JSON pointer should reference an existing
JSON_ERROR_INVALIDPOINTER
JSON value!
8 ERROR: Array index should not contain leading
JSON_ERROR_LEADINGZERO
InOut: zeros!
9 ERROR: Function supports a maximum of 65535
JSON_ERROR_MAXINDEX
array indexes
10 ERROR: Array index exceeds upper bound! Valid
JSON_ERROR_BOUND
indexes: 0..MAX
11 ERROR: JSON pointer should reference a single
JSON_ERROR_NOSINGLE
JSON value!
12 ERROR: Something went completely wrong!
JSON_ERROR_FATAL
20 ERROR: Parser not yet initialized
JSON_ERROR_PARSER
21 ERROR: Constant JSON_MAX_ARRAY_SIZE too
JSON_ERROR_ARRAY_PATH
small
22 ERROR: File close failed
JSON_ERROR_FILE_CLOSE
23 ERROR: File open failed
JSON_ERROR_FILE_OPEN
24 ERROR: no parser registered
JSON_ERROR_NO_PARSER_REGISTERED
Description Status information

5.2. eStatus (ENUM) 23


CHAPTER 6

ParameterList (PARAMS)

Scope Name Type Initial Comment


UDINT 65535 used by Fb_JSON_ParseAndModify
JSON_MAX_DATA_LENGTH
and FbJSON_Sax_Parser to define the
size of JSON data
UDINT 100 used by Fb_JSON_ParseAndModify to
JSON_MAX_TOKEN_COUNT
define the maximum number of token
INT 255 used by Fb_JSON_ParseAndModify to
SIZE_JSON_POINTER
define the size of a JSON pointer string
Constant UDINT 2000 used by Fb_JSON_Writer_01
JSON_MAX_STRING
STRING ‘#Parame- used by Fb_JSON_Writer_01
JSON_REPLACE_STRING
ter’
INT 170 used by GetValueByArrayPath
JSON_MAX_ARRAY_SIZE
UDINT 6000 used by FbUserJson and
MAX_JSON_FILE_SIZE
FbJson_Advanced
INT 7 used by FbWrite_ToIec_ByRule
MAX_ARRAY_ELEMENTS_CUSTOM
InOut: INT 2000 used by FbJSON_Sax_Parser
JSON_MAX_STRING_SAX
BOOL FALSE used by FbJSON_Sax_Parser to
JSON_NAME_ARRAY_BY_INDEX_SAX
differentiate the export format of the
base array
INT 255 used by Fb_JSON_ParseAndModify to
JSON_POINTER_RESULT
define the size of a JSON string result
UDINT 10000 Used by FbJSON_Sax_Parser to define
JSON_SAX_CHUNK_SIZE
the amount of data parsed by one read
operation
UDINT 50000 Used by FbJSON_Advanced to define
JSON_ADVANCED_CHUNK_SIZE_IMPORT
the amount of data imported each time
(not less than 35000)
UDINT 50000 Used by FbJSON_Advanced to define
JSON_ADVANCED_CHUNK_SIZE_EXPORT
the amount of data written to the file in
one operation
UDINT 80 used by FbJson_Advanced
JSON_MAX_STRING_RESULT

24
CHAPTER 7

VersionHistory (GVL)

WagoAppJSON.library
date version author change
04.08.2020 1.1.0.11 u010663 Method JSON_ValueDetected new string length
JSON_MAX_STRING_SAX
24.06.2020 1.1.0.10 u010663 Status attribute qualified only set
15.06.2020 1.1.0.9 u010663 Internal improvement
04.06.2020 1.1.0.7 u010663 Bugfix FbJson_Advanced
02.06.2020 1.1.0.6 u010663 Bugfix FbJson_Advanced
16.04.2020 1.1.0.5 u010663 Add two dimensional arrays in FbJson_Advanced
16.04.2020 1.1.0.2 u010663 Improve robustness FbJson_Advanced
09.04.2020 1.1.0.1 u010663 Enhancement data type null
08.04.2020 1.1.0.0 u010663 Enhancement FbJson_Advanced, FbJSON_Sax_Parser
31.03.2020 1.0.2.3 u010663 Bugfix FbJson_Advanced
20.01.2020 1.0.2.2 u010663 Bugfix FbJSON_Sax_Parser
10.12.2019 1.0.2.1 u010663 Documentation improved
03.04.2019 1.0.2.0 u010663 New FbJSON_Sax_Parser
04.03.2019 1.0.1.3 u010663 Documentation issues FbWrite_ToIEC_ByRule
11.02.2019 1.0.1.2 u010663 Improve documentaion function block Fb_Json_Writer_01
07.01.2019 1.0.0.0 u010663 Release
Release Notes:

25
CHAPTER 8

Library Reference

This is a dictionary of all referenced libraries and their name spaces.

8.1 SysMem
8.1.1 Library Identification
Placeholder: SysMem
Default Resolution: SysMem, * (System)
Namespace: SysMem

8.1.2 Library Properties


• LinkAllContent: False
• QualifiedOnly: False
• Key: SysMem
• SystemLibrary: False
• Optional: False

8.2 WagoAppFileDir
8.2.1 Library Identification
Placeholder: WagoAppFileDir
Default Resolution: WagoAppFileDir, * (WAGO)
Namespace: WagoAppFileDir

8.2.2 Library Properties


• LinkAllContent: False
• QualifiedOnly: False
• Key: WagoAppFileDir
• SystemLibrary: False
• Optional: False

26
WagoAppJSON, Release 1.1.0.11

8.2.3 Library Parameter


Parameter: STANDARDSCHEDULINGMODE = eSchedulingMode.AsyncLow

Parameter: STANDARDTIMEOUT = TIME#10s0ms

8.3 WagoAppString
8.3.1 Library Identification
Placeholder: WagoAppString
Default Resolution: WagoAppString, * (WAGO)
Namespace: WagoAppString

8.3.2 Library Properties


• LinkAllContent: False
• QualifiedOnly: True
• Key: WagoAppString
• SystemLibrary: False
• Optional: False

8.4 WagoSysErrorBase
8.4.1 Library Identification
Placeholder: WagoSysErrorBase
Default Resolution: WagoSysErrorBase, * (WAGO)
Namespace: WagoSysErrorBase

8.4.2 Library Properties


• LinkAllContent: False
• QualifiedOnly: False
• Key: WagoSysErrorBase
• SystemLibrary: False
• PublishSymbolsInContainer: True
• Optional: False

8.4.3 Library Parameter


Parameter: RES_LOG_MAX_FILESIZE = 2000

Parameter: RES_LOG_MAX_FILES = 1

Parameter: RES_LOG_MAX_ENTRIES = 200

Parameter: RES_LOG_NAME = ‘WagoAppResultLogger’

8.3. WagoAppString 27
WagoAppJSON, Release 1.1.0.11

8.5 WagoSysFileDir
8.5.1 Library Identification
Placeholder: WagoSysFileDir
Default Resolution: WagoSysFileDir, * (WAGO)
Namespace: WagoSysFileDir

8.5.2 Library Properties


• LinkAllContent: False
• QualifiedOnly: False
• Key: WagoSysFileDir
• SystemLibrary: False
• Optional: False

8.6 WagoSysStandard
8.6.1 Library Identification
Placeholder: WagoSysStandard
Default Resolution: WagoSysStandard, * (WAGO)
Namespace: WagoSysStandard

8.6.2 Library Properties


• LinkAllContent: False
• QualifiedOnly: False
• Key: WagoSysStandard
• SystemLibrary: False
• Optional: False

8.7 WagoSysVersion
8.7.1 Library Identification
Name: WagoSysVersion
Version: 1.0.0.0
Company: WAGO
Namespace: WagoSysVersion

8.7.2 Library Properties


• LinkAllContent: False
• QualifiedOnly: False
• Key: WagoSysVersion, 1.0.0.0 (WAGO)
• SystemLibrary: False
• Optional: False

8.8 WagoTypesErrorBase
8.8.1 Library Identification
Placeholder: WagoTypesErrorBase

8.5. WagoSysFileDir 28
WagoAppJSON, Release 1.1.0.11

Default Resolution: WagoTypesErrorBase, * (WAGO)


Namespace: WagoTypesErrorBase

8.8.2 Library Properties


• LinkAllContent: False
• Optional: False
• QualifiedOnly: True
• Key: WagoTypesErrorBase
• SystemLibrary: False
• PublishSymbolsInContainer: True
© WAGO Kontakttechnik GmbH & Co. KG, Germany 2018 – All rights reserved. For the avoidance of doubt,
this copyright notice does not only apply to the information above but also and primarily to the described library
itself. Please note that third-party products are always mentioned without reference to intellectual property rights,
including patents, utility models, designs and trademarks, accordingly the existence of such rights cannot be
excluded. WAGO is a registered trademark of WAGO Verwaltungsgesellschaft mbH.

8.8. WagoTypesErrorBase 29

You might also like