Showing results for 
Search instead for 
Did you mean: 

NXT Flatten to String Not Working with Clusters and Arrays




My name is Joshua and I am from the FIRST Tech Challenge Team 4318, Green Machine. We are trying to write a program that will write to a configuration file and read it back. The idea is that we will be able to write to a config file from our computer that will be read by our autonomous program when it runs. This will define what the autonomous program does.


The easiest way to do this seems to be flattening a data structure to a string, saving it to a file, and then reading back and unflattening it. The issue is that the flatten to string and unflatten from string VIs don't seem to work with arrays and clusters on the NXT. It does work when running on the computer. We've tried arrays, clusters, clusters in arrays and arrays in clusters, none seem to work. Thinking it was something to do with reading the string from a file, we tried bypassing the file functionality, still not working. It does work with basic data types though, such as strings and numbers.


No error is thrown from what we can tell. All you get is a blank data structure out of the unflatten VI.


The program attached is a test program I've been working on to get this functionality to work. It will display the hex content of what is going into the file, coming out of the file, and then the resulting data from the unflatten string, as well as any errors that have been thrown. The data type we are using simulates what we would like to store. There is also a file length in and out counter. The out file is a little larger because the NXT write file VI adds a new line character on to the end (thus the use of the strip white space VI). This character was corrupting even basic data types saved to file.


I would like to know if there is a problem with what we are doing, or if it is simply not possible to flatten arrays on the NXT. Please ask if you have any questions about the code. Thank you in advanced!



0 Kudos
Message 1 of 4

I don't have an NXT brick I can test this on but, looking at the help for the NXT VIs, there does seem to be a problem.  You set the maximum file size to the length of the string but the NXT VI adds a new line character so your actual string will be longer than the maximum file size you set.


Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 2 of 4

Hi jfireball,


This is a very interesting situation. Take a look at what kbbersch said. I also urge you to post in the FTC Forums. You posted your question to the general LabVIEW forums, but by posting to the FTC Forums, you will have access to others that are using the NXT hardware.


David B.
Applications Engineer
National Instruments
0 Kudos
Message 3 of 4

Thank you for your help everyone! Increasing the file size by so that the newline character is accounted for doesn't seem to fix it but it is a good catch. It will probably prevent some strange errors from happening. I'll try the FTC form, thanks for directing me to it.


Joshua Driesman

0 Kudos
Message 4 of 4