This application example demonstrates the usage of the JSON Library
This application example consists of two parts.
- Showing the usage of the library in a PLC Program, which can be downloaded to a 1500 PLC or PLCSIM Advanced
- Many examples as UnitTest in the
test
folder
-
Open a command line interface (CLI) and switch to the target folder. Example, if the traget folder is D:\temp
D: cd \temp
-
Install the application example on your local PC
Run the following commands in a CLI
apax create @simatic-ax/ae-json-library --registry https://npm.pkg.github.com ae-json-library
Switch to the project directory
cd ae-json-library
install the dependencies with:
apax install
and open AxCode
axcode .
The PLC program executes different steps:
-
CreateDocument1 Add an JSON element of type Integer with value
1234
in a empty JSON documentdoc
-
SerializeDocument1
doc.Serialize(doc.buffer) serializes the JSON document
doc
into the array of char (doc.buffer).Expected result in the array of char:
{"myInt": 1234}
In this step, the time for serializing will be measured and stored in the variable
TimeCreationDocument1
. The result od serializing will be stored in the string variableSerializedDocument1
-
ParseDocument1
Parse the JSON document
doc
for thekey = myInt
and get the value1234
-
ResetJSonDocument1
Delete all JSON elements in the JSON document
doc
. So it's possible to create a new JSON document with other JSON elements. -
CreateDocument2
Create a JSON document with nested JSON elements. Structure of nested JSON document:
doc | +- myBoolean(value = true) | +- myObject -+- myInt(value = 1234) | +- myDint(value = 12345678)
-
SerializeDocument2
doc.Serialize(doc.buffer) serializes the JSON document
doc
into the array of char (doc.buffer).Expected result in the array of char:
{"myBoolean": true, "myObject": {"myInt": 1234, "myDint": 12345678}}
In this step, the time for serializing will be measured and stored in the variable
TimeCreationDocument2
. The result od serializing will be stored in the string variableSerializedDocument2
-
ParseDocument2
Parse the JSON document
doc
for thekey = myDint
and get the value12345678
-
ResetJSonDocument2
Delete all JSON elements in the JSON document
doc
. So it's possible to create a new JSON document with other JSON elements.
-
Start a PLCSIM Advanced Instance or using a 1500 PLC. Download a TIA Portal created HWCN with a 1500 standard PLC (Default IP Address 192.168.0.1).
The default ip address can be changed in the
apax.yml
and in the.vscode/launch.json
IP_ADDRESS: "192.168.0.1"
{ "version": "0.2.0", "configurations": [ { "name": "Debug live on PLC", "type": "plc-debug", "request": "launch", "program": "${workspaceFolder}", "ip": "192.168.0.1" } ] }
-
If not open, open a terminal in AX Code (
CTRL+SHIFT+ö
) -
Start the application example
apax dlplc
1500
is required, if you use a real 1500 PLC instead of PLCSIM Advanced. -
Monitor variables with mon-File:
- Open the file
default.mon
- Enable monitoring
- Observe the values
- Open the file
Thanks for your interest in contributing. Anybody is free to report bugs, unclear documentation, and other problems regarding this repository in the Issues section or, even better, is free to propose any changes to this repository using pull requests.
This workspace will be checked by the markdownlint-cli (there is also documented ho to install the tool) tool in the CI workflow automatically.
To avoid, that the CI workflow fails because of the markdown linter, you can check all markdown files locally by running the markdownlint with:
markdownlint **/*.md --fix
Please read the Legal information