From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
10-15-2020 07:31 AM
Hi all,
I tried to flatten a LV object to XML with the idea to unflatten it on the other end of a UDP connection.
The screenshot below shows that it flattens my object to an XML, but it can't unflatten it back to the object.
The faltten to string and unflatten to string work fine by the way. The only reason to go with a structured text string is easier debugging with tools like Wireshark.
Flatten to and from JSON isn't an option, because it doesn't accept my object.
The help file doesn't provide any information (or none that I detected) to any caveats when it comes to flatten and unflatten from XML. It says "anything".
Please advise whether it is supposed to work (aka it's a bug) or that I'm missing/overlooking a crucial piece of information in the help.
10-15-2020 12:32 PM - edited 10-15-2020 12:39 PM
It's hard to tell based on a screenshot, but are those Variants inside your classes' private data structure?
If so, that's what's causing the problem. The class constant you pass in has to have the Variant "pre-set" to match the type in the saved class. Example:
If you run this code:
This is the FP output:
However, with a class, this isn't possible. The "unflatten from XML" node uses the default value of the class, always:
This:
Outputs this:
So the only way to unflatten LabVIEW class XML that has a Variant in it is to not have anything stored inside the Variant...
10-15-2020 01:04 PM
@Kyle97330 wrote:
It's hard to tell based on a screenshot, but are those Variants inside your classes' private data structure?
It is actually a Map (based on the XML). That error is usually a version mismatch in the class data (note the Version element), in this case it is not clear why LV perceives a mismatch. I would try (1) branching the wire you feed to the Flatten function to the Unflatten function to see if the error persists and (2) changing the string indicator with the XML to a control, playing with the Version element value and see if you can get the error to go away. Again, this just localizes the problem, the root cause may still be a bug.
10-16-2020 02:47 AM
You are correct. I'm using a variant as the map's value type. To make matter worse: I'm using the variant attributes to create a "map" inside a map.
The reason why I'm not using a map instead of the variant attribute method is that it crashes cRIO code. See https://forums.ni.com/t5/LabVIEW/LV-Real-time-crash-on-specific-map-use-with-objects/m-p/4015176. (Bug filed)
I will continue to use the regular flatten to and unflatten from string functions to send my object across a network connection.
I was hoping to provide some data insights for the customer in case of problems.
10-16-2020 02:49 AM
I tried it with an intialized (some fields different values) object attached to the data type input of unflatten from XML, to no avail. It's most certainly the variant causing the issue.
10-16-2020 03:06 AM - edited 10-16-2020 03:07 AM
Even if this worked (e.g. not give an error), the variant attributes are not part of the variant's value.
So even if this did work, flattening\unflattening will not preserve the 'map':