Carpe diem
socketcan, can-utils 본문
리눅스에서는 can을 사용할 수 있도록 커널에서 socketcan이라는 것을 제공해준다.
하드웨어 (usb-can, can controller) 등을 can0또는 vcan0 장치로 생성을 해주면,(장치 번호는 다를 수 있음)
can0또는 vcan0 장치를 socket처럼 열어서 read, write을 할 수 있도록 해주는 것이 socketcan이다.
구글링을 해봐도 자료가 많이 없는 편이어서..
socketcan을 편리하게 사용할 수 있는 간단한 wrapper 함수들을 구현해봤다..
https://github.com/syjung0130/socketcan_wrapper
GitHub - syjung0130/socketcan_wrapper: simple wrapper to use socketcan
simple wrapper to use socketcan. Contribute to syjung0130/socketcan_wrapper development by creating an account on GitHub.
github.com
정상적으로 read, write이 되는지도 확인을 해봐야하는데,
can-utils패키지를 사용하면 편리하게 사용이 가능하다.
(우분투는 기본 패키지로 포함되어서 따로 설치를 하지 않아도 된다.)
그 외에도 cantools라는 python 패키지도 유용한 툴이었던 것 같다.
CAN 장치는 USB-CAN장치를 사용했다.
https://www.seeedstudio.com/USB-CAN-Analyzer-p-2888.html
USB to CAN Analyzer Adapter with USB Cable
This USB to CAN Analyzer can easily to collect the CAN-BUS data to your computer to analysis. Using this USB to CAN Analyzer to develop, test, manage and maintain CAN Bus networks, as well as receive, send and analyze CAN data by software of the analyzer.
www.seeedstudio.com
가격이 다른 케이블에 비해 비싸지 않다..
VCAN, CAN 장치 생성방법
https://elinux.org/Bringing_CAN_interface_up
Bringing CAN interface up - eLinux.org
Introduction SocketCAN provides several CAN interface types: virtual interfaces like vcan0 native (real hardware) interfaces like can0 SLCAN based interfaces like slcan0 Virtual Interfaces Virtual CAN interfaces will be brought up via iproute2 ip utility:
elinux.org