LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

24 hour textfile

Solved!
Go to solution

labviewproject wrote:

Hi,

 

Is there a function that can set a specific time such as 00:00:00 and not the date so i can that i could compare it with the current time.


This is unclear to me Smiley Sad

How can "a function" decide to set a specific time if you don't input something to that function???

 

 


labviewproject wrote:

When the specfic time matches the current time, my textfile will be recreated and the name is set as the current date. I have look through the labview examples & the threads but found that most of it is about time elapsed. If anyone have done this before or knows how to set the specific time, please help me by telling me what function i could use. Thanks. 


 

So you need to compare the actual time with that "specific time", right?

Just wire both to a compare function no more no less.

 

SNAG-010.jpg

 

I once had to do something with a user selectable time interval in minutes.

Once the process was started by the user, I add the time interval to the current time and out that in the "Time2NextMeas" control (see code below).

In the Time out state of an event structure I compared that time with the actual time and to what I had to do, among other things: add the time interval to the actual time of course so that the process can go on forever 🙂 (see code above)

 

SNAG-011.jpg

 

Using the full DateTime stamp you also avoid midnight problems!

I think you have all you need to go on 🙂

Message 11 of 31
(1,506 Views)

Hi all,

 

Thanks for the prompt reply.

 

@Gaurav k : I have thought of using the elapsed timer but it will only recreate 1 new textfile after 24hr. the reason for wanting the vi to recreate at 00:00:00 is because it will be the log file for the day. If the textfile is recreated at lets say 2:45:55, it will not be accurate for the day as what happened between 00:00:00 to 2:45:55 would be log in the previous day. This is what i had interpreted from your post. Sorry if i had misinterpreted it.

 

@Nitin: Could you please tell me the name of the function that has %<%y-%M-%d>T> as input? I searched all the functions but still could not find it.

 

@Alain S: What i mean was, is there a function that will allow me to compare 00:00:00 & the current time? If they match, a boolean true could be send to the case structure to recreate a new textfile for the day.  sorry for confusing you. I will start working on the examples that all of you have provided & come back if i have any more questions.

 

Special thanks to all who helped.

Message Edited by labviewproject on 08-26-2009 10:18 AM
0 Kudos
Message 12 of 31
(1,485 Views)

That function is on the string palette.  Format into String.

 

I don't think you want to compare current time to a specific time.  First, time is measured using floating point numbers.  As numerous other threads discuss, comparing floating point numbers for equality is dangerous on a computer has many numbers can't be represented precisely in binary.

 

Even if you could compare floating points precisely, what are your chances that the current time would ever be EXACTLY equal to midnight?  Your current time might wind up being a second after midnight, or even a fraction of a second after midnight.  Chances are your current time will never be exactly midnight.

 

What you should do his store the previous time in a shift register and compare the current time to it.  Strip off the day portion and only look at the time of day portion.  If the current time is less than the previous time than you know you've rolled past midnight.  If you take the time value and use the Quotient/Remainder function to divide by 86400 (seconds in a day), then multiply the Remainder by 86400, you will have a time value based on the time since midnight and the day value of the time stripped away.  Be aware that you might have some complications based on local time zone vs. UTC time.  You may have to factor that into the calculations.

Message 13 of 31
(1,477 Views)
Solution
Accepted by topic author labviewproject
It's really not that big a deal to see if it's a new day. You can use a couple different functions to get the date and you just have to check to see if the date changes. Attached is one method. If you decide to use an actual timestamp instead of a string, all of the comparison functions work with timestamps.
Message 14 of 31
(1,475 Views)

@Nitin: I found the function already. Thanks.

 

@Raven Fans: Thanks for the detailed analysis. i will keep it in mind about it.

 

@Dennis: Thanks for the vi.

0 Kudos
Message 15 of 31
(1,465 Views)

Hi,

 

I implemented the method that dennis have attached as it is similar to comparing the specific time but when i changed the comparison to every minute instead of day, the file will only run for 1 time & not go back to the outer while loop. this would mean that the vi runs for the first time & not run again. How can i make the while loop run again after it has checked that the date has changed?Thanks.

Message Edited by labviewproject on 08-26-2009 05:30 PM
0 Kudos
Message 16 of 31
(1,448 Views)

Ravens Fan wrote:

Even if you could compare floating points precisely, what are your chances that the current time would ever be EXACTLY equal to midnight?  Your current time might wind up being a second after midnight, or even a fraction of a second after midnight.  Chances are your current time will never be exactly midnight.


That's why one should use SNAG-012.jpg instead of SNAG-013.jpg

First time after midnight that this code is executed, a new file will be created but don't forget to add 1 day to the "NextTimeToEvent", call-it-like- you-want, control so that the process will be executed only once in a day and again the next day.

 

 

 

@LabviewProject: If you could post in LV 8.5, or place a screen shot, I can have a look at your vi.

0 Kudos
Message 17 of 31
(1,442 Views)

Hi,

 

I have save my vi in 8.5. I do not know if this is the correct way as i have not save in previous version before.

0 Kudos
Message 18 of 31
(1,419 Views)

Its working for me LabVIEWproject.

 

To make it work for time, I had to change the file names at two places as shown in this diagram. 

midnight.jpg

Did you change it in both the places? Also if you did change it in both the places, time gives a ':' in my time settings to me, and it isn't a valid file name for windows, so it errors out.

0 Kudos
Message 19 of 31
(1,408 Views)

Hi Nitin,

 

I didnt change the name for my textfile as i know using the time as name of textfile will not be allow. so i used the date as the name for the textfile.

 

i used the time as simulation for checking the date as i could not possibly wait for 00:00:00 to see whether the vi will recreate. but when i run the vi, i used the highlight execution to see how the vi will go, & i found that when the time changes, the vi will prompt the user & create a textfile, but after this, the outer while loop will not check whether there was a change in time anymore. this means that when it is checking for change of date instead of time, the vi will not recreate another textfile if the date have changed, as it is only running in the inner while loop. i believe the problem lies with the inner while loop but i cant really pinpoint it as im not really good at debugging.

0 Kudos
Message 20 of 31
(1,396 Views)