Lasse Hedeby

Sharing my passion for automation, programming, IT and other geeky stuff

JSON is a very powerful and simple way of arranging data and exchange it between systems.

https://www.json.org/
https://www.w3schools.com/js/js_json_intro.asp

JSON parser comes for almost every PC based programming language, but not PLC’s, so I started my own.

This parser can read and write JSON in Siemens SIMATIC S7-12xx/S7-15xx PLC’s.
There are some limitations though;

Only strings, numbers and booleans are supported.
No spaces between characters.

 
// Test string 
#tempJSON := '{"name":"Lasse","age":35,"sex":"male","birthDay":"1984-03-02"}'; 
// Convert string to Char array 
Strg_TO_Chars(Strg:=#tempJSON,              
              pChars:=0,               
              Cnt=>#tempCnt,               
              Chars:=#tempChar); 
// Read JSON
"gFBJSONRead"(json:=#tempChar); 

JSON is very useful when systems has to exchange data in e.g. TCP/IP socket communication. Traditionally data exchange has to be documented and agreed on between systems, to have the same data structure for the byte stream. With JSON, this is not needed anymore, and the data and values can be arranged differently but, still understood on all systems.

Attachments:

April 15th, 2019

Posted In: Automation, S7-1200/1500, SIMATIC, Structured Text (SCL/ST)

Tags: , , , ,