[转]How Do I Append to a Text or Binary File in LabVIEW?

http://digital.ni.com/public.nsf/allkb/F55FD21DFEF0C3C1862571F500023123

 

How Do I Append to a Text or Binary File in LabVIEW?

Primary Software: LabVIEW Development Systems>>LabVIEW Professional Development System
Primary Software Version: 1.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
I am using the Open/Create/Replace File VI to open a file. When I write to the file multiple times in the program the data stored in the file is being overwritten with new data on each write. How do I append data to the end of the file on each file write?
Solution:
LabVIEW 8.0 or later:
Use the Set File Position VI found on the Functions palette under Programming»File I/O»Advanced File Functions. Set the from (0:start) enumerated input of this VI to “end”. Connect the refnum outfrom the Set File Position VI to the file input of the VI that is writing to the file. This will append new data to the end of the file. The image below shows an example of appending a string value to a text file. The End of Line Constant is concatenated to the string input in this case to create a new line for every value written to the file. This constant is not needed if an array type is entered into the Write to File VI because it will automatically append it to the value.

For more information about the Set File Position VI, see LabVIEW 8.6 Help: Set File Position.

LabVIEW 7.1:

The Write File function on the File I/O Palette has an input called pos mode (0:2). Right-click this input and select Create»Constant. This will create an enumerated constant. By selecting End, the new data that you are writing to the file will be appended to the end. Note that it may be necessary to do a line break / carriage return.
Note: For the Binary File VIs ( Write to I16 File VI or Write to SGL File VI), wire a True constant to theAppend to File input.
Related Links:
LabVIEW 8.6 Help: File I/O VIs and Functions
LabVIEW 8.6 Help: Set File Position
Developer Zone Example: Writing a Text File from an Array of Strings

Advertisements
  1. 留下评论

Log in or fill out contact info to leave a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: