03-28-2014 11:03 AM
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?
03-28-2014 11:22 AM
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
03-28-2014 11:24 AM - edited 03-28-2014 11:24 AM
Hello, Attachment added of the screenshot. .vi also attached.
03-28-2014 12:03 PM - edited 03-28-2014 12:03 PM
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
03-28-2014 12:28 PM
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.
03-28-2014 02:16 PM
Hello,
Put in a close file .vi as suggested. Still not working. Any ideas.
.vi attached.
03-28-2014 03:53 PM
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
03-28-2014 05:27 PM
@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.
03-29-2014 05:28 AM - edited 03-29-2014 05:28 AM
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.
03-29-2014 05:42 AM - edited 03-29-2014 05:42 AM
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…