CAN
总线配置
在
Linux
系统中,
CAN
总线接口
设
备作为网络
设
备
被
系统进行统一
管
理。在控制
台下
,
CAN
总线
的配置和以
太
网的配置使用相
同
的
命令
。
在控制
台
上输
入命令:
ifconfig –a
可以得到以下结果:
can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
NOARP MTU:16 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:18
eth0 Link encap:Ethernet HWaddr 00:50:c2:22:3b:0e
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth1 Link encap:Ethernet HWaddr 00:50:c2:22:3b:60
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:41 Base address:0xe000 lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:256 errors:0 dropped:0 overruns:0 frame:0
TX packets:256 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0 RX bytes:19952 (19.9 KB) TX bytes:19952 (19.9 KB)
在上面的
结果
中,
eth0
和
eth1
设
备为以
太
网接口,
can0
设
备为
CAN
总线接口。接
下
来使用
ip
命
令
来配置
CAN
总线的位速
率:
ip link set can0 type cantq 125 prop-seg 6phase-seg1 7 phase-seg2 2 sjw 1
也
可以使用
ip
命令直
接
设
定位速
率:
ip link set can0 type can bitrate 125000
当
设
置
完
成后,可以通过
下
面的
命令查询
can0
设
备的
参
数
设
置
:
ip -details link show can0
当
设
置
完
成后,可以使用
下
面的
命令
使能
can0
设
备
:
ifconfig can0 up
使用
下
面的
命令取消
can0
设
备使能
:
ifconfig can0 down