can_bus_receive.c

来自「linux对sja100t,can总线操作及can简单通讯程序」· C语言 代码 · 共 42 行

C
42
字号
#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <stdlib.h>//**********************#define       DEBUG//*********************int main(){        int fd;        int i,j,ret;        char buf[11];        fd=open("/dev/can_bus",O_RDWR);        if (fd<0)        {        printf("Error open can_bus\n");        }      #ifdef  DEBUG        printf("read begin!\n");#endif        ret=read(fd,buf,11);        printf("\nData received is:");//        sleep(10);		for(i=1;i<11;i++)	{	printf("%x",buf[i]);	}#ifdef  DEBUG        printf("\nread end!\n");#endif        }

⌨️ 快捷键说明

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