//第一步:打开controlcan文件夹中的Makefile文件,修改文件中的相应的路径:g++ -o hello_cpp main.cpp /home/ttc/Desktop/controlcan/libcontrolcan.so -lpthread (按实际路径修改) //以下部份为查看系统信息。可省略。 ttc@ubuntu:~$ uname -a Linux ubuntu 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:34:49 UTC 2016 i686 i686 i686 GNU/Linux ttc@ubuntu:~$ ttc@ubuntu:~$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/5/lto-wrapper Target: i686-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.3.1-14ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-i386/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-i386 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-i386 --with-arch-directory=i386 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-targets=all --enable-multiarch --disable-werror --with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu Thread model: posix gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2) ttc@ubuntu:~$ //以上部份为查看系统信息。可省略。 //以下命令是查看USB设备信息,插上USB即可查找到ID 04d8:0053 Microchip Technology, Inc. 设备,无需安装USB驱动。USB驱动已集成在二次开发库中。 ttc@ubuntu:~$ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 004: ID 04d8:0053 Microchip Technology, Inc. Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub ttc@ubuntu:~$ //以上命令是查看USB设备信息,插上USB即可查找到ID 04d8:0053 Microchip Technology, Inc. 设备,无需安装USB驱动。USB驱动已集成在二次开发库中。 //将controlcan文件夹放在桌面。把CAN1与CAN2对接,运行后,可以看到程序内置的发送数据,被另一个通道接收。 ttc@ubuntu:~$ ls Desktop Downloads Music Public Videos Documents examples.desktop Pictures Templates ttc@ubuntu:~$ cd \Desktop ttc@ubuntu:~/Desktop$ ttc@ubuntu:~/Desktop$ ls controlcan ttc@ubuntu:~/Desktop$ ttc@ubuntu:~/Desktop$ cd \controlcan ttc@ubuntu:~/Desktop/controlcan$ ttc@ubuntu:~/Desktop/controlcan$ ls controlcan.h hello_cpp libcontrolcan.so main.cpp Makefile ttc@ubuntu:~/Desktop/controlcan$ rm hello_cpp ttc@ubuntu:~/Desktop/controlcan$ ttc@ubuntu:~/Desktop/controlcan$ ls controlcan.h libcontrolcan.so main.cpp Makefile ttc@ubuntu:~/Desktop/controlcan$ ttc@ubuntu:~/Desktop/controlcan$ gedit main.cpp //在此处修改测试样例程序C代码。main.cpp //保存,关闭C代码。main.cpp ttc@ubuntu:~/Desktop/controlcan$ ttc@ubuntu:~/Desktop/controlcan$ ls controlcan.h libcontrolcan.so main.cpp Makefile ttc@ubuntu:~/Desktop/controlcan$ ttc@ubuntu:~/Desktop/controlcan$ make clean && make rm -f *.o hello #gcc -o hello -L. -lcontrolcan -lpthread -lusb main.c #arm-none-linux-gnueabi-gcc -o hello -L. -L /home/caidunqing/controlcan -lcontrolcan -lpthread main.c g++ -o hello_cpp main.cpp /home/ttc/Desktop/controlcan/libcontrolcan.so -lpthread ttc@ubuntu:~/Desktop/controlcan$ sudo ./hello_cpp [sudo] password for ttc: >>this is hello ! >>open deivce success! >>Get VCI_ReadBoardInfo success! >>Serial_Num:01701019000 >>hw_Type:CAN-Linux Index:0000 CAN1 TX ID:0x00000000 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 Index:0001 CAN2 TX ID:0x00000001 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 Index:0002 CAN1 TX ID:0x00000002 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 Index:0003 CAN2 TX ID:0x00000003 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 Index:0004 CAN1 TX ID:0x00000004 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 Index:0005 CAN2 TX ID:0x00000005 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 Index:0006 CAN1 TX ID:0x00000006 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 Index:0007 CAN2 RX ID:0x00000000 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 TimeStamp:0x065FA867 Index:0008 CAN1 RX ID:0x00000001 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 TimeStamp:0x065FA877 Index:0009 CAN2 TX ID:0x00000007 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 Index:0010 CAN1 TX ID:0x00000008 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 Index:0011 CAN2 TX ID:0x00000009 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 Index:0012 CAN2 RX ID:0x00000002 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 TimeStamp:0x065FA882 Index:0013 CAN2 RX ID:0x00000004 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 TimeStamp:0x065FA89A Index:0014 CAN1 RX ID:0x00000003 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 TimeStamp:0x065FA88E Index:0015 CAN1 RX ID:0x00000005 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 TimeStamp:0x065FA8A5 Index:0016 CAN1 RX ID:0x00000007 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 TimeStamp:0x065FA8BD Index:0017 CAN2 RX ID:0x00000006 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 TimeStamp:0x065FA8B1 Index:0018 CAN2 RX ID:0x00000008 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 TimeStamp:0x065FA8C8 Index:0019 CAN1 RX ID:0x00000009 Extend Data DLC:0x08 data:0x 00 01 02 03 04 05 06 07 TimeStamp:0x065FA8D4 run thread exit ttc@ubuntu:~/Desktop/controlcan$