Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use relative timestamps in Frame API

The NI-CAN doc talks about the NC_ATTR_TIMESTAMP_FORMAT attribute being available in the frame API. I set this to relative using my USB 8473 w/sync. I'm not sure how to process the received timestamp field though. The doc only talks about timestamp format being NCTYPE_ABS_TIME and make no reference to the format of the parameter when using relative timestamps.

So, how do I make use of relative timestamps? What is the actual bit/type format of the timestamp field when the device is set to relative time?

0 Kudos
Message 1 of 8
(10,261 Views)

Hi Jeremy,

 

The relative format provides a double value representing the number of seconds since the beginning of your task. For more information, see page 11-103 of the CAN hardware & software manual, linked here:

 

CAN Hardware & Software Manual: http://www.ni.com/pdf/manuals/370289k.pdf

 

Let me know if theres anything I can clarify!

Al B.
Staff Software Engineer - TestStand
CTA/CLD
0 Kudos
Message 2 of 8
(10,247 Views)

Thanks for the reply. There's still an aspect of this that I'm not understanding though. When I receive frames using ncRead, I'm going to get NCTYPE_CAN_STRUCT. That has a Timestamp field which is NCTYPE_ABS_TIME. That itself is structure of 2 32-bit values, not an individual double value.

So, is there some special way I need to typecast or handle the Timestamp field in order to really get a final decimal value since start time in seconds?

0 Kudos
Message 3 of 8
(10,245 Views)

Hi JaremyP,

 

The relative and absolute timestamp data will be formatted in the same manner, so you will be able to treat the relative time data exactly like you would treat absolute data, the only difference being in the conversion from the seconds value to the date/time format if this is something you are doing in your code.  If you are not sure how to get from the NCTYPE_ABS_TIME struct of 2 32 bit values to the double value for either time format, let me know and I can look into more details on that process

Al B.
Staff Software Engineer - TestStand
CTA/CLD
0 Kudos
Message 4 of 8
(10,222 Views)

That number conversion is where I'm stumped. If you could get more details and perhaps supply a C code sample converting the NCTYPE_ABS_TIME struct to a final double value in relative seconds, I would very much appreciate it. Thanks!

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

Hi JeramyP,

 

The absolute time data contains the upper and lower portions of a 64 bit integer representing nanoseconds since the time start.  combining the two components, then converting to seconds through division will allow you to get a double representation of the seconds.  For more information, check out this article on datetime manipulation (the absolute time struct is a FILETIME struct):

 

http://www.codeproject.com/KB/datetime/winapi_datetime_ops.aspx?display=Print

 

Let me know if I can do anything else to help!

 

Al B.
Staff Software Engineer - TestStand
CTA/CLD
0 Kudos
Message 6 of 8
(10,191 Views)

I believe it actually represents 100ns, not 1ns,  ticks since start...

0 Kudos
Message 7 of 8
(10,173 Views)

GPIB Guru,

 

You are correct - each tick is 100ns.  Sorry for the confusion!

Al B.
Staff Software Engineer - TestStand
CTA/CLD
0 Kudos
Message 8 of 8
(10,155 Views)