04-12-2009 01:03 AM
Hi,
This is probably a fairly easy fix but I've not been able to get my head around it despite trying a number of different loop types and conditions.
I need to save waveform data to a spreadsheet file over many hours, and the plan is to have the file pathname changed automatically every 30mins or so, such that the file size doesn't get to large. On the advice of several members, I've made this in a producer/consumer plan, and the write file is in the consumer loop.
In its current form (attached) the VI successfully changes the file name and saves the file with a header at appropriate time intervals, however, due to the true/false scheme it never actually saves any data to the file.
Thanks in advance for any advice,
Claire.
04-12-2009 02:03 AM
How well have you tested the true/false case? What happens when the boolean is false? What file path does it write to then? You should probably use shift registers to save the path file name from one iteration to the next.
Another architecture suggestion would be to use a state machine architecture instead of using sequence structures. To understand how to write a state machine, refer to File -> New... and navigate to the Design Patterns directory.
04-12-2009 02:11 PM
Hi Adnan,
In the false case the pathname is empty. I don't seem to be able to add shift registers to the case structure - is that possible? Also, I've only ever used shift registers where I'm initialising something outside the loop (like an empty array) - should I have the pathname outside the case structure and be passing it in? Is there a way to pass the pathname from the true case to the false case?
Thanks,
Claire.
04-12-2009 02:26 PM
04-12-2009 03:51 PM
04-12-2009 08:33 PM
Hi, I can't seem to win on this, either I can have it iterate the filenames but not save the data correctly, or I can have it save correctly but never iterate file names. I'm attaching my VI here and would appreciate if you can see where I'm going wrong.
Thanks,
Claire.
04-13-2009 11:48 AM
This modification to your code demonstrates what Adnan explained. Note the use of the shift register in the while loop to store the path.
Eventually, a better solution would be to open the file in the true case and store the file refnum in the shift register, instead of storing the path.
Also, note that I removed the sequence structure that surrounded all of your code since it was a single frame and was unnecessary.
04-13-2009 12:34 PM
Hi Nathand, thank you for modifying my block diagram, much appreciated. I will try to implement your suggestion about the open file being in the true case.
Looking at the timestamps in the output code, the difference between the timestamps varies (without a pattern) between 0.0015 and 0.002s. Would you have an idea why this would happen? I don't think its due to a rounding error as the seconds are recorded to 6 decimal places.
Thanks,
Claire.
04-13-2009 12:50 PM
Hi CFJ,
You were close with your original post. What you were missing were a set of shift register. The problem was that whenever the case was false (ie when you want to add new data to the existing file) you aren't giving a file path to the Export Waveform to Spreadsheet.vi and nothing can be written to the file. You need to continue to pass the filepath from one iteration of the loop to the next. The following screenshots illustrates what you need to change.
04-13-2009 01:13 PM
CFJ wrote:Looking at the timestamps in the output code, the difference between the timestamps varies (without a pattern) between 0.0015 and 0.002s. Would you have an idea why this would happen? I don't think its due to a rounding error as the seconds are recorded to 6 decimal places.
On a Windows system it is normal to see this sort of variation; if you need completely consistent timing then you need to use a real-time (RT) operating system. In general you can't get better than 1ms accuracy on Windows, so if your variation is within 0.5ms you're doing pretty well. Also, while the seconds may appear to be recorded to 6 decimal places, you may find that it's not actually that precise and that the last few digits are not significant digits; that's just my guess.