Page 1 of 1

CAN Message callback procedure?

Posted: Wed 3. Nov 2010, 23:20
by mdenton
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?

Re: CAN Message callback procedure?

Posted: Thu 4. Nov 2010, 14:07
by M.Maidhof
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

Re: CAN Message callback procedure?

Posted: Thu 4. Nov 2010, 14:12
by mdenton
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.

Re: CAN Message callback procedure?

Posted: Thu 4. Nov 2010, 15:26
by M.Maidhof
Hi,

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

regards

Michael

Re: CAN Message callback procedure?

Posted: Thu 4. Nov 2010, 15:29
by mdenton
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.