LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

table based CAN message decoder (generally: string parser)

Hi all,

I'm building a CAN message decoder.  Using the example CAN Receive.vi, I get 2-d array of the messages/strings.   For each message, based on its ID, I'd decode the message accordingly, i.e. extract the variables contained in the data part of message.  The layout of the data part of the message is stored in an excel file with 3 fields: start bit, stop bit and signal_name.
For example: the excel file would contain something like:
3, 0, v1
4, 4, v2
6, 5, v3
...

The for each CAN message, after matching the ID, I'd open the corresponding excel file and get the layout of the data part of the message.  Based on the start and stop bits, I'd assign the corresponding bit(s) to the corresponding variable name, e.g. 4 bits from bit 3 to 0 will be assigned to variable v1.

Can anyone suggest a simple way to do it?  I'm able to get the CAN message and the contents of the excel table.  Now I need help in using the info to decode the data part of the message (parse the string) and assigned them to the corresponding variables.

Thanks,
-Ep
0 Kudos
Message 1 of 4
(3,606 Views)
Hi Ep,

From what I understand the CAN portion of your code is working you are just trying to parse the string file for the data. There are alot of functions in the string pallete that can be used to do this, such as String Subset, scan from String, or Search/Split String. The best thing to do is use the context Help by pressing Ctrl H and reading the information about each VI to see which one will help you. I hope this helps. If this did not answer your question or you have another question please let me know.

Regards
Krista S.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 4
(3,579 Views)
Thanks, Krista.
Yes, you're right, I got the CAN portion working.  I just need to decode the data portion according to a table that specifies the layout of the data.  I'm able to get the bit fields that I want by using AND to mask out the unwanted bits, and then use the logical shift to get the actual numbers, because the smallest number in LV is 8-bit wide and the data could only be 1-bit wide. For the example that I wrote in my previous post: to get bit 4, I used AND on the lowest byte with hex 10 and shift the result left 4 times.  Hence, I got bit 4 in an 8-bit number, which I assigned to variable v2.

Right now, I hard-coded the bit numbers and the variable names.  I wanted to do that dynamically, i.e. get the start & stop bits and the variable names from a file.   So in case the table changes, I don't need to edit my vi.  The problem I'm having with that is the width of the variables are not the same.  Well, I can do the masking on the 64-bit data, but it would be overkill if most of the variables are only 1 bit wide.
Any inputs/comments?

Thanks,
-Ep

0 Kudos
Message 3 of 4
(3,575 Views)
Ep,

Can you have an entry in your file which defines the variable width? Then you could select a mask size and data representation which was efficient for that particular situation. If the number of possible widths is small and known ahead of time, this approach might be a reasonable compromise.

Lynn
0 Kudos
Message 4 of 4
(3,569 Views)