[CAN 05] - PCAN Device Driver Installation on Linux
Step-by-step guide to installing PEAK-System's PCAN drivers on Linux for SocketCAN and PCAN-Basic API
PEAK-System’s PCAN hardware is a staple in robotics and industrial automation. On Linux, developers generally have two interface options: the native SocketCAN (NetDev) and the proprietary PCAN Driver (CharDev).
While SocketCAN offers great “plug-and-play” convenience, many advanced robotics projects require the specific capabilities of the Character Device (CharDev) driver.
Why Professional Developers Choose CharDev
- PCAN-Basic API Compatibility: It is the only way to use the PCAN-Basic API on Linux. This allows for seamless code portability between Windows and Linux, preserving your existing development workflow.
- Deterministic Hardware Access: By bypassing the Linux network stack, CharDev offers a direct path to the hardware. This minimizes jitter and overhead, which is critical for high-frequency control loops (1 kHz+) where timing consistency is paramount.
- Persistent Device Addressing: Unlike network interfaces (
can0,can1) that can reorder on reboot, CharDev allows you to reliably identify hardware using persistent Device IDs, simplifying the management of multi-axis robotic systems.
In this guide, we will walk through the compilation and installation of the PEAK-System proprietary driver and the PCAN-Basic API on Linux.
Part 1: Installing the PCAN Linux Driver
First, we need to install the core driver. You can find the latest proprietary PCAN-Linux driver package here. For deeper technical details, you can always refer to the official PCAN Driver Manual.
Step 1: Download and Extract
Once you’ve downloaded the driver package, open your terminal and extract the files:
tar -xzvf peak-linux-driver-*.tar.gz
Navigate into the newly created directory and clear out any old build files:
cd peak-linux-driver-*
make clean
Step 2: Install Dependencies
Before we can compile the driver, our system needs a few development libraries. Install them using apt:
sudo apt-get update
sudo apt-get install libelf-dev libpopt-dev
Step 3: Compile and Install
Now you are ready to build the driver. Run the following commands:
make clean
make
sudo make install
🛠️ Troubleshooting: GCC Errors If you encounter compilation errors and are using
gcc-11, try compiling withgcc-12instead. You can do this by specifying the compiler in your make command:make clean make CC=gcc-12 sudo make install
A Note on SocketCAN vs. PCAN-Basic
By default, running the standard make command builds the driver with chardev (Character Device) support. This is exactly what you need if you plan to use the PCAN-Basic API.
However, if your goal is to use the device with SocketCAN (which typically works without driver installation on modern kernels, but might need an update on older ones), you must explicitly rebuild the driver with network device support (netdev):
make -C driver NET=NETDEV_SUPPORT
Part 2: Installing the PCAN-Basic API
With the base driver installed via chardev, we can now install the PCAN-Basic API. This API provides the necessary libraries to write custom applications (in C++, Python, etc.) that communicate with your CAN bus.
Step 1: Download and Extract
Head over to the PEAK-System website and Download the PCAN-Basic API for Linux.
Extract the tarball and navigate into the pcanbasic source directory:
tar -xzvf PCAN-Basic_Linux-*.tar.gz
cd PCAN-Basic_Linux-*/libpcanbasic/pcanbasic/
Step 2: Compile and Install
Just like with the driver, we will clean, make, and install the API libraries:
make clean
make
sudo make install
Part 3: Load the Driver
Normally, installing kernel modules requires a system reboot. However, you can bypass this and start using your CAN interface immediately by asking the Linux kernel to probe for the newly installed PCAN module:
sudo modprobe pcan
Plug in your PCAN hardware, and you are ready to start sniffing, sending, and analyzing CAN frames!