LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

append binary file

Solved!
Go to solution
I would like to append new binary values to the existing binary file. Write File.vi looks like a good candidate for this, and it has two inputs, pos. mode and pos. offset which looks like something useful for my task. Unfortunately whatever I put into pos offset input I got Error 4 �end of file� and whatever I put into pos. mode nothing changes in binary file. There is also no example on the web which makes any use of them.

Please can you tell how I can simply append new binary values to existing binary file. I put vi. In attachment which will write binary file, but only once.

Thanks,

Zoran
0 Kudos
Message 1 of 11
(5,752 Views)
When you open the file you get the file size out from the open function. Wire that number to the pos.offset input of the write function.

The write function has an output that will return the offset after the write so if you need to do more than one write you can use that output as input to the next write (the write will by default start at the current position though so in many cases that's not necessary).

An alternative is to just set the pos.mode to "End".
0 Kudos
Message 2 of 11
(5,753 Views)
This is what I tried before and either idea is not working. Write function output always returns zero and pos. mode doesn�t seams to do anything different with �End� or �Start� mode. I put simple vi in attachment where you can see this.

Thanks,

Zoran
0 Kudos
Message 3 of 11
(5,752 Views)
It's because you have wired the constant 2 to the file open function, which is create or replace, not open or create (missed that one when I looked at it the first time). Just delete that and right-click on the terminal and select create constant, you then get an enumerated cosnatnt that shows the name of the selected value as well, option 1 is what you want; open or create. Remember also to wire the file size of the open to the pos.offset (skip the control), and you can remove the pos.mode control.
0 Kudos
Message 4 of 11
(5,752 Views)
The problem is not with the "write", but with the "open". You open the file with code 2, which Creates/replaces the existing file. (Only you know why this constant is named "open or create" ;-), quite confusing at first. )

You need to open with code 1. Please delete the constant, the right click on the function(open:0) terminal and select "create constant". Now you'll have a nice ring control to select the right mode.
0 Kudos
Message 5 of 11
(5,752 Views)
Solution
Accepted by topic author zoran
This works! Thanks.

Zoran
0 Kudos
Message 6 of 11
(5,752 Views)
Will this work if I have a situation like this ?
 
I have a DAQ VI which gives me about 32667 events in about 10 loops. I want to append these events onto a binary file after every iteration. I followed the message conversations regarding the append binary file but for some reason only the latest set of events are recorded. Will this work in a loop ?

Kudos are the best way to say thanks 🙂
0 Kudos
Message 7 of 11
(5,507 Views)

There is actually an example VI that installs with the DAQ driver that illustrates how to append data betwee iterations of a loop during an acquisition. The name of this example is "Cont Acq&Graph Voltage-To File(Binary).vi". The part about fooling with header information can be a bit confusing, so you can cut that part out if it's too complicated.

Kind Regards,

E. Sulzer
Applications Engineer
National Instruments
0 Kudos
Message 8 of 11
(5,493 Views)
I exactly did the same thing with Labview 8.0. For some reason it just stores the data from the latest acquisition. Here is how I am doing mine:

Open File -->For loop --> Data acquire --> Get file size --> Set File position --> Write to binary file---> end loop --> close file

Kudos are the best way to say thanks 🙂
0 Kudos
Message 9 of 11
(5,485 Views)
Sulzer

I got mine to work. When I get the data from my DAQ I write them to a binary file inside the loop. I keep appending data for as long as I acquire data (using get file size, and set file position).

This seems to work reasonably well.

Thanks

Kudos are the best way to say thanks 🙂
0 Kudos
Message 10 of 11
(5,464 Views)