LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Issue reading a binary file.

Solved!
Go to solution

Hello,

 

I managed to create two routines to write and read a binary file containing a 2D array of doubles. However, when using the reading routine, something is off, and it does not read the binary file sucessfully. I am currently trying to make sense of the error message (see image, file names are provided) which mentions an APPEND instruction.

Could you please comment on why the routine is seemingly not working? I believe it is not a formatting error, as I wrote the array in the same way as I expect to read it, or did I miss something? Also, the binary file is populated and exists.

 

Kind regards,

Fl0

Download All
0 Kudos
Message 1 of 14
(1,426 Views)

Hello,

 

Paths don't match.

 

"background_QCLIR_test.bin" for Write

"background_QCLIR.bin" for Read

 

 

0 Kudos
Message 2 of 14
(1,404 Views)

Hello,

 

Please disregard this, as the pics were taken in different times. The binary file is correct and on the same directory. Take solely into consideration the reading VI. The writing VI is there for reference.

0 Kudos
Message 3 of 14
(1,394 Views)

Write binary default to Prepending the array with size information. Either turn that off and read all or Read 1 Integer first to get the info needed for the binary read. 

Yamaeda_0-1719220547583.png

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 14
(1,382 Views)

How big is the file? What version of LabVIEW are you using?

0 Kudos
Message 5 of 14
(1,382 Views)

Could you please attach the two VIs ?

So that we can reproduce the problem on our side.

 

Save them for previous version (LabVIEW 2020 or prior), as most of us don't have recent versions of LabVIEW.

 

PS: you can wire the refnum at the "file (use dialog)" entry of the Write Binary VI.

PinguX_0-1719221121212.png

 

Message 6 of 14
(1,369 Views)

I have attached both VIs in this post, for LabView 20.0 version

Download All
0 Kudos
Message 7 of 14
(1,351 Views)

@Yamaeda, not sure if I fully understood what you did there. Can you please explain it a bit more in depth?

0 Kudos
Message 8 of 14
(1,340 Views)
Solution
Accepted by topic author Flonares

Good News!  I was able to recreate your error message (the one with the <Append>).

 

I wrote a little program to generate a 5 x 5 array of Dbl (my data), opened a binary data file, wrote the data, closed it, re-opened it, read it, and closed it again.  I then compared the two arrays, and wrote a Boolean "Same?" if they were the same.

 

Ran it.  Got an error message.  Why?  Made a silly mistake (which, sadly, took me several minutes to find).  When I generated the data file, I forgot to wire "create" to the "operation" terminal of Open/Create/Replace file, so it did the (default) Open, which generated an Error 7 (that I wasn't looking at), which was propagated past my next three File I/O commands, resulting in the final Error Message.  Fixing this (stupid) mistake fixed the bug and the program ran fine.

 

See if you have the same bug.  Make sure the Error Line is OK before you start doing the Read.

 

Bob Schor

 

P.S. -- I think @Yamaeda was noting that writing data arrays requires knowledge of the size of the Arrays (so LabVIEW can figure out the size of the dimensions it is reading).  The default (which you do in your code, a Good Thing) is to write the Array Size information as I32s before writing the Array elements.  If I look at my output file with a Hex viewer, I see 5, 5, 0, 0, then a bunch of floats.  The 5, 5 are my Array size, the first pair of zeros are, in fact, my first Dbl (which was 0), followed by 24 other floats.

Message 9 of 14
(1,278 Views)

Just as an "education" extra, here is the test routine I described in my previous post.  It is simple enough that I'm leaving it as a picture.  To reproduce the "failure" (and see the Error Message pop up), just delete the "create" input on the first Open/Create/Replace File function.  Note the use of the "And Array" functions to return a single Boolean if the Arrays are the same.

2D Real Test.png

 

Bob Schor 

Message 10 of 14
(1,275 Views)