LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What's the best way to read/write data from a file (preferably a *.txt file)?

Sounds like it's time to upgrade. Smiley Wink Keep in mind that your version of LabVIEW is about 8 years old.

 

Since you are seeing that behavior with the file dialog box (which is bizarre), then you may need to create your own user interface for the file selection. You could have something as simple as having a path control to select the folder. When the folder changes, get the list of files in that directory that have .lds extension, and populate a listbox. Then the user can select one of the files from the listbox. 

 

For the file save you will need to change the way it's done. If the user selects an existing file then you will have to read the LDS file to get all the specs from it, giving you a 1D array of specs in code, and populate a listbox so the user knows what specs are in there. The user can select one of the ones there, or enter a new name in a separate string control. If the user selects an existing spec from the listbox you just need to replace the array element with the new spec and write out the file as if you were creating a new LDS file. If the user entered a new spec name then you just need to append the new spec to the 1D array and again simply write out the file as if you were creating a new LDS file. 

 

I'd write you code, but I don't have LabVIEW 6i, so I don't know what functions did not exist in that version.

0 Kudos
Message 11 of 17
(1,369 Views)

Hmm...  I'm getting a bit bogged down here.  I've only been using LabVIEW for a few months and most of my experience has been with active x controls.  Could anyone throw a few more ideas (or explanations) in my direction as either text or code please.  If you do send any code, please either make it with lv6.1 or take a picture(s).

 

Sorry about this...!  Smiley Indifferent



Never say "Oops." Always say "Ah, interesting!"

0 Kudos
Message 12 of 17
(1,334 Views)

Hi

I have labview 7.0 and I have tested both your read and write demo VI. They are somewhat crude but they do the job. But I think it is something that you have misunderstood regarding Labview datalog files.

1)


James Mamakos wrote:
In the file dialog, you have to already know the exact string to input else you'll just be told the file doesn't exist (applies for both loading and saving). 


Ok first of all in the "Read spec.vi" You have wired the datalog type to the file dialog. This mean that the file dialog only will show files containing data which match the datalog type 100%. You also have specified a pattern (*.LDS). So if the file dialog do not show any files the reason are quite obvious. It can not find any file matching the datalog type AND having file extension LDS. I suggest you drop the pattern specification. You do not need it since only files with the matching datalog type is showed

 

2)


James Mamakos wrote:
When saving a spec, you cannot see any files previously saved, nor even any previous specs saved within the file.  This means that one can unwittingly overwrite specs without realising it.


My first comment will also apply her. But I also think the biggest misapprehension lay here. If you select an existing file the new record will be append to this file. This will happens regardless of any existing datarecords containing the same specs name. So you will never overwrite any specs but you may have duplicates. Since datalog records may have different size i.e. different spec name length. New datarecords are always appended to the file. You are not allowed to overwrite an existing record since this may corrupt the whole file. If you must delete or change a record. You have to write your modifications to a temporary file. If this is succeeded you may delete or rename the old file and rename the temporally file to correct filename. Sad but true. Datalogs files are not a database system.

 

Message Edited by Coq rouge on 04-29-2009 02:16 PM


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Message 13 of 17
(1,321 Views)

smercurio_fc wrote:

For the file save you will need to change the way it's done. If the user selects an existing file then you will have to read the LDS file to get all the specs from it, giving you a 1D array of specs in code, and populate a listbox so the user knows what specs are in there. The user can select one of the ones there, or enter a new name in a separate string control. If the user selects an existing spec from the listbox you just need to replace the array element with the new spec and write out the file as if you were creating a new LDS file. If the user entered a new spec name then you just need to append the new spec to the 1D array and again simply write out the file as if you were creating a new LDS file.


 

I've got the dialog box working for saving a file but  I'm still having problems with the interface for saving specs into the file.  In the attached picture, you can see the code for "Write Spec.vi", which calls up the dialog box shown top left.  You can see a file I created to test its operation.  Once a file has been selected (or a new file name entered), the "Location Prompt.vi" is called up (you can see both the FP and the BD).  I currently have a string constant where the spec name is entered.  How (if at all) could i create a drop-down menu with all the previously saved specs in the file showing, but with the option to type in a new spec name?  The only thingi can think of is to use an enum, and then have a property node referring to its text, but that doesn't seem to work quite the way i want.  Any ideas?



Never say "Oops." Always say "Ah, interesting!"

0 Kudos
Message 14 of 17
(1,281 Views)
You would need to read the file to get all the spec names. You can then feed that list as an array to your "Location Prompt" VI. In that VI use a combobox instead of a string control. You can initialize the items in the combobox with the array of spec names that is fed in (just write to the String[] property). A user can select one of the items there, or enter a new one in the combobox.
0 Kudos
Message 15 of 17
(1,265 Views)

I use LabVIEW 6.1, and I don't believe I have (least I cannot find) these comboboxes you speak of.  Smiley Sad  All I have available are listbox, multicolumn listbox, and table.  Would any of these be suitable?

 

As an aside, is there something similar to the Rotate String function that, instead of moving the first character to the end, moves the last character to the beginning?



Never say "Oops." Always say "Ah, interesting!"

0 Kudos
Message 16 of 17
(1,246 Views)

James Mamakos wrote:

I use LabVIEW 6.1, and I don't believe I have (least I cannot find) these comboboxes you speak of.  Smiley Sad  All I have available are listbox, multicolumn listbox, and table.  Would any of these be suitable?

 

As an aside, is there something similar to the Rotate String function that, instead of moving the first character to the end, moves the last character to the beginning?


Yet another reason to upgrade, huh? Smiley Wink Well, in that case you could use a listbox or a dialog menu ring in conjunction with a string control next to it. If the user entered something in the string control, use that. If not, use what's selected from the listbox/dialog menu ring.

 


As an aside, is there something similar to the Rotate String function that, instead of moving the first character to the end, moves the last character to the beginning?

Just insert a Reverse String function before and after the Rotate String function. Smiley Wink You could also convert the string to a byte array and use the Rotate 1D Array and then convert the byte array back into a string, but I think it's simply easier and more efficient to work with the string functions. 

 

0 Kudos
Message 17 of 17
(1,235 Views)