CAN Message callback procedure?

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
mdenton
Posts: 19
Joined: Thu 23. Sep 2010, 16:04

CAN Message callback procedure?

Post by mdenton » Wed 3. Nov 2010, 23:20

Hi,

I am using a dual peak PC-104 board on my embedded Linux system. I have installed the peak drivers on my target device and have my two can ports working in chardev mode, installed as /dev/pcan8 and /dev/pcan9.

Today I got my own code running using the supplied driver, so far so good, I have implemented a basic control and test application for my target which is talking to 6 CANBus four channel hydraulic valve controllers. However, I am wondering if there is a way to install a "message received" callback procedure, instead of having to poll for received messages?
Matt Denton

Micromagic Systems - www.micromagicsystems.com
Hexapod Robot - www.hexapodrobot.com

M.Maidhof
Support
Support
Posts: 1753
Joined: Wed 22. Sep 2010, 14:00

Re: CAN Message callback procedure?

Post by M.Maidhof » Thu 4. Nov 2010, 14:07

Hi,

thanks for the info. With our chardev Linux driver its possible to open the device in blocking or non blocking mode. So when you use blocking mode the CAN_Read function will only return when there are new messages in the buffer. So this will be similar to a receive event under Windows.

h = LINUX_CAN_Open("/dev/pcan32", O_RDWR); // blocking
h = LINUX_CAN_Open('/dev/pcan0', O_NONBLOCK); //O_NONBLOCK

best solution will be to create a separate thread for the CAN_Read than.

regards

Michael
Last edited by M.Maidhof on Thu 4. Nov 2010, 15:24, edited 1 time in total.

mdenton
Posts: 19
Joined: Thu 23. Sep 2010, 16:04

Re: CAN Message callback procedure?

Post by mdenton » Thu 4. Nov 2010, 14:12

Hi Michael,

That is exactly what I have at the moment, I opened the port in on blocking pode, and poll it within a separate thread. Just wanted a slightly more elegant solution.
Matt Denton

Micromagic Systems - www.micromagicsystems.com
Hexapod Robot - www.hexapodrobot.com

M.Maidhof
Support
Support
Posts: 1753
Joined: Wed 22. Sep 2010, 14:00

Re: CAN Message callback procedure?

Post by M.Maidhof » Thu 4. Nov 2010, 15:26

Hi,

but when using the blocking mode its not polling, polling is only possible in non blocking mode!

regards

Michael

mdenton
Posts: 19
Joined: Thu 23. Sep 2010, 16:04

Re: CAN Message callback procedure?

Post by mdenton » Thu 4. Nov 2010, 15:29

Ok,

I guess that depends how you describe "polling" My definition of polling is having to call a function such as LINUX_CAN_Read... to find out if it has a CAN message for you. As opposed to having a callback / signal handler tell you that a message is ready.
Matt Denton

Micromagic Systems - www.micromagicsystems.com
Hexapod Robot - www.hexapodrobot.com

Post Reply