send.c

来自「在linux操作系统下CAN收发程序的示例源代码。」· C语言 代码 · 共 49 行

C
49
字号
#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 fd, ret,i;
   
  if ( ( fd = open("/dev/can1", O_RDWR ) ) < 0 )  {
    perror("open");
    printf("Error opening /dev/can1\n");
    exit(1);
  }
  
  for( i=0; i<1; i++ ) {
    sendmsg.data[ 0 ] = i;
    sendmsg.data[ 1 ] = i + 88;
    if ( ( ret = write( fd, 
			&sendmsg, 
			sizeof(struct canmsg_t) ) ) < 0 ) {
      perror("write");
      printf("Error sending message\n");
      break;
    }
    printf("??????????????Sent message %i.\n", i);
  }
  
  sleep( 10 );
  close( fd );
  printf("Done\n");
  return 0;
}

	







⌨️ 快捷键说明

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