system.util.jsonEncode encodes floating point numbers to string

I'm trying to set the value of an item in a document tag read from a Siemens PLC OPC server:

I find that when I read the document tag into a python dict and then re-encode it back to a JSON string ignitions jsonEncode function turns any floating point numbers into strings which then throws an error when writing it back to the tag.

Any reason why it would do this:

I'm finding it very troublesome to write data back to document tags that are read/written from Siemens OPC servers. Has anyone had similar issues?

I was going to assume that this was an issue with the jsonEncode function, because I have had issues working with document tag types before using the built in jsonEncode/Decode functions where they did not like dictionaries that contained any other "complex" data types (arrays or other objects), but when I mocked up a test that mimicked your exact code above (different tag path, for my own sake) it ran perfectly. What version of Ignition are you using? I did my testing on a gateway running 8.1.22.

I'm using version 8.1.20. Did you use a document tag whose source is a siemens PLC OPC server? The above script also works fine for me when reading/writing to a memory document tag. Its specifically when the document tags source is from a siemens PLC OPC server.

Ah, I was testing with memory tags, as I don't have any Siemens devices on hand. I know this shouldn't be necessary, but have you tried writing your dictionary value to the tag directly using system.opc.writeValue()?

Yes tried this and it doesn't work.

The work arounds I came up with where to either:

  1. Store the Siemens PLC tag structure as a string instead of a document and use the native json.loads/dumps function for making modifications to the string.

  2. Read the document tag and convert to a string before using json.loads/dumps.

I'd very much like to see a new perspective component for reading and writing to json tags. Something that can accept any arbitrary nested json data structure and display it in a nice way. I came up with this but I expect that my scripting is not too efficient.


Sorry you keep running into issues with this. You seem to be walking a path different than everyone else dealing with structured tags and finding some new bugs.

This one is an interop issue between the JSON representation used by the Document type and the very old JSON representation that pre-dates it, used by the jsonEncode and jsonDecode functions. I opened an issue for this and it looks like a pretty trivial fix.

1 Like

I'm new to SCADA development so probably not following any typical path. Just trying to find an easy way to get tags into ignition from Siemens without having to do too much. Its handy during commissioning to be able to modify controls PLC side in response to testing and have any user inputs automatically appear on the SCADA.