Multi-CAN interface

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
Terje
Posts: 12
Joined: Sun 27. Sep 2020, 19:04

Multi-CAN interface

Post by Terje » Mon 26. Oct 2020, 16:15

Hi.
I'm wondering if you have any good advice to me.
I'm writing a program for a Linux-computer which should read data from 12 USB-CAN channels (2x PCAN-USB FDx6).
I'm ready with my code and it works perfect.

BUT,, I have coded using threads in C .
That has resulted in 100% loaded CPU-cores (all six of them.)
Is there a better way to catch data from several can-busses?

Next for me is to test with separate processes. Not sure if it helps.

But I guess somebody out there has got it working.

The Select command sit there and waits for data.Is there a memory queue in the drivers?
Or is it possible to check several channels within on select command? Probably not since it require a handle.

/Terje.

M.Heidemann
Sales & Support
Sales & Support
Posts: 290
Joined: Fri 20. Sep 2019, 13:31

Re: Multi-CAN interface

Post by M.Heidemann » Mon 26. Oct 2020, 16:25

Hello Terje,

What does Linux-computer mean in your case?

Can you give us some hardware-specs to see if you might some ceiling in terms of whats possible?

Furthermore, which API are you using?


Best Regards

Marvin

Terje
Posts: 12
Joined: Sun 27. Sep 2020, 19:04

Re: Multi-CAN interface

Post by Terje » Wed 28. Oct 2020, 06:44

Linux can driver 8.10.2 64-Bit.
PEAK Basic API 4.4.0 .
Ubuntu 20.04.1 LTS 64-Bit
The computer is an Intel i5. with 6 cores.
8MB of memory. 480GB MM2 drive.
Two PCAN-USB x 6 IPEH-004064.

Is there any input cache in the PCAN-USBx6 Device?
Does the drivers have any cache? or queue?

/Terje.

M.Heidemann
Sales & Support
Sales & Support
Posts: 290
Joined: Fri 20. Sep 2019, 13:31

Re: Multi-CAN interface

Post by M.Heidemann » Wed 28. Oct 2020, 09:25

Hello Terje,

Thank you for the information.

Yes, the driver does use a queue, those queues are also referenced quite a few times in the PCAN-Linux Driver Documentation:
queues.PNG
queues.PNG (8.04 KiB) Viewed 235 times

Most likely you are reading constantly, which of course will drive CPU usage up.

A recommendation here is to use event-driven reading instead of a constant call of read within a loop.

For this you can take a look at the example "pcaneventread" to see how events can be used to initiate a read. You can find this example in.

Code: Select all

 peak-linux-driver-8.10.2\libpcanbasic\examples\c++\src 
Please report back to me if this approach was able to resolve your issue.


Best Regards

Marvin

Terje
Posts: 12
Joined: Sun 27. Sep 2020, 19:04

Re: Multi-CAN interface

Post by Terje » Wed 28. Oct 2020, 11:40

Hi.
Thanks for a quick answer.

I based my code on your program example pcan event read.

Anyways I tested threads. One thread-process for each can-interface.
Every thread would occupy one core to almost 100% cpu.

I don't think select and treads works together well.

Anyways, I have now changed the code using fork() to make 6 extra processes.
All cpu-cores are now resting at 1 - 10%.

Success..

/Terje.

Post Reply