LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can Communication lag

Hey everyone 🙂 Me again!

 

right now I develop a Labview Software using the CAN BUS protocol.

I use a PCAN adapter that is connected via USB. Communication works via PCAN_Driver_LV2010 v1.0.0

https://lavag.org/files/file/211-pcan-driver_lv2009/, I can send and receive and control the device.

 

BUT: I do have a strange time lag reading. An example: I read the can message for voltage and display them in a diagram. The device is continuously sending the voltage can message. If I switch off the device, data continues to be displayed for a minute or so, unless the device is already turned off and stopped to send data some time ago. I verified it with PCAN viewer, that uses the same connection and immediately stops to receive data when I switch off the device... So - principally it is possible.

 

I posted a screenshot to clarify what happenes and I posted my reading vi. If you need further information please let me know.

 

Precise questions:

 

1) Is there a buffer, the driver is reading from?

2) Do I read too slow (not often enough)?

 

 

If anyone has experience with the use of the PCAN Dongle and the driver mentioned or an idea, please let me know 🙂

Best regards

Anna

Download All
0 Kudos
Message 1 of 14
(3,433 Views)

Your read buffer is filling up because you aren't reading from the device as fast as data is coming in.  You have a control Ze wartende which is set to 10 ms.  Well after that 10ms wait you go and read a single frame.  Even at 125Kbaud you will likely get a message must faster than once every 10ms.  What you should be doing is every 10ms read ALL messages in your buffer, then wait another 10ms and then read ALL messages in your buffer.  An easy way to do this is to put a while loop around around your read and keep reading all messages until there are no more to read.

Message 2 of 14
(3,400 Views)

Hi,

 

thx for your answer! Good idea! Sounds very simple and now, that I read it, I wonder why I didn't come up with it myself 😛

I will give it a go and report...

 

regards

Anna

 

0 Kudos
Message 3 of 14
(3,378 Views)

Hi Anna,

 

does that PCAN interface API allow to read more than just one CAN message with PCAN_Read (or similar VI)?

This would simplify to read the CAN messages without filling up a backlog buffer!

Best regards,
GerdW


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

A lot of these cheaper CAN devices are just DLL wrappers of function calls.  Several I've seen just read a single frame at a time, some don't have an ability to read the number of frames waiting in the buffer, which is why I suggested just reading in a while loop until an error is returned (or no new frame comes in).  Just another reason why I love the flexibility of XNet.  That being said I've used cheap less functional hardware many times for simple things, you just need to know extra software layers like this might be needed to do things like read all remaining frames.

0 Kudos
Message 5 of 14
(3,363 Views)

Hello, 

Is it possible to use 2 PEAK CAN adapters (for 2 different CAN buses) with PCAN_Driver_LV2010 v1.0.0 library?

0 Kudos
Message 6 of 14
(3,256 Views)

It doesn't look like the DLL has the ability to specify the device to talk to.  It could be that there are newer version of the DLL from the manufacturer but that driver seems very limited.  Might I recommend an XNet device.  The USB-8205 has two High speed or CAN FD ports via USB and supports all kinds of useful features with different sessions types, frame signal API and database management, with lots of shipped examples.

Message 7 of 14
(3,248 Views)

Thank you for fast reply.

0 Kudos
Message 8 of 14
(3,243 Views)

Hello,

I have implemented the same reading CAN messages in while loop.The baud rate is 250 Kbps.My device sends a message with transmission rate 25ms. But when I log the data I cant see the difference in two CAN frames of same message near to 25ms, its almost 1 ms.I am using High resolution Relative Seconds.vi for timing reference in log.

If I take trace from PCAN View the same message shows cycle time of 25 ms correctly.

So my doubt is -

How can I use PCAN_Read.vi effectively to read CAN messages and get correct transmission rate.

How the PCAN_USB.dll is working for storing data in buffer? 

0 Kudos
Message 9 of 14
(3,028 Views)

Hi prajakta,

 

when you ask for help on "improvements to my code" you should actually attach your code…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 10 of 14
(3,021 Views)