Protocols

Generic CAN

qianmoQqianmoQ· 更新于 2026-09-30· 阅读 12 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

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

NameValueDescription
publishwritePublishes a CAN frame via the CAN transport.
receivesubscribeListens 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

genericcan

Maven Dependency

<dependency>
  <groupId>org.apache.plc4x</groupId>
  <artifactId>plc4j-driver-can</artifactId>
  <version>1.0.0</version>
</dependency>

Default Transport

can-socketcan

Supported Transports

  • can-socketcan
  • can-virtualcan

Config options:

node-id

INT

Node id of the target device.

request-timeout-ms

INT

1000

Default timeout for all types of requests.

Transport config options:

can-socketcan

can-socketcan.interface-name

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.

can-socketcan.reuse-interface

BOOLEAN

false

Share CAN socket across multiple transport instances on the same interface

can-socketcan.read-timeout-ms

INT

1000

Read timeout in milliseconds for blocking reads on the CAN socket

can-socketcan.filter-ids

STRING

Comma-separated list of accepted CAN IDs (decimal or 0x hex). Empty means accept all.

can-socketcan.filter-range-start

INT

-1

Start of accepted CAN ID range (inclusive). -1 means no range filtering.

can-socketcan.filter-range-end

INT

-1

End of accepted CAN ID range (inclusive). -1 means no range filtering.

can-virtualcan

can-virtualcan.bus-name

STRING

default

Name of the virtual CAN bus. Instances on the same bus exchange frames in-memory.

can-virtualcan.filter-ids

STRING

Comma-separated list of accepted CAN IDs (decimal or 0x hex). Empty means accept all.

can-virtualcan.filter-range-start

INT

-1

Start of accepted CAN ID range (inclusive). -1 means no range filtering.

can-virtualcan.filter-range-end

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 TypeLength (in bits)PLC4X Type
BOOLEAN1BOOL
UNSIGNED88USINT
UNSIGNED1616UINT
UNSIGNED2424UDINT
UNSIGNED3232UDINT
UNSIGNED4040ULINT
UNSIGNED4848ULINT
UNSIGNED5656ULINT
UNSIGNED6464ULINT
INTEGER88SINT
INTEGER1616INT
INTEGER2424DINT
INTEGER3232DINT
INTEGER4040LINT
INTEGER4848LINT
INTEGER5656LINT
INTEGER6464LINT
REAL3232REAL
REAL6464LREAL

This type table is similar to CANopen’s. The main difference is the lack of support for string types.

Examples

200:BYTE
200:BYTE[8]

More Information

  • CAN Bus - the shared transport and frame model used by this driver.
  • CANopen - the driver to use for devices that follow the CANopen application layer instead of raw frames.

评论

登录后参与评论

正在加载评论…