socan library
The socan library API
The API has following features:
One library for accessing all CAN interfaces on a system. All CAN interfaces are addresses with a simple number, called port. A library function is used to associate CAN interface names on your system with port numbers.
Definition of CAN Objects. The application defines CAN Objects with a port, a COB, a length, a timeout and a type. Each CAN Object has a data buffer for one CAN frame and an optional extra data block (“user area”) that can hold data for the application that is associated with that CAN object.
Filtering of CAN Objects: Only defined CAN Objects of the “read” type can receive data. A data frame is only accepted if it’s size matches the length of the CAN Object.
Timestamp support. All CAN objects have a timestamp with microsecond resolution. For CAN Objects of type “read” this is this most recent time new data arrived. For CAN Objects of type “write” this is the time the CAN Object data was actually written to the CAN bus.
Blocking and non-blocking read- and write functions for single CAN Objects. The timeout for blocking read and blocking write is taken from the CAN Object definition.
Blocking read on an arbitrary number of CAN Objects with no timeout.
Implementation of RTR CAN frames with automatic generation of replies to incoming RTR frames.
The complete API documentation is here:
socan library design features
There is one reader and one writer thread for each CAN port that run, presuming sufficient permissions, with real time priorities. The real-time priorities can be configured. Without real time permissions, the library can still be used but real time properties may be a bit worse.
socan tests
A command line test program, sotest implements tests for almost all features of the library.
CAN hardware initialization
socan assumes that CAN devices are present on the system and are already set up.
How to set up and initialized your can interfaces is described at Set up your CAN device.
Tip
You can test socan even if you don’t have a CAN interface card by using virtual CAN Bus interfaces. Set up your CAN device describes how to do that.