05-03-2015 05:06 AM
I am dynamically creating a file name using current date .
Once created, I open a file with the name. Since the code is in a timed loop, I open the file inside a case structure which fires only once.
I pass on the File Refnum to a Write-To-Spreadsheet function to write data once every minute.
All the above works well on my Laptop.
But when the code is loaded on the client machine( which has a LV12 Run Time Engine) , for every Spread Sheet Write, it pops up the File Dialog box asking for a file name. Obviously the ByteStream Refnum property node does not seem to work ?
I dont know what is different on the client machine. My Laptop is a WIN7/ 64 Bit system. Client machine is a WIN 7 / 32 Bit system.
The relevant code is below :
05-03-2015 07:32 AM
05-03-2015 08:04 AM
05-03-2015 08:18 AM
05-03-2015 08:33 AM
Somewhere, you have a loop that fires once a minute and includes the Write to Spreadsheet function. Put the File Open/Create code outside (in front of) this loop so you demonstrably only do it once, you never do it inside the loop, and you use the File Refnum created outside the loop to save the data generated inside the loop. When you exit the loop (having written all of the data), you can safely close the file.
Much simpler, logic is intuitive, no need for Case Statements, for (mis-used) Local Variables to guarantee opening the file once, etc.
Bob Schor
05-03-2015 09:11 AM
05-03-2015 10:05 AM
@Bob_Schor wrote:
..... Put the File Open/Create code outside (in front of) this loop so you demonstrably only do it once, you never do it inside the loop, and you use the File Refnum created outside the loop to save the data generated inside the loop. When you exit the loop (having written all of the data), you can safely close the file.
Much simpler, logic is intuitive, no need for Case Statements, for (mis-used) Local Variables to guarantee opening the file once, etc.
Bob Schor
What you wrote is generally what is done. But then exceptions exist - in my case there is no way I can generate the file name outside the 0.5 Sec Timed Loop. OK this was not obvious in my original post - but then my problem was different - the same EXE works fine on a laprtop on which it was built. But on the client desktop, keeps asking for File Name for every write to the Spread Sheet. That I guess is still not answered..
( The image shows 5 instead 120 of logging. This is only for checking the logic )
05-03-2015 10:31 AM
05-04-2015 07:03 AM
1. What is in that black subVI? You are obviously generating a path in there. What is that path? Is it based on the VI location?
2. File I/O inside of a timed loop? That is just asking for trouble (missed cycles, late cycles, etc.). Wait...Windows code? Do not even bother with the timed loop. It does nothing but add overhead and you gain little to nothing from it. Just use a normal While loop with a Wait ms fuction.
3. Since you appear to care about your timing (why else would you use a timed loop), then you really should use a Producer/Consumer to move your file I/O to another loop. Further, you should not use the Write Spreadsheet File since it opens and closes the file each time it is called. Instead, open and close the file only when you are changing files. Write to the file with Write Text File. If you dig into the Write To Spreadsheet File VI, you will see this being done. Store your file reference in a shift register.
05-04-2015 11:51 AM
@crossrulz wrote:
1. What is in that black subVI? You are obviously generating a path in there. What is that path? Is it based on the VI location?
2. File I/O inside of a timed loop? That is just asking for trouble (missed cycles, late cycles, etc.). Wait...Windows code? Do not even bother with the timed loop. It does nothing but add overhead and you gain little to nothing from it. Just use a normal While loop with a Wait ms fuction.
3. Since you appear to care about your timing (why else would you use a timed loop), then you really should use a Producer/Consumer to move your file I/O to another loop. Further, you should not use the Write Spreadsheet File since it opens and closes the file each time it is called. Instead, open and close the file only when you are changing files. Write to the file with Write Text File. If you dig into the Write To Spreadsheet File VI, you will see this being done. Store your file reference in a shift register.
1. The Black Sub Vi just returns the current path based on the situation - whether in Design mode or Run time system.
2. File I/O inside a Timed is a true concern. But then my acquistion rate is rather slow at once per minute. And the user needs the plot to reflect only once per hour intervals. So I thought its simpler to do what I did even if it means opening and closing the Spread Sheet file 1440 times a day. Not much ?? Anyway I do agree the overhead of the Timed Loop and have since changed to a simple while loop.
3. The producer / consumer with Queues is something that I normally use for relatively fast data grabbing say at about 50ms rate. But here again i wanted to keep it simple since its a slow process. The following one is what i have got working and it seems to hold reasonably well for the intended purpose.
Thanks for your time.