?? readburst.c
字號:
#include <stdio.h>#include <fcntl.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <signal.h>#include "../include/can.h"int fd;/*--- handler on SIGINT signal : the program quit with CTL-C ---*/void sortie(int sig) { close(fd); printf("Terminated by user\n"); exit(0); }int main(void) { int n,ret; unsigned long i=0; struct canmsg_t readmsg={0,0,5,0,0,{0,}}; struct sigaction act; /*------- register handler on SIGINT signal -------*/ act.sa_handler=sortie; sigemptyset(&act.sa_mask); act.sa_flags=0; sigaction(SIGINT,&act,0); /*---------------------------------------*/ if ((fd=open("/dev/can0",O_RDWR)) < 0) { perror("open"); printf("Error opening /dev/can0\n"); exit(1); } while (1) { readmsg.flags=0; readmsg.cob=0; readmsg.timestamp=0; ret=read(fd,&readmsg,sizeof(struct canmsg_t)); if(ret <0) { printf("Error reading message\n"); } else { printf("Received message #%lu: id=%lX dlc=%u",i,readmsg.id,readmsg.length); for(n=0 ; n<readmsg.length ; n++) printf(" %.2X",(unsigned char)readmsg.data[n]); printf("\n"); i++; } } return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -