03-19-2021 02:05 PM
Hi Labview gurus,
I am using a Kvaser USB CanLight to read CAN Frames using their library. It is working well, but the issue I am running into since every update cycle a new message comes in, how do I take each of these messages individually so I can extract the data that I want out of them?
I have attached my project as reference.
03-19-2021
05:42 PM
- last edited on
08-14-2024
08:19 AM
by
Content Cleaner
I would use something like a Producer/Consumer to process the data in a parallel loop.
03-19-2021 11:42 PM - edited 03-20-2021 12:02 AM
Yes a producer/consumer works well with CAN Bus. Here's one I made for monitoring a lithium Ion battery pack
I don't have NI-CAN library installed at home so that is what is missing in the Producer loop
I basically looked at the Arbitration ID and decoded only the packets I was interested in.
03-22-2021 10:18 AM
Ok I am trying to replicate the Producer/Consumer model in my VI.
Full disclosure, this is my first Labview program and so I am going through a learning curve trying to understand everything. Here are my questions:
Ok so here the code that brings in the CAN frame -->
I feed the CAN data to the Obtain Queue and then into the While Loop with the Enqueue Element for the Producer limit -->
and then also send the data to the Consume Loop into the Dequeue Element block -->
but I am confused on what to do next, in the example provided what type of element is the Data Packet?
How can I make my code like this?
Also can you please explain this data structure ? How did you write it like this?
03-22-2021
12:27 PM
- last edited on
08-14-2024
08:20 AM
by
Content Cleaner
Oh my, that's a big project for just starting out... anyway here's a better picture with all the NI-CAN library VI's.
Here's the front Panel
All of the "Blue" Vi's are part of the NI-CAN Library. I don't know if NI-CAN will work with any brand of CAN interface, but I am guessing it only work with NI CAN bus devices.
The "Data Packet" is a "TypeDef Cluster", I believe that also came with NI-CAN.
But making a Cluster then making that into a "Typedef Cluster" is pretty easy.
Whether your CAN device and supplied CAN library can use it is another story...
Along with that the Other thing you asked about is "Unbundle By Name" in the Cluster Platte.
If a Cluster is made "properly" you can use Unbundle By Name as everything is labeled for you.
03-26-2021 12:15 PM
I appreciate the suggestion and yes this was a difficult problem for my first Labview, but what I just ended up doing was just doing a bunch of equal statements to the CAN ID that I wanted and then processed each frame individually. Not the most robust repeatable way to code, but it works for now.
I appreciate the help!
03-26-2021 01:29 PM - edited 03-26-2021 01:36 PM
@st9go wrote:
I appreciate the suggestion and yes this was a difficult problem for my first Labview, but what I just ended up doing was just doing a bunch of equal statements to the CAN ID that I wanted and then processed each frame individually. Not the most robust repeatable way to code, but it works for now.
I appreciate the help!
That will work but I did it this way...
We were only interested in data who's Arbitration ID = 300h AND DF0 (Element 0 of the data array) = 0, so that is my outer case.
DF1 (Element 1 of the data array) has the Command ID of the information we want. So DF1 feeds right into a case structure.
There is a case for every value if DF1 we are interested in and the default case has nothing, so any commands we are not interested in just get ignored.
Case selectors don't have to be a T/F Boolean, they can be anything.