LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Not Writing to Text File Multiple Times

Hello,

 

I have developed the following .vi. 

There is a write to text file command within the For loop but what I don't understand is why it only saves once. Because the wroite to text file is within the For loop I would expect it to save multiple times. What am I doing wrong?

 

Capture.JPG

 

 

0 Kudos
Message 1 of 10
(2,841 Views)

Your image is too small for my old eyes. Also, some of the labels overlap, making it even more difficult.

 

Please post your actual VI. If you have a small data file, it might be helpful to post that also.

 

Lynn

0 Kudos
Message 2 of 10
(2,835 Views)

Hello, Attachment added of the screenshot. .vi also attached.

0 Kudos
Message 3 of 10
(2,831 Views)

The problem may be that the file is closed after the first write. The Detailed Help file for the Write to Text File function suggests that not wiring the refnum out tells the fucntion that you are done with the file and it closes it. Since you open the file outside the loop (as you should), on the second iteration the file is closed and no write occurs. Do you get any kind of file closed error?

 

Possible fix? Wire the refnum out through the while loop and place a File Close function outside the loop.

 

Lynn

0 Kudos
Message 4 of 10
(2,815 Views)

johnsold wrote:

Possible fix? Wire the refnum out through the while loop and place a File Close function outside the loop.


Just to clarify this some.  Read the Help file on the Write To Text File.  It states the it will close the file if the reference out is not used.  So you are actually closing your file on the first iteration.  The fix is to pass the reference out of the Write To Text File to a Close File that is outside of the FOR loop.

 

I would also highly recommend using a shift register for the reference to avoid the evil bug of a 0 iteration FOR loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 10
(2,802 Views)

Hello,

 

Put in a close file .vi as suggested. Still not working. Any ideas.

 

.vi attached.

0 Kudos
Message 6 of 10
(2,785 Views)

I do not have the spectrometer VIs, so I cannot see what is in there.

 

1. Are you sure the loop is iterating? How do you know?

2. Is new data being received from the instrument? The spectrometer VIs apparently do not have error wiring, so are you sure that no errors are occurring in those VIs? Try putting a temporary string indicator on the text input to the Write to Text File function.

3. How fast does the loop iterate?

 

Lynn

0 Kudos
Message 7 of 10
(2,773 Views)

@johnsold wrote:

Your image is too small for my old eyes. Also, some of the labels overlap, making it even more difficult.


As an aside, you can get the full-size image by right-clicking, then choosing View Image (at least in Firefox) and clicking to zoom to full size. The image itself is fine, it's the forum that's scaling it small for display in the thread.


nevica wrote:

Put in a close file .vi as suggested. Still not working. Any ideas.


I can't open your VI as I don't have 2013 available at the moment, but you don't need Set File Position. If you don't close the file, then the next write happens just after the previous write. The file position is already correct.

 

You should put the file refnum in a shift register around the while loop. Wire the refnum out of Write to Text File, to the shift register from the inside of the loop, and then put Close File outside the loop.

0 Kudos
Message 8 of 10
(2,762 Views)

Thanks for all your replies and suggestions. I re-wrote the .vi in order to save to a spreadsheet. I can't see any need to include a shift register as the .vi works. What benefit will a shift register give me?

 

The new .vi is attached.

0 Kudos
Message 9 of 10
(2,749 Views)

Hi nevica,

 

as you rewrote your VI by using a wrapper function for file access you don't need the shift register anymore. You should have used that in your old approach…

 

Btw. you don't need to wire default values like the FALSE constant at the "transpose?" input of WriteSpreadsheetFile…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 10
(2,744 Views)