LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

loop to automatically change file path for writing continuously acquired data

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.

0 Kudos
Message 1 of 18
(5,390 Views)

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.

Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies
Message 2 of 18
(5,383 Views)

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.

0 Kudos
Message 3 of 18
(5,363 Views)
You cannot add shift registers to a case structure but can to the loop. Well, you should be having some sort of file name for a false case through each iteration of the loop. So, I would recommend you have a path name initialized outside the loop and use the value from the shift register to pass file name constants during a false case.
Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies
0 Kudos
Message 4 of 18
(5,361 Views)
I'm sorry Adnan, I am not understanding what to do. I've been on this for many hours. Perhaps I haven't explained well enough what I want to occur. The file should be written continuously for 30 mins, then the pathname updated to the current time and a new file begun, which then saves for the next 30 minutes. Do you have time to do a quick sketch of the outline. I don't see how to make the filename stay constant and feed to the false case when the condition for changing the filename is in the true case? Can you feed from the true case to the false case?
0 Kudos
Message 5 of 18
(5,351 Views)

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.

0 Kudos
Message 6 of 18
(5,346 Views)

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.

Message 7 of 18
(5,302 Views)

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.

Message 8 of 18
(5,295 Views)

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.

 

 






 

 

 

0 Kudos
Message 9 of 18
(5,292 Views)

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.

0 Kudos
Message 10 of 18
(5,285 Views)