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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving string array to binary file

Solved!
Go to solution

Hi!

My data is mainly in string format.

Whenever I save DBL array in binary files  – everything is ok (see file ‘UN Test Read write - DBL.vi’). This Labview 9 file writes binary file to root C:\ and then reads it.

When I try to load file with string array in it (file ’ UN Test Read write - STRING.vi’) – I get an error.

Is it possible to save sting arrays in binary files?

Download All
0 Kudos
Message 1 of 7
(3,639 Views)

@Gurator wrote:

Hi!

My data is mainly in string format.

Whenever I save DBL array in binary files  – everything is ok (see file ‘UN Test Read write - DBL.vi’). This Labview 9 file writes binary file to root C:\ and then reads it.

When I try to load file with string array in it (file ’ UN Test Read write - STRING.vi’) – I get an error.

Is it possible to save sting arrays in binary files?


You might be better served using the generic read file and write file VIs.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 7
(3,636 Views)

When you say you get an error, it helps if you tell what the error was.  Number?  Description?

 

I ran your VI and it worked okay for me.

0 Kudos
Message 3 of 7
(3,630 Views)

Instead of finding the file size and what not, just wire a -1 to the count on the read and all of the strings will be read.

There is also no need to set the file position to the start right after creating the 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
0 Kudos
Message 4 of 7
(3,624 Views)
Solution
Accepted by topic author Gurator

The problem is the fact that you do some fancy math, assuming that the elements are 8 bytes long. THis assumption cannot be made for arrays of strings.

 

If you write an array of string to a binary file, you simply need to read it again as array of strings. Here's a quick example. Your sequence structure is not needed, because execution order is fully determined by dataflow.

Message 5 of 7
(3,623 Views)

Hello!

Thank you for your quick solution. I considered casting all strings as ASCII arrays before you came and saved the day.

Strange thing though: feeding ]Read From Binary File' module with -1 works under Labview 9.0.1 on Windows XP Version 2002 SP3 but same file on same Labview version on Windows 7 SP1 generates Error 116 : Unflatten or byte stream read operation failed due to corrupt, unexpected or truncated data.

Hope nothing like this will happen during running compiled (on XP) executable.

 

0 Kudos
Message 6 of 7
(3,588 Views)

Gurator wrote:

I considered casting all strings as ASCII arrays before you came and saved the day.


I have no idea what you mean by that. ASCII is not a datatype.

 


Gurator wrote:

Strange thing though: feeding ]Read From Binary File' module with -1 works under Labview 9.0.1 on Windows XP Version 2002 SP3 but same file on same Labview version on Windows 7 SP1 generates Error 116 : Unflatten or byte stream read operation failed due to corrupt, unexpected or truncated data.

Hope nothing like this will happen during running compiled (on XP) executable.


Are you absolutely sure the code is identical? If the file has been written using the litte endian option, you need to read it again using little endian, else the file will most likely be considered corrupt.

Also, under windows 7 you should not try to write to the root of the C: drive. There are better places.

 

0 Kudos
Message 7 of 7
(3,578 Views)