04-15-2015 04:51 AM
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?
04-15-2015 05:53 AM
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)…
04-15-2015 06:25 AM
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.
04-15-2015 06:28 AM
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…
04-15-2015 07:09 AM
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?
04-15-2015 07:37 AM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-22-2015 11:27 AM
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?
04-22-2015 11:40 AM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
16 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-24-2015 02:12 AM
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?
04-24-2015 02:24 AM - edited 04-24-2015 02:37 AM
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!