polltest.c
来自「盛博can驱动程序功能很全」· C语言 代码 · 共 42 行
C
42 行
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <poll.h>
#include "sbscan.h"
int main(void)
{
int fd;
struct pollfd *fdarray;
unsigned long nfds=1;
int timeout=20;
fd=open("/dev/can0",O_RDWR);
if (fd<0)
printf("open failed\n");
fdarray=(struct pollfd *)malloc(sizeof(struct pollfd));
fdarray->fd=fd;
fdarray->events=POLLIN;
ioctl(fd,CAN_IOCRESET);
while (1) {
poll(fdarray,nfds,timeout);
if (fdarray->revents&POLLIN) {
printf("message come\n");
}
else
printf("no message\n");
}
if (close(fd))
printf("close failed\n");
return ;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?