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

📄 can_write.c

📁 ATEML AT91SAM9260测试程序。包括 can测试
💻 C
字号:
/* * can_test.c * * Copyright (C) 2007 Mengrz */#include <sys/types.h>#include <sys/unistd.h>#include <sys/stat.h>#include <linux/fcntl.h>#include <linux/ioctl.h>#include "can.h"int main(int argc, char *argv[]){    if (argc < 2) {	printf("Useage: %s dev\n", argv[0]);	exit(0);    }        struct can_frame frame;        int device = open(argv[1], O_RDWR);    if (device == -1){	perror("open:device");	exit(-1);    }            int i,can_id = 1;    int rate;    ioctl(device, CAN_IOCSRATE, 250000);    ioctl(device, CAN_IOCGRATE, &rate);        printf("%s Work Rate: %dbps\n", argv[1], rate);            while(1)    {		memset(&frame, 0, sizeof(struct can_frame));	sprintf(frame.data, "%d", can_id);	frame.header.id = can_id;	frame.header.dlc = strlen(frame.data);	if ((can_id % 2) == 0) {	    frame.header.ide = 1;	    frame.header.eid = can_id * 2 + 1;	}else{	    frame.header.ide = 0;	    frame.header.eid = 0;	}	can_id++;	if (can_id > 2031) {	    can_id = 1;	}			int ret = write(device, &frame, sizeof(struct can_frame));	if (ret < 0)	    perror("write");		sleep(3);	    }        close(device);        return 0;    }

⌨️ 快捷键说明

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