06-24-2024 03:30 AM
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
Solved! Go to Solution.
06-24-2024 03:52 AM
Hello,
Paths don't match.
"background_QCLIR_test.bin" for Write
"background_QCLIR.bin" for Read
06-24-2024 04:01 AM - edited 06-24-2024 04:03 AM
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.
06-24-2024 04:15 AM
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.
06-24-2024 04:15 AM - edited 06-24-2024 04:17 AM
How big is the file? What version of LabVIEW are you using?
06-24-2024 04:29 AM
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.
06-24-2024 05:08 AM
I have attached both VIs in this post, for LabView 20.0 version
06-24-2024 05:36 AM - edited 06-24-2024 05:37 AM
@Yamaeda, not sure if I fully understood what you did there. Can you please explain it a bit more in depth?
06-24-2024 09:46 AM
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.
06-24-2024 09:53 AM
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.
Bob Schor