07-09-2025 02:21 PM
Hello,
I have a file with an array of clusters and would like to add an element to that array. Unfortunately, this time, the binary write function does not work but, doesn't give an error. An error appears only after I try to read the file and get the EOF error.
My biggest problem is that the write binary block is not working and I do not know why. The task I want to do is save the array of cluster in a file which can than be accessed later in the same VI or another VI.
Please be patient with me as I am new to LabVIEW, Thank you.
Solved! Go to Solution.
07-09-2025 02:27 PM - edited 07-09-2025 02:28 PM
You should probably know by now that nobody here can diagnose pictures. Once you attach your VI, I will have look.
Most likely you need to set the file position before reading. The current file positions where you are reading is at the end of the last write, i.e. at the end of the file.
(Also, the correct way to append an element to an array is "built array", not insert into array")
07-09-2025 02:27 PM - edited 07-09-2025 02:30 PM
The write is working. But after the write, the file pointer is at the end of the file. When you try to do a read starting at the end of the file, you will get an End Of File error. After the write, you need so set the file pointer back to 0 using Set File Position (I think it is in the File I/O->Advanced palette). Then the read will read the entire file including what you just wrote.
Additionally, instead of doing a read, append, and write, you can use the Set File Position to set the pointer to the end of the file and then just write the new value. This will be a lot more efficient.
07-09-2025 02:58 PM
Hello,
Thank you for the feedback, I tried doing it your way as it makes sense that the pointer would be at the end of the file but, when I put the pointer back at the start and read it, I still do not see the new value appended.
Thanks again for the reply.
07-09-2025 03:12 PM - edited 07-09-2025 03:16 PM
The index of your probe display is not at zero, so you cannot see the first element. The probe shows data. You did not wire the count, so you only get one by default. What would happen if you would wire a "-1" to count?
Again, attach your VI instead of endless pictures!!!!
07-09-2025 03:38 PM
In this example, you wrote a scalar cluster to the end of the file and read an array from the start of the file. The array you got is the first array you wrote to the file.
You have to know how LabVIEW flattens data when writing to disk in order to understand what is going on: Flattened Data
When you write an array to a binary file, the array size is written before the actual data. If you then read an array, you get back an array of the originally written size, even if there are more elements that follow (because you wrote another element afterwards).
This behaviour can be overriden by wiring false to the prepend array or string size? terminal on top of write binary file.
As altenbach wrote, you can choose how many elements to read, -1 means to read all.
Note that you cannot use an array for the type input if you wrote scalars or used prepend array or string size? = false.
write/read binary file with array
07-10-2025 09:55 AM
Thank you for the help, it worked in the end. I misunderstood how the file held data and did not understand that you could simply append an element at the end of the file and LabVIEW will read the file as an array.
Here is the final solution I have.
Thank you to everyone that replied and have taught me new things!