LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

data acquisition CAN bus

Hello,

 

I am trying to acquire CAN frame data coming from a CAN bus by executing a "CAN Read" function in a while boucle and storing the frame in an array using shift register. I then write the whole array into a text file. But I got a problem is that when I open the text file, I saw that the acquisition rate decrease as the number of frame increase. At the start, I can acquire a lot of frame in 1 ms second but when nearing the end each frame is acquired every 1ms. Does anyone has any idea what causes this ? Is there a better way to store the frame in a regular rate?

 

 Capture.PNG

0 Kudos
Message 1 of 15
(4,419 Views)

Hallo trainee,

 

that problem occures very often in loops, where an array is increasing in size due to constantly adding new elements!

 

Limit your array to a reasonable size - and svae your data more often (not just once after the loop is finished)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 15
(4,406 Views)

Thank you GerdW. How can I save the data while the while loop is running? I am trying to save all the frame data into one array.

0 Kudos
Message 3 of 15
(4,394 Views)

Hi trainee,

 

put the file function inside the loop…

 

For a more performant approach you should use the consumer-producer-scheme with a queue between your producer (CAN reading loop) and your consumer (file saving loop). That way the producer can run as fast as it needs to, while the queue is used as buffer for the consumer…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 15
(4,391 Views)

Thank you GerdW. Can the queue function works with array? I can't seem to wire in the data in array form. It says the data is a double precision element. Is there a way to solve this? 

0 Kudos
Message 5 of 15
(4,384 Views)

What hardware are you using and where did you get those drivers?  Does it really only return a single frame and not a buffer of them?  Your while loop has no delay, I'd suggest adding at least a wait 0ms to help with CPU usage.

 

As for your question about a queue.  You have a couple options, but the best would be to not deal with the doubles at this point.  I'd suggest sending the frame as a cluster to the consumer loop, which can then deal with the conversion, logging, and display.

0 Kudos
Message 6 of 15
(4,376 Views)

Thank you Hooovahh. Actually I am using a Peak System CAN bus interface and the drivers was bought from them. I managed to send in the CAN frames in cluster form into the buffer as you had suggested. But the problem is when I loop below 1ms (by placing a wait and wire in a 0.5ms value), I saw that in the text file where I wrote all the frames there are frames which were not written properly. I can't seem to solve this data lost issue. Do you have any suggestion how can I loop faster than 1ms to acquire all the CAN frame without having any data lost?

0 Kudos
Message 7 of 15
(4,309 Views)

This is a question for the manufacturer.  I can tell you for sure that NI hardware has a large buffer on it, and polling as often, or as seldom as you want results is all unread frames to be returned.

0 Kudos
Message 8 of 15
(4,307 Views)

Actually is there a way to loop the while loop faster than 1ms, like 50us? I don't have labview real time module so is there an alternative way to do so?

0 Kudos
Message 9 of 15
(4,285 Views)

Hi Trainee,

 

with LabVIEW on a standard OS (like Windows) you can only set loops with 1ms wait/iteration time. Even then you will have a notable jitter due to other (OS) tasks…

 

You might use the "hard-coded CPU-burning" way by using the HighResolutionRelativeSeconds function and an additional loop to wait for your 50µs - but be warned: this will burn your CPU and still wil show a huge jitter!

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 15
(4,278 Views)