⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 polltest.c

📁 盛博can驱动程序功能很全
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -