一、这是我在学习socketcan时看到的一篇文章(超级萌新),可以参考学习。
Example C SocketCAN Code
1、资料
1)官方手册(Official documentation for the SocketCAN interface)
2)下面例子的完整代码(Complete code for the following examples)
2、例子不含有make files,可以用gcc命令生成可执行文件
gcc cantransmit.c -o cantransmit
命令:gcc test.c -o test 含义:将test.c预处理、汇编、编译并链接形成可执行文件test。-o选项用来指定输出文件的文件名。
3、步骤
1)Opening and binding to a CAN socket
create a socket
int s;
if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
perror("Socket");
return 1;
}