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

📄 cantxrx.c

📁 武汉创维特公司的2410arm9开发办的can linux源代码
💻 C
字号:
#include <stdio.h>#include <stdlib.h>//#include <unistd.h>#include <fcntl.h>#include <pthread.h>#include <asm-arm/arch-s3c2410/S3C2410_2.h>//#include <asm-arm/arch/hardware.h>//#inclued <asm-arm/arch/bitfield.h>#include "mcpcan.h"#include "spi_cmd.h"
#include "def.h"
//#include "2410addr.h"
#include "directio.h"//#include "option.h"
//#include "2410lib.h"


#define DEBUG#ifdef DEBUG#define dbgprintf(S) printf(S)#else#define dbgprintf(S)#endifint fd;void send(void * arg){        struct mcpcan_data *datagramptr = (struct mcpcan_data *)arg;        while(1)        {                      sleep(2);                write(fd, datagramptr, sizeof(struct mcpcan_data));                printf("send datagram.\n");                printf("the data sended is %s.\n", datagramptr->data);        }                                                                                                                                      }int main(){	pthread_t id;	int ret;	struct mcpcan_data data_receive;	struct mcpcan_data data_send;    /* 打印提示信息 */
	printf("---can总线测试程序---\n");
        data_send.BufNo = TXBUF0;        data_send.IdType = STANDID;        data_send.id = 23;        data_send.DataLen = 8;        strcpy(data_send.data, "-CVTECH-");	data_receive.BufNo = 0;
	data_receive.IdType = 0;
	data_receive.id = 0;
	data_receive.DataLen = 0;
	memset(data_receive.data,9,0x0);

	fd = open("/dev/can",O_RDWR);	if(fd < 0)	{		printf("Open device failed.\n");		return fd;	}	printf("Open device success.\n");

	ret=pthread_create(&id,NULL,(void *)send, &data_send);        if(ret!=0){		printf ("Create pthread error!\n");		exit (1);        }
	printf("Create pthread success.\n");	while(1)
	{			int datalen;
		read(fd, &data_receive, sizeof(struct mcpcan_data));
		printf("data_receive.BufNo = %d\n",data_receive.BufNo);		printf("data_receive.IdType = %d\n",data_receive.IdType);		printf("data_receive.id = %d\n",data_receive.id);		printf("data_receive.DataLen = %d\n",data_receive.DataLen);		printf("data_receive.data = %s\n",data_receive.data);	}	return 0;}

⌨️ 快捷键说明

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