I've created a JSON parsing and composing library. I realize Codesys has a paid library for this, but I'm using Schneider SoMachine,and it doesn't support dynamic memory allocation, and it looks like the Codesys library uses the __NEW operator to create an array of variables. Hopefully someone finds this library useful. I've learned quite a bit from posts in this forum, and I guess this is my way of contributing back to the community.
There's an example program in the library, and commenting throughout the various functions.
I've tested this with a number of different JSON strings, but there's no guarantee that it's 100% bug free. My testing environment was Schneider SoMachine 4.3, with M241/M251 PLCs. Comment below to contribute ideas, request changes, or report a bug.
EDIT: version 22.214.171.124, fixes a few bugs
UPDATE: this package has been added to the Codesys Forge https://forge.codesys.com/lib/pro-json/home/Home/
Thanks to Ingo for the assistance with that.
Though this not the right subforum to post this, I would still like to thank you for your contribution!
I have taken a short look and it looks very professional, though I have not tried to run the provided example yet.
Anyway, thanks from a community member.
Originally created by: rickj
Thank you very much. This was something on my bucket list.
thanks for that contribution. A really nice one!
I'd love to see this library in a project on CODESYS Forge https://forge.codesys.com.
You are heartly welcome to our beta program
@Ingo, the Codesys Forge looks like a good concept. I've created an account, but I've never worked with a repository before, so I'll have to spend some time figuring out how that works.
If you like, I can help you.
For the beginning this might be a good read:
step 1 "As a prerequisit, you need to have CODESYS SVN installed."
...available in the Codesys store for 500 euro
First, I don't know if the Codesys SVN would work with Schneider SoMachine, and second, I'm not sure I'm quite that committed to this project that I'm willing to spend 500 euro on it. Sorry.
500eu Ouch! When I signed up for an account, emphasis seemed to be on individuals rather than companies. If 500eu is the required entry fee, many individuals will quickly loose interest. Unfortunate for an otherwise worthy idea.
you do not need a licence for CODESYS Forge!
no, you don't need a license for Codesys Forge, but you appear to need a licence for CODESYS SVN in order to post projects to Codesys Forge. I could be corrected on this, but the first step in the instructions is: "As a prerequisit, you need to have CODESYS SVN installed." Codesys SVN is 500 euro
Codesys SVN is required because codesys source is stored as a binary blob rather than individual files, if I understand correctly.
Sorry that this is not more clearly stated at the CODESYS Forge Website, or on the CODESYS SVN product page.
CODESYS SVN can freely be used with CODESYS Forge
As long as you only connect to repositories on CODESYS Forge you can use CODESYS SVN for free, without a license. We want to support the open source community with that.
Hey Ingo, that's great. I think the Forge is a wonderful idea.
The forge looks like a good idea in concept, but I honestly lost interest by the time I had to install the third software package, and run a .bat file to change the registry. This shouldn't be that complicated--all I'm interested in doing is posting the .library file for people to use. I might get into it again at some point, but right now I don't have time to learn all the ins and outs of SVN packages, as interesting as it might be.
i'm using your library for a Zigbee2mqtt converter.
Is working fine, but sometimes I get a Closing braket to much. I figgured out that a
'EndObject' is set to much.
May we have a look to get this out?
Which version of the library are you using? I had some similar problems, which were fixed in v. 126.96.36.199. You can get the latest version from the codesys forge. If you're still having the issue, can you send me a string that causes the problem? My email is in the library.
Just posted version 188.8.131.52 on the Codesys Forge https://forge.codesys.com/lib/pro-json/home/Home/
Thanks Stefan for the input and testing.
Summary of changes, see comments in the code for more:
-changed how characteristics of JSONVAR variables are determined. FB_Init wasn't picking up everything on the first and last variables of a structure, and some of it is now moved to STRUCT_TO_JSON.
-added a MaxLevels input, basically to define where JSON starts to be created--was necessary especially for JSON in nested function blocks
-I've added a VariableArraySize input, to suppress creation of array positions which are null
-I've added a Format input, which will add white space an indenting to a string (for example, when writing to a file). This is not tested yet.
- a lot of minor code changes, trying to make it easier to read and more efficient
Just a little proposal: to append Codesys version for title of package/library.
Something like: json-pac_v184.108.40.206 (3.5.13 - IDE version (patch usually irrelevant) and 7 - library version).
Also I download .package from forge right now and seems like there is version 220.127.116.11, not 18.104.22.168.
Someone else created the .package file last time, I'm not really sure how to do that. I got into it a bit, according to https://forge.codesys.com/tol/cforge/ho ... ol-handler, it looks like I have to install cforge, but even after I install the package, there's still no C:\Program Files (x86)\3S CODESYS\CODESYS\CFORGE folder with a setup.bat file, and I don't have time to figure it out. I don't actually use Codesys, I'm using Schneider Machine Expert, so I'm already doubling up my time just to post it to the forge.
Here's a link to the .library file if anyone's interested. https://www.dropbox.com/s/2ap9jowqqjzap ... brary?dl=0
I found the Setup.bat file in a different location. Ran it, and I get "Installed URL Handler for cforge tool", so I assume it's installed, but I'm still not getting a "cforge" entry in the context menu of my package folder.
This all seems unnecessarily complicated
Log in to post a comment.