LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question about append header to binary

Hey guys,

 

I just had a quick question regarding appending header to a binary file with string data written to it.

As you can see I can read the files correctly if I set  "prepend array or string text size" to TRUE.

 

append header true.png

 

but when I set it to false, an error occurs.

 

append header false.png

 

I thought each string is assumed to be 1byte, so if I pass the file size in bytes to the read function, it would return me the correct number of strings. Which assumption of mine is incorrect?

 

Thanks for your help

0 Kudos
Message 1 of 4
(2,378 Views)

Your problem is you are trying to read the string as a binary.  When you do that, it needs to see the string size at the start.  If you use the Read Text File instead, then you tell it how many characters to read.

 

So the lesson here really is when using text, use the Write/Read Text File.  When using binary data, use the Write/Read 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 2 of 4
(2,362 Views)

 

So the lesson here really is when using text, use the Write/Read Text File.  When using binary data, use the Write/Read Binary File.


 

I totally agree with you. I was only doing this because there was another minute problem I was trying to avoid.

0 Kudos
Message 3 of 4
(2,327 Views)

Hi,

   If you remove the wire going to the data type on the binary read vi in the second example, I think it will work. If you wire a string constant to the data type it reads an array of strings. If you don't wire anything it outputs a flattened string. It's always seemed kind of buggy to me. You can always read flattened string, the default and then un-flatten separately into any data type.

 

Thanks,

-Gabe

0 Kudos
Message 4 of 4
(2,316 Views)