Read and write json file from a Beckhoff PLC
This is an opensource library that allows read and write json files for Beckhoff PLCs.
- NO Licence costs (This software is free also for commercial uses)
- supports the newest Json standard
- reads any Json body with complex nested structures (it also works with json lists of object as API response)
- parse any Json response to plc structure
- Install the unofficial TwinCAT Function TFU003 on your target system
- Install the TwinCAT Library to your project
Jump to Quick-Start using an Example
Download and reference the BeckhoffJsonReadWriter library and import it to your project.
You can now declare and call a json parser in your program and start using json files.
PROGRAM MAIN
VAR
parser : JsonParser;
END_VAR
parser(
Execute:=FALSE ,
File:= 'C:\temp\my-fancy-json.json',
ParseMethod:= 'ReadFile' , // or even 'WriteFile'
Content:= 'GVL.Variable',
HasError=> ,
ErrorId=> );
This software can parse and convert normal DUTs (also nested DUTs) into Json object thaks to the power of TwinCAT.JsonExtension. The only things you have to do is to add the JSON attribute to your code like follows and specify if your field has another json-name or can be used with its own name.
TYPE JsonDUT :
STRUCT
{attribute 'json' := 'message'}
sMessage : STRING;
iResponse : INT;
{attribute 'json' := 'status'}
sStatus : STRING;
{attribute 'json' := 'numbers'}
daNumbers : ARRAY[1..10] OF DINT := [1,2,3,4,5,6,7,8,9,10];
{attribute 'json'}
child : ChildDUT;
END_STRUCT
END_TYPE
Yes, please!
Try the library and feel free to open an issue or ask for support.
Don't forget to star this project!
Check other project you may be interested in:
- BeckhoffS7Client S7 PLC communication library.
- BeckhoffHttpClient HTTP Client for Beckhoff PLC.
- TwinCatAdsTool Management tool for every TwinCat PLC
Special thanks to JetBrains for supporting this open source project.