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

📄 fasynctest.c

📁 盛博can驱动程序功能很全
💻 C
字号:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include  <signal.h>


int input_handler(void)
{
 printf("message come!\n");
 return 0;
} 

int main(void)
{
 int fd;
 int result;

signal(SIGIO,&input_handler); 

fd=open("/dev/can0",O_RDWR);
if (fd<0)
    printf("open failed\n");
 
fcntl(fd,F_SETOWN,getpid());
fcntl(fd,F_SETFL, FASYNC|fcntl(fd,F_GETFL));

while (1) {
 /*
  here you can do your other job ,such as analyse the data ,send answer message
  etc, especially for the process which need much time,you can process it while
  no data come.if data came ,the input_handler will receive it in buf automatic 
  and needn't  you wait the data comming.
*/ 
}

 if (close(fd)) 
   printf("close failed\n"); 

return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -