This forum covers PCAN-Linux and Linux development issues concerning our products
-
cheeyw
- Posts: 3
- Joined: Mon 28. Aug 2017, 15:41
Post
by cheeyw » Tue 29. Aug 2017, 18:16
I am using the linux headers of peak-linux-driver-8.4.0.
When I use OFD_NONBLOCKING flag in pcanfd_open, the receive function will be a pure non-blocking function.
How do I send & receive pcan messages with a fixed timeout?
Code: Select all
int fd = pcanfd_open("/dev/pcan32", OFD_BITRATE | OFD_BTR0BTR1 | OFD_NONBLOCKING, PCAN_BAUD_250K);
Are there any functions that are similar to:
Code: Select all
DWORD LINUX_CAN_Read_Timeout(HANDLE hHandle, TPCANRdMsg* pMsgBuff, int
nMicroSeconds);
DWORD LINUX_CAN_Write_Timeout(HANDLE hHandle, TPCANMsg* pMsgBuff, int
nMicroSeconds);
-
S.Grosjean
- Software Development

- Posts: 357
- Joined: Wed 4. Jul 2012, 17:02
Post
by S.Grosjean » Wed 30. Aug 2017, 10:32
Hello,
Simply setup the select() call by yourself: open lib/src/libpcan.c and have a look to both LINUX_CAN_xxx_Timeout() functions. Copy both functions in your own source, and replace "desc->fd" with your "fd".
Timed wait during "nMicroSeconds" for read one "msg" from "fd" should look like something like:
Code: Select all
struct timeval t;
fd_set fdRead;
int err;
/* calculate timeout values */
t.tv_sec = nMicroSeconds / 1000000L;
t.tv_usec = nMicroSeconds % 1000000L;
FD_ZERO(&fdRead);
FD_SET(fd, &fdRead);
/* wait until timeout or a message is ready to read */
err = select(fd + 1, &fdRead, NULL, NULL, &t);
/* the only one file descriptor is ready for read */
if (err > 0)
return pcanfd_recv_msg(fd, &msg);
/* nothing is ready, timeout occured */
if (!err)
return CAN_ERR_QRCVEMPTY;
Regards,
Stéphane
— Stéphane