05-15-2014 04:49 PM - last edited on 05-16-2014 08:26 AM by Matt_McLaughlin
I need to compare the date of creation of multiple files that are being created throughout the execution of the application, so that if the date and time of the file is equal to the current date and time, a led will light up, and if not, the file will be deleted.
I've made a VI, but I'm getting an error and I don't know how to fix it.
What I need is for the vi to read all the files in the directory and continue reading all the files as they are created in the directory. The weird thing about this error is that it only shows up when I run it without highlight execution.
05-15-2014 05:27 PM
Several things come to mind.
0. What error do you get? The error code or description can be very useful in identifying a problem.
1. When a VI runs OK with execution highlighting and fails without, that usually indicates a timing problem.
2. The inner loop runs as fast as possible because there is nothing in there to slow it down. Put a Wait (ms) in there to slow things down a bit.
3. The loops will never stop. Do not create infinite loops by wiring False constants to the Stop if True terminal. The inner loop should probably be a for loop which will automatically stop after checking all files. The outer loop should have something to stop it - a front panel button, error, something.
4. The timestamp has approximately 19 digits of precision in the fraction of a second portion. The resolution is limited by the clock in the computer. The implication is that you will almost never get exact equality. You need to define "how close" is close enough. Perhaps within 1 second? Then modify the comparison function to determine whether the timestamps are within that limit.
Lynn
05-15-2014 05:52 PM
I need the timesatmp precision to be of 1 second.
The error I get is:
Error 1 ocurred at file/directory info in date & Time comparison.vi
Possible reasons:
Labview: An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @.
<Not a path>
05-15-2014 06:20 PM - edited 05-15-2014 06:44 PM
Your inner loop needs to be an autoindexing FOR loop, so it completes when it runs out of file names. Your inner while loop spins forever and you get enpty strings once there are more iterations than files. That's where you get the error. Your file has now a name with zero characters.
If a file matches, your LED will light up for a nanosecond or less. You won't notice it.
How many files are there? How often do they get created? Who creates them?
Your case structure does nothing. Your outer loop does nothing.
05-15-2014 06:33 PM - edited 05-15-2014 06:36 PM
I need the loop to execute forever, because I don't know the exact number of files that are going to be inside the folder. Is there a way for me to avoid this error, or to treat this error in a way that if there are no more files, it should wait for a file to be created.
The files are created by an IP camera. The configuration is as follows: if the camera detects motion, it is going to store a picture in the folder. I am doing this, because the IP camera is not supported by labview and its the only way for me to analyze the images with the vision assistant.
Thanks in advance!
05-15-2014 06:40 PM
As both altenbach and I have pointed out, the inner loop needs to be a For loop. It will stop as soon as it checked all the files in the folder. If you do not understand how autoindexing works, please loo at the detailed help for Loops and perhaps work through the Getting Started with LabVIEW tutorials.
The outer loop should have some means of stopping. It could stop when the user presses a front panel Stop button, or on errors. No loop should be set to run forever. The Abort button should only be used to stop defective VIs durign development and troubleshooting. It should not be used to routinely stop running VIs.
Lynn
05-15-2014 06:47 PM
Also, if you compose a post, don't paste garbage html code (see lower left of your first post)
05-15-2014 06:57 PM - edited 05-15-2014 07:05 PM
I found a way to keep running the vi, even if the error is encountered. What I need now is a way to go over all the files in the folder again, to see if there are any new files. the only thing is that I should've wired the entire error not just the code to the case.
05-15-2014 07:19 PM
05-15-2014 07:19 PM - edited 05-15-2014 07:24 PM
What's all that code for? Why do you convert the timestamp to strings and then reconvert to a timestamp? Can't you just compare the two directly? I mean, couldn't you just subtract one from the other and use the absolute value of the result for your test?