Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Decoding CAN Frame data?

So I have a VI, which was written by a third party and it doesn't work as beleived.  Unfortunately it uses the CAN Frame API to retrieve data and therefore doesn't put the data into channels.  I may be able to do something, where a Frame to Channel conversion is done, but in my larger application framework, Channels are not used, but a 2 array solution is sort of built, where one array holds the variable and the other one holds the data for that variable.
 
So, the problem is when the data is being parsed from the data array being retried from the hardware by ncReadNetMulit.vi  Once the data is retrieved, now it has to be parsed into my data set.  I have attached two vi's which is supposed to do this for me.  The problem is in the "Decode the data -dbc.vi"  and it is decoded based upon a CAN input structure, which defines each variable.  I variable specification is correct as I have tested this and can correlate it.  The message variables are pulled from a .dbc file and that part of the vi's are not attached.  I wrote a short app, which was to parse a CANalyzer .asc data file and use that as the input data to simulate hardware and test the "Decode the data-dbc.vi" file, but it is not complete as of right now.  It does use a .dbc file as well.
 
So, back to the essensence of the problem, which I have narrowed it down to and understand, but I am not sure how to proceed.  I  was hoping someone out there might have already had to tackle this problem and can help me out.
 
A Motorola CAN message is recieved as an 8 byte array (hex values), so it will look something like this...  99 C3 8F 12 7B 0D 66 44
 
in my VI's, I take this hex array (and converts to binary) and creates a string, which will look like this:
 
1001 1001 11000011 1000 1111 0001 0010 0111 1011 0000 1101 0110 0110 0100 0100
 
where
 
AA is the first byte.  For CAN, the following is true, so far as I know:
 
Byte   Bit Order
0         7<=0 
1         15<=8
2         23<=16
3         31<=24
4         39<=32
5         47<=40
6         55<=48
7         63<=56
 
Well, the way I parse out a variable is to start at the xx bit in the string input and go from left to right from there.  This of course doesn't work for the data as shown.  I could possibly flip each byte, but if I have a multi byte variable, then I am going to have a problem.  For example, say one, that starts at Bit 8 and goes 8=>15 and then to bit 0 and then to bit 1 (lsb=>msb) 
 
Perhaps I could use the start bit, subtract the # of bits from the start bit and then parse out the value from that start point.  I tried to implement this and it will show as such in the VI.  It was just parsing from the start bit from left to right.
 
Anyhow, I hope someone has had to tackle this problem before and can help me out as I am about at my end with trying to figure it out.  See attachments.
 
I may just have to use some sort of Frame-Channel conversion vi to make it happen.
 
Thanks,
Rich
 
 
 
 
 
Download All
0 Kudos
Message 1 of 2
(7,997 Views)
I have my application working as expected.  I will post the code on how I did it when I am finished with the Motorola side. 

In essence, the Motorola format is using Big Endian (7<-0) and the vi (String Subset.vi) I am using to parse out sections of the string reads Little Endian (0->7) format.  Anyhow, thanks to those, who emailed me with assitance.  A helpful link is here.
Message 2 of 2
(7,962 Views)