Generic CAN
Generic CAN is a transport-agnostic driver for raw CAN Bus traffic. It applies no application-layer protocol of its own: every field is addressed as a raw node id plus a data type, and the values written or received for a single node id are packed into a single CAN frame in field order. It is a good fit where the devices on the bus speak a proprietary or undocumented protocol built directly on raw CAN frames - anything that follows a specific higher-level protocol on top of CAN bus, such as CANopen, is better served by CANopen.
Supported Operations
| Name | Value | Description |
|---|---|---|
publish |
|
Publishes a CAN frame via the CAN transport. |
receive |
|
Listens for incoming CAN frames matching a subscribed node id. |
There is no read support; the driver only writes and subscribes.
Connection String
genericcan:can-socketcan://{interface}[?{options}]
genericcan:can-virtualcan://{bus-name}[?{options}]
genericcan:can-socketcan://can0
genericcan:can-virtualcan://test
The interface and the bus name can also be given as options - can-socketcan.interface-name and
can-virtualcan.bus-name - for callers that assemble a connection string out of options alone.
The address segment wins if both name one.
Connection String Options
Name |
Type |
Default Value |
Required |
Description |
Name |
Generic CAN |
|||
Code |
|
|||
Maven Dependency |
<dependency> <groupId>org.apache.plc4x</groupId> <artifactId>plc4j-driver-can</artifactId> <version>1.0.0</version> </dependency> |
|||
Default Transport |
|
|||
Supported Transports |
|
|||
Config options: |
||||
|
INT |
Node id of the target device. |
||
|
INT |
1000 |
Default timeout for all types of requests. |
|
Transport config options: |
||||
can-socketcan |
||||
|
STRING |
Linux CAN interface name (e.g., "can0", "vcan0"). Alternative to naming the interface in the address segment of the connection string, which takes precedence. |
||
|
BOOLEAN |
false |
Share CAN socket across multiple transport instances on the same interface |
|
|
INT |
1000 |
Read timeout in milliseconds for blocking reads on the CAN socket |
|
|
STRING |
Comma-separated list of accepted CAN IDs (decimal or 0x hex). Empty means accept all. |
||
|
INT |
-1 |
Start of accepted CAN ID range (inclusive). -1 means no range filtering. |
|
|
INT |
-1 |
End of accepted CAN ID range (inclusive). -1 means no range filtering. |
|
can-virtualcan |
||||
|
STRING |
default |
Name of the virtual CAN bus. Instances on the same bus exchange frames in-memory. |
|
|
STRING |
Comma-separated list of accepted CAN IDs (decimal or 0x hex). Empty means accept all. |
||
|
INT |
-1 |
Start of accepted CAN ID range (inclusive). -1 means no range filtering. |
|
|
INT |
-1 |
End of accepted CAN ID range (inclusive). -1 means no range filtering. |
|
Tag Addresses
Addressing is implemented in Java. There is no read support; the driver writes and subscribes. See the protocol support matrix for what each implementation does.
General Format
nodeId:type[arraySize]
nodeId is a plain (non-hexadecimal) integer CAN node/frame identifier. type is one of the data
types listed below. arraySize is optional; see Addressing arrays.
The underlying pattern (GenericCANTag.java:36-37) is
(?<nodeId>\d+):(?<dataType>\w+)(?:\[(?<arraySize>\d+)\])?. It is not anchored with ^/$, but
GenericCANTag.matches() (GenericCANTag.java:83) applies it with Matcher.matches(), which
requires the whole input string to match. Trailing text after a valid address is therefore
rejected, not silently ignored.
You can use multiple fields to write and subscribe actual data. All fields together must sum up to 64 bits. If you subscribe to less than the frame contains, the remaining data is discarded and not available via the PLC4X API. Written and received data is ordered the same as the fields in the request.
Data Types
Address Type |
Length (in bits) |
PLC4X Type |
BOOLEAN |
1 |
BOOL |
UNSIGNED8 |
8 |
USINT |
UNSIGNED16 |
16 |
UINT |
UNSIGNED24 |
24 |
UDINT |
UNSIGNED32 |
32 |
UDINT |
UNSIGNED40 |
40 |
ULINT |
UNSIGNED48 |
48 |
ULINT |
UNSIGNED56 |
56 |
ULINT |
UNSIGNED64 |
64 |
ULINT |
INTEGER8 |
8 |
SINT |
INTEGER16 |
16 |
INT |
INTEGER24 |
24 |
DINT |
INTEGER32 |
32 |
DINT |
INTEGER40 |
40 |
LINT |
INTEGER48 |
48 |
LINT |
INTEGER56 |
56 |
LINT |
INTEGER64 |
64 |
LINT |
REAL32 |
32 |
REAL |
REAL64 |
64 |
LREAL |
This type table is similar to CANopen’s. The main difference is the lack of support for string types.