01-22-2018 06:55 PM
Hi.
I am trying to extract the timestamp from a CAN frame. How can I do this? I am able to extract the relevant bits from the raw frame data (http://zone.ni.com/reference/en-XX/help/372841L-01/nixnet/rawframeformat/) but I'm not sure how to convert this into the current time. Any help appreciated. example VI would be a bonus!
Many Thanks
01-22-2018 08:59 PM
Haven't tried it myself but have you tried using the Type Cast function with the type being a timestamp constant? Also are you using the NI-CAN API or the NI-XNET API?
http://zone.ni.com/reference/en-XX/help/371361N-01/glang/type_cast/
01-22-2018 09:53 PM
Hi Matt.
Thanks for the quick reply.
I tried your suggestion to type cast the data using a timestamp constant, but the output doesnt update, even though I can see the relevant bits in the frame change.
I am using the NI-XNET API.
Since the CAN frames gives the nomber of 100ns since 12:00 a.m. January 1 1601, Is there a way to add these together to come up with the current time?
Thanks
01-23-2018 02:37 AM - edited 01-23-2018 02:40 AM
Hi Rookie,
I got this VI from an old CAN example for the NI9853 module:
Did you actually read the help you linked in your own question?
It says this:
NI-XNET includes a pair of VIs to convert between this U64 timestamp format and the LabVIEW timestamp format. The NI-XNET VIs handle all time format and byte order aspects. For more information, refer to the NI-XNET examples for logfile access.
01-23-2018 05:43 AM
Why are you using RAW and not CAN in the frame?
01-23-2018 04:08 PM - edited 01-23-2018 04:09 PM
If you are using the NI-CAN toolkit the CAN Timestamp is part every data packet and extracting it is trivial
01-23-2018 04:09 PM
The ordering of the bytes in the payload are all mixed up, so its easier to work with raw to reorder the bytes into the correct order. The suppliers of the equipment generating the CAN signals may have done this to make it more difficult to 'hack' into. They haven't provided me with the database file either, so working with raw seemed like an easier option.
It is actually quite easy to do using case structure, with the different cases determined using the CAN Arbitration ID.
01-23-2018 04:10 PM
Unfortunately, I dont have the NI-CAN toolkit 😞
01-23-2018 04:17 PM
Thanks GerdW.
I'll have a look at this when I'm in the lab next.
01-23-2018 04:24 PM
@rookie2017 wrote:
It is actually quite easy to do using case structure, with the different cases determined using the CAN Arbitration ID.
I think a for loop (for all frames) and an unbundle by name (unbundle the ID) is easier. I've honestly never used the raw format except for logging. There are a few shipped examples on how to flatten and unflatten a frame to an array of bytes. Look for Replay CAN Frames from TDMS in the example finder to see a (somewhat inefficent) way of converting a U64 time to LabVIEW timestamp. The main VI that does this is found here: \vi.lib\xnet\xnet.llb\_XNET Convert Time U64 to LV.vi
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord