I took time to read and modify your multiport.c program:
Code: Select all
$ sudo ./multiport_rt
pcan3 status = Broken pipe
pcan4 status = Broken pipe
Sending ... frame: m s 0x00000008 4 01 02 03 04
Receiving ... frame: m s 0x00000008 4 01 02 03 04
1/ CAN_Open() enumerates ports from 1 (not from 0) so please change:
Code: Select all
#define CAN_PORT_1 1 // logical port number for physical port 1
#define CAN_PORT_2 2 // logical port number for physical port 2
Code: Select all
trx_task = rt_task_init_schmod(102, 2, 0, 0, SCHED_FIFO, 0xF);
if (!trx_task) {
printf("rt_task_init_schmod() failed errno=%d\n", errno);
exit(1);
}
Write this instead (for example):
Code: Select all
err = CAN_Read(h2, &msg); // this will block/wait until either an error occur
s or data is coming
if (err) {
printf("error %d while reading: %s\n", errno, strerror(errno));
goto error;
}
4/ Re-order the way you exit your program, by closing handles before exiting RT mode, to use the RT close entry points of the RT driver:
Code: Select all
error:
// close ports
CAN_Close(h2);
error_2:
CAN_Close(h1);
// back to user mode
exit_user:
rt_make_soft_real_time();
rt_task_delete(trx_task);
6/ You SHOULD add a test on MSGTYPE when analysing a received msg since you might receive messages that are not CAN frames:
Code: Select all
if (m->MSGTYPE & MSGTYPE_STATUS)
printf("status: id=%u ", m->ID);
else
printf("frame: %c %c %c 0x%08x %1d ",
Stéphane