LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to move messages that cyclically update

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.

0 Kudos
Message 1 of 7
(2,026 Views)

I would use something like a Producer/Consumer to process the data in a parallel loop.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 7
(1,992 Views)

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

CantCapture.PNG

I basically looked at the Arbitration ID and decoded only the packets I was interested in.

 

 

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 7
(1,973 Views)

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 -->

st9go_0-1616425774594.png

I feed the CAN data to the Obtain Queue and then into the While Loop with the Enqueue Element for the Producer limit -->

st9go_1-1616425877422.png

 

and then also send the data to the Consume Loop into the Dequeue Element block -->

st9go_2-1616426130705.png

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?

st9go_3-1616426223380.png

 

Also can you please explain this data structure ? How did you write it like this?

st9go_4-1616426282429.png

 

 

0 Kudos
Message 4 of 7
(1,937 Views)

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.

 

CAnCapture.PNG

Here's the front Panel 

cannCapture.PNG

 

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.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 7
(1,915 Views)

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!

0 Kudos
Message 6 of 7
(1,884 Views)

@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.

Cant2Capture.PNG

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 7
(1,877 Views)