LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unflatten From String from cluster that contain string problem / bug

The following behavior is quite strange.

I hope some one has an explanation...

The following sequence leads to a strange error (116 - Unflatten From String)

 

1. I create a cluster that contains a string and an array of numbers

2. The string length is EXACTLY 13 characters. (no more no less)

3. I flatten the cluster to a string

4. I save the string to a file

5. I read the file

6. When I try to convert the string back to the cluster  - I get an Error.

 

I have investigated a bit - and I get the same error with string length of 269, 525 and 781.

 

 

What is going on???

No Error.PNG

 

Error.PNG

 

0 Kudos
Message 1 of 6
(3,802 Views)

I didn't run the code, but I can see that your string lengths are all multiples of 256+13. When you flatten a string, its length is encoded as part of the flattened data, so that whatever unflattens it knows how many bytes to look at. Most likely, the issue is that the byte equal to 13 is interpeted as a carriage return character somewhere (since that's the ASCII value). My bet would be the file functions (which you can see from their icons are configured to look at line breaks). I woudn't be surprised if the same thing happens with strings of length 10 (which is the line feed character), although I'm guessing your test would have found that, so it probably doesn't happen.

 

You will probably see the difference clearly if you compare the string saved to file with the string read from the file and presumably the easiest solution is to configure the write and read to ignore line breaks.


___________________
Try to take over the world!
Message 2 of 6
(3,783 Views)

Thanks!

 

I have replaced the "Read from text file" to "read from binary file" and set the data type string and it works flawlessly.

 

After finding out the reason it looks so trivial...

Message 3 of 6
(3,762 Views)

Hi Hazkel,

 

finding out the reason it looks so trivial...

Well, reading the help is also trivial!

If you would have done you would have switched off the "end of line" conversion in the TextWrite/Read functions…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 6
(3,754 Views)
0 Kudos
Message 5 of 6
(3,753 Views)

@Hazkel wrote:

solution.PNG


You can actually make this even simpler by not using the Flatten To String and the Unflatten From String.  Just use the cluster for a direct write/read with the Write To Binary File and Read From Binary File.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 6
(3,702 Views)