pci-1680 can card use

Driver download address: Can card driver download address

1. Install can card driver under ubuntu

The ubuntu16.04 is used here. Although the description does not say that 16.04 can be used, the actual test is possible.

cd advcan_source_v2.0.19.0/driver/
make
sudo make install
sudo make nodes
cd utils/
sudo sh ./cansetup ../etc/advpci.conf

It should be fine.

2. Test Procedure

#include <stdio.h>
#include <iostream>
#include <pthread.h>
#include <ctime>
#include <cstdlib>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "can4linux.h"

#define STDDEV "can0"
#define MAX 500

using namespace std;

canmsg_t tx_state[MAX];
canmsg_t tx[MAX];
canmsg_t rx[MAX];
int fd;
int got=0;

int main(int argc, char **argv)
{
    
    
   int i, sent = 0, count = 0;
   char device[40];
   if(argc == 2) 
   {
    
    
      sprintf(device, "/dev/%s", argv[1]);
   }
   else 
   {
    
    
      sprintf(device, "/dev/%s", STDDEV);
   }
   printf("using CAN device %s\n", device);
   if(( fd = open(device, O_RDWR|O_NONBLOCK )) < 0 )
   {
    
    
      cout<<fd<<endl;
      fprintf(stderr,"Error opening CAN device %s\n", device);
      exit(1);
   }
   
  while(1)
  {
    
    
     
    tx_state[0].id=0x282;
    tx_state[0].length=1;
    tx_state[0].data[0]= 0xFF;
    write(fd,&tx_state[0],1);

    cout << "send!" << endl;
    got=read(fd, rx, MAX);
    
    if( got > 0)
    {
    
               
        unsigned int temp=0;
        int num=0;
        while(num<got)
        {
    
    
            cout << "rx[num].id:" << rx[num].id << endl;
            num++;
        }
    }
}

  close(fd);
  return 0;
}

Guess you like

Origin blog.csdn.net/qq_35632833/article/details/109136080