Proper type to write to document tag

Hello! I am attempting to write to a document tag (an array of structs). From reading this forum post, it seems that I cannot write to a part of the document, I must write the whole thing which is okay.

I have tried to write a python list of objects to the document tag and it did not work and resulted in the error: [Error_TypeConversion("Cannot coerce to document from class type 'class org.python.core.PyList'")]

I then tried converting the list of objects to a dataset and then writing that to the document tag which also did not work and resulted in this error: [Error_TypeConversion("Cannot coerce to document from class type 'class com.inductiveautomation.ignition.common.BasicDataset'")]

Looking at the docs for the Document data type, it mentions that a document is essentially JSON and that PyDictionaries can be coerced into a document.

When I convert my list of python objects to JSON using system.util.jsonEncode(str(my_list_of_python_objects)) and then attempt to write that to the document tag, I get this error: [Bad("Bad_EncodingError: Encoding halted because of invalid data in the objects being serialized.")]

I cannot find much information about what a PyDictionary is so I assume it's just a wrapper around python's builtin dictionary. So I attempt to convert my list of python objects into a dict using the builtin function dict(my_list_of_python_objects). When I attempt to write this to the document tag, it results in this error: ValueError: dictionary update sequence element #0 has length 4; 2 is required

What is the correct way data type required to write to a document tag? Please let me know if there is anything else I can provide.

NOTE: All tag writing is done with system.tag.writeBlocking()

What kind of objects are you storing in the dictionary you are trying to encode to JSON?

The Document tag doesn't allow arbitrary classes/objects to be stored.

Pretty simple datatypes. Heres what the array of objects looks like that I am trying to encode into JSON

[
   {
      "name": "systemvar1",
      "value": 100.0,
      "index": 0L,
   },
   {
      "name": "systemvar2",
      "value": 200.0,
      "index": 1L,
   },
]

No problem here... can you post your actual code? What version of Ignition?

1 Like

I replicated your code and got the following error:
[Bad("Bad_EncodingError: Encoding halted because of invalid data in the objects being serialized.")]

tag_path = ["[edge]paramMgr/parameters"]
raw_tag_data = [
	{
		'index': 0, 
		'name': u'systemvar1', 
		'value': 100.0, 
		'desc': u''
	}, 
	{
		'index': 1, 
		'name': u'systemvar2', 
		'value': 200.0, 
		'desc': u''
	}, 
	{
		'index': -1, 
		'name': u'', 
		'value': 0.0,
		'desc': u''
	}
]

v = system.util.jsonEncode(raw_tag_data)

print v

print system.tag.writeBlocking(tag_path, [v])

print v did work though so the issue seems to be in system.tag.writeBlocking()

My version of ignition is 8.1.21 with a perspective version of 2.1.21

I've also made sure that the parameters tag is of type Document

I think you need to upgrade, I remember something about writing document arrays not being supported until maybe something like 8.1.27 but I can't find the exact ticket I'm looking for.

hmm, okay. How do I upgrade my ignition? And do I need a new license when I upgrade?

no license needed within versions (8.1.x to 8.1.y)

Take a gateway backup before upgrading. Consider calling support if this isn't something you are comfortable with.

edit: based on your tag provider name it looks like you're using Edge - if this is an Edge on board device that came with Ignition there could be some complications and you should call support.

1 Like

hmm okay, thank you for the help. I am using ignition edge on a PLC so I will most likely have to call support

I found it here

Version 8.1.27

7165: Cannot write to OPC document tag containing an array of structures
Support for writing struct array values represented as a Document tag.

1 Like

Yeah, that was the best I could find too. It was written in the context of OPC tags but I think it applied to all Document tags.

1 Like