Error Saving/Loading Arrays or Clusters from Configuration Files

Updated Sep 14, 2023

Issue Details

I am seeing incorrect results when unflattening some or all of my complex data types, such as arrays and clusters. The controls aren't updating, or the updated control values are incorrect. How do I use the Configuration File VIs to read and write values for more complex data types like clusters and arrays?

Solution

The Configuration File VIs, located in the File I/O palette, are not designed to work with arrays and clusters. The Read Key.vi and Write Key.vi functions are polymorphic to only work with boolean, double, I32, U32, string and path data types.

You can read and write more complex data types by using the Flatten To XML function located in the Functions Palette by navigating to Programming»String»Flatten/Unflatten String. You can pass any kind of data type into this function to convert it to an XML formatted string. Then, you can write the flattened XML string to the configuration file using the Write Key.vi. Read the data from the configuration file using the Read Key.vi and convert it back to an array or cluster using the Unflatten From XML function.

Additional Information

The Flatten/Unflatten to JSON functions work just as well as the XML Functions. You can also use the Flatten/Unflatten to String functions, but the XML and JSON formats are recommended because they convert data structure information to a human readable format.