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

📄 test.c

📁 在linux操作系统下CAN收发程序的示例源代码。
💻 C
字号:
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/types.h>


#include "../can.h"

int main( void )
{
  struct canmsg_t sendmsg={0,0,5,0,8,{1,2,3,4,5,6,7,8}};
  int fd1, fd2, ret,i;
   
  if ( ( fd1 = open("/dev/can0", O_WRONLY ) ) < 0 )  {
    perror("open");
    printf("Error opening /dev/can0\n");
    exit(1);
  }
  
  if ( ( fd2 = open("/dev/can1", O_RDONLY ) ) < 0 )  {
    perror("open");
    printf("Error opening /dev/can1\n");
    exit(1);
  }

  sendmsg.data[ 0 ] = 1;
  sendmsg.data[ 1 ] = 88;
  if ( write( fd1, 
	      &sendmsg, 
	      sizeof(struct canmsg_t) ) < 0 ) {
    perror("write");
    printf("Error sending message\n");
  }

  sleep( 10 );
  close( fd2 );
  close( fd1 );
  printf("Done\n");
  return 0;
}

	






































⌨️ 快捷键说明

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