Skip to content

Risele/CodesysJSONFile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodesysJSONFile

Read JSON file to CODESYS Structs

Uses the PRO JSON lib by TVM, version 1.0.0.16

Usage

Some customization of FB required:

For each JSON object you should provide two types of structs:

  • Your normal DUT (YOUR_STRUCT, YOUR_SUB_STRUCT in example)
  • JSONVAR DUTs (note! names should match JSON file exactly) (JS_YOUR_STRUCT, JS_YOUR_SUB_STRUCT in example)

That should be done for every JSON object type. Core:

Structs for core object

And inner:

Structs for inner object

And converting methods

  • For top-most JSON object (CORE_JS_TO_ST in example)
  • And for inner JSON objects (SUB_JS_TO_ST in example)

Also you should specify your DUTs in function block and maximum possible array size of the topmost object (see Limitations/Arrays )

FB-tuning

Limitations

Memory

Well, it's memory-consuming. The memory usage is specified by changing constants at GPL_JSON list in PRO_JSON library section.

Naming

The names in JSON and in ST-based JSONVARs should match exactly. For JSON fields of

{"field":"value",
 "otherField":3.14
}

ST-struct should be:

TYPE JSONST
STRUCT
	field  :  		JSONVAR;
	otherField:		JSONVAR;
END_STRUCT
END_TYPE

Arrays

The Array could not be topmost structure:

[
{"obj": "value"},
{"obj": "value"}
]

This is NOT valid.

The topmost array should be named:

{"myArr":
[
{"obj": "value"},
{"obj": "value"}
]}

The corresponging ST structure is

TYPE JSONST
STRUCT
	obj  :  		JSONVAR;
END_STRUCT
END_TYPE

And the name of the array in the ST code should match the JSON exactly:

VAR
  myArr: ARRAY[1..10] OF JSONST;
END_VAR

UTF8

Do not work with non-english UTF8 symbols (or I failed to do this).

Application name

Application name should match to specified in GPL_JSON list in PRO_JSON library section ('Application' by default)

Requirements:

For Cyryllic symols use Win-1251 (CP1251) encoding. Use Owen String Utils to deal with CP1251->WStrings

Use iconv from Linux to convert file encoding if needed.

About

Read JSON file to CODESYS Structs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published