LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert an event structure time data node to a timestamp

Hello,

 

I tried searching for this but I wasn't able to find anything.  Can anyone provide the recipe for calculating a time stamp from the time data node? Is it a relative time stamp or is it based on some other epoch?

 

Thanks,

Bob

0 Kudos
Message 1 of 10
(5,497 Views)

Looks like it's the value of the millisecond timer when the event occurs.

 

 

 

Capture.PNG

0 Kudos
Message 2 of 10
(5,484 Views)

When I tried to use the time conversion functions built into LabVIEW I got a screwy date of 1920s.  When I print the value of the time functions, the numeric data is a much larger number than the one I get from the event structure.  Is there some sort of setting for the time or epoch?

0 Kudos
Message 3 of 10
(5,479 Views)

Here's a thread on the topic:

 

http://forums.ni.com/t5/LabVIEW/millisecond-timer-value/td-p/781796

 

I don't do much with millisecond timing but the gist I get is that the number itself is rather arbitrary and intended to compare to another millisecond timer reading to determine a specific timeframe.

0 Kudos
Message 4 of 10
(5,462 Views)

You can not convert that to a timestamp because the base reference time (millisecond zero) is undefined.

 

If you need a timestamp the put the Get Date Time Now primitive in the event case that needs it.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 10
(5,461 Views)

I don't do much with millisecond timing but the gist I get is that the number itself is rather arbitrary and intended to compare to another millisecond timer reading to determine a specific timeframe.


Be careful when you use this in comparisons because the value of the millisecond timer wraps from (2^32)-1 to 0.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 10
(5,456 Views)

Thanks for the information.  I was beginning to think it might be something like that.  It was obvious that I wasn't getting a consistent time stamp conversion and it was updating in large chunks.  It will be much easier to use the Get Date Time Now function.

0 Kudos
Message 7 of 10
(5,453 Views)

How accurate do you need to be?

 

The timestamp should be generated at the instant the event occurs, but the timestamp is not directly related to the time of day.

 

The event case may not execute for sometime after the event occurs depending on how responsive your code is.  So a Get Time in that case is not going to be the time the event actually occurred.

 

But if you took another millisecond timer value and a Get Time in the event case and set them up so they occure nearly the same time.  You can use the difference between the event's timestamp, and the event case's grab of the time stamp to adjust the Get Time function's returned value.

0 Kudos
Message 8 of 10
(5,432 Views)

I only need to generate a timestamp that is approximate, it does not have to be very precise.  So if it is off even by 1 second, I don't really care, I just need a value to pass to my sub VI.

0 Kudos
Message 9 of 10
(5,421 Views)

RF gave you the answer -

 

  1. Use the Tick Count and Get Date/Time functions inside the event case to get the current time in both formats.
  2. Subtract the event time from the tick count to know how many ms ago the event happened. This works correctly as long as the event happened less than 50 days ago, because integer math handles rollover correctly. If your event happened more than 50 days ago, you have bigger problems in your code.
  3. Divide that by 1000 to convert to s and subtract the result from the current time to get the absolute timestamp of the event.

Note that in many cases, event structures are pretty much always available to respond to events, so the time of the event and the time of handling it will be within the same second. If this isn't the case for you, that means the code taking place inside the event structure takes a long time to execute and that can often mean it shouldn't be there (certainly if the event structure is used for UI handling).

 

If the event structure isn't used for UI interaction and you're using user-defined events, I would suggest encoding the time information as part of the event data and setting it at the source, rather than relying on the event handling mechanism to get the time.


___________________
Try to take over the world!
0 Kudos
Message 10 of 10
(5,400 Views)