安裝與設定
- 在 Ubuntu, Dabian 底下安裝方式為:
- sudo apt-get install can-utils
- 手動載入模組:
- sudo modprobe can
- 如果手邊沒有 CAN to USB 的硬體裝置可以使用虛擬的 CAN:
- sudo modprobe vcan
- 設定介面卡(ifconfig)真實 CAN to USB 硬體:
- sudo ifconfig can0 up
- 虛擬的 CAN (vcan):
- sudo ip link add dev vcan0 type vcan
- sudo ip link set up vcan0
電腦上裝有 CAN to USB 裝置
- 觀看線上(CAN Bus)狀況指令 candump:
- candump can0
- 如果只要秀特定 ID 的內容例如 0x567:
- candump can0,0x567:0x7FF
- 如果要秀特定的兩組 ID 內容如 0x567 與 0x678 則下:
- candump can0,0x567:0x7FF,0x678:0x7FF
- 以此類推
- 發出 CAN Message 例如 ID:0x456, Data:88 77 66 55 44 33 22 11:
- cansend can0 456#8877665544332211
虛擬 CAN 裝置
- 觀看線上(CAN Bus)狀況指令 candump:
- candump vcan0
- 如果只要秀特定 ID 的內容例如 0x567:
- candump vcan0,0x567:0x7FF
- 如果要秀特定的兩組 ID 內容如 0x567 與 0x678 則下:
- candump vcan0,0x567:0x7FF,0x678:0x7FF
- 以此類推
- 發出 CAN Message 例如 ID:0x456, Data:88 77 66 55 44 33 22 11:
- cansend vcan0 456#8877665544332211
在 linux 底下編譯/安裝 PCAN driver
- 下載驅動程式
- http://www.peak-system.com/fileadmin/media/linux/files/peak-linux-driver-7.15.2.tar.gz
- 解壓縮驅動程式
- tar xvaf peak-linux-driver-7.15.2.tar.gz
- 進入驅動程式資料夾
- cd peak-linux-driver-7.15.2/drivers
- 清除已編譯的檔案
- make clean
- make NET=NO
- 開始編譯
- make
- 安裝編譯後的驅動程式
- make install
在 linux 底下移除 PCAN driver
- 進入驅動程式資料夾
- cd peak-linux-driver-7.15.2/
- 移除驅動程式
- sudo make uninstall
相關連結
Using can-utils https://discuss.cantact.io/t/using-can-utils/24
SocketCAN https://en.wikipedia.org/wiki/SocketCAN
How to create virtual CAN port on linux? (C++) http://stackoverflow.com/questions/21022749/how-to-create-virtual-can-port-on-linux-c