# Connect CANopen devices

> Run eaxPLC as the CANopen master of a CAN bus (SocketCAN on Linux, an SLCAN adapter on Windows or Linux), import the nodes' EDS, DCF, XDD or XDC files, configure PDOs and boot SDOs, and map the process data to %I and %Q.

Product: eaxPLC · Type: How-to guide · Editions: Free, Pro
Source: https://eaxware.com/docs/eaxplc/how-to/connect-canopen-devices/
Status: migrated page, not yet verified against the current code.

## Goal

eaxPLC is the CANopen master of a CAN bus: it starts every node, exchanges
its process data (PDOs) with the PLC's `%I` and `%Q` areas in every scan,
supervises the nodes and reports their emergencies. You configure the bus
and its nodes in the Studio's **Fieldbus** view, from the nodes' own device
description files.

## Before you start

- **The CAN port.** One of:
  - **SocketCAN** (Linux): a CAN interface of the system, for example
    `can0`. Set its bit rate in the system first:
    `ip link set can0 type can bitrate 500000` then `ip link set up can0`.
  - **An SLCAN adapter** (Windows and Linux): a USB-CAN adapter that speaks
    the SLCAN serial protocol, on its serial port (`slcan:COM5`,
    `slcan:/dev/ttyACM0`), or behind a serial device server in raw TCP mode
    (`slcan:tcp://192.168.1.50:4001`). eaxPLC sets the adapter's bit rate.
- **The nodes' device files**, as their makers publish them: EDS or DCF
  (CiA 306), XDD or XDC (CiA 311).
- The bus is terminated (120 Ω at both ends), every node has its own node
  ID, and all run at the bus's bit rate.
- You are signed in as an engineer: applying a fieldbus configuration needs
  your e-signature, because it drives real outputs.
- CANopen masters count like EtherNet/IP scanners and EtherCAT masters in
  the edition's allowance of fieldbus masters (eaxPLC Free: none,
  Standard: one, Performance: all).

## Add the bus

1. Open **Fieldbus** and click **+ CANopen**.
2. Set:
   - **CAN port**: `can0`, `slcan:COM5`, `slcan:tcp://host:port`, or `sim:`
     (virtual nodes, see below);
   - **Bit rate**: 10 000 to 1 000 000 bit/s (default 500 000);
   - **SYNC period**: how often the master sends the RPDOs and then SYNC
     (default 10 000 µs);
   - **Master node ID** (optional): when set, no node may use it and the
     master produces its own heartbeat every **Master heartbeat** ms, so that
     the nodes can supervise the master (see *Outputs*).
3. Select the bus: the **Nodes** table lists its nodes with their state,
   NMT state, heartbeat age and last emergency, updated live.

## Add a node from its device file

1. Select the bus (a new node) or an existing node, and click
   **Device file**.
2. Choose the node's EDS, DCF, XDD or XDC file and click **Read the file**.
   The PLC recognises the format from the content and shows what it read:
   the identity (vendor, product, revision), how the identity is checked,
   the PDOs, the objects, and the fields it fills.
3. Click **Use for ...** (or **Add the device**). The file fills the node's
   empty fields only:
   - the **vendor ID** and **product code** (checked at every boot);
   - from a DCF or XDC: the **node ID**, the **heartbeat time**, the
     configured **PDOs**, and the configured values that differ from their
     default as **boot SDOs**;
   - from an EDS or XDD: the device's **default PDO mapping**.
4. With **Add the I/O entries the file describes**, one I/O entry per mapped
   object is added on free `%I` / `%Q` addresses.

A file that is not a device description, or that is damaged, is refused
with the line of the problem, and nothing changes. Files with a DTD or
entity declarations are refused: a device file never needs one, and the
PLC never fetches or runs anything a file names. Files are limited to 2 MiB.

To keep the configuration of a node as a file, select it and click **DCF**:
the PLC writes a CiA 306 DCF with the node ID, the bit rate, the PDOs, the
heartbeat time and the boot SDOs.

The same **Device file** button imports an EtherCAT ESI on an EtherCAT bus,
an EtherNet/IP EDS on an EtherNet/IP bus, and a register map (CSV or JSON)
on a Modbus TCP bus.

## Configure the PDOs

Select the node and open the **PDOs** tab.

- **+ TPDO** adds a PDO the node sends (its data goes to `%I`); **+ RPDO**
  one it receives (its data comes from `%Q`).
- **COB-ID**: empty uses the predefined connection set (TPDO 1 to 4:
  0x180, 0x280, 0x380, 0x480 + node ID; RPDO 1 to 4: 0x200 to 0x500 + node
  ID). PDO 5 and above need a COB-ID. Every COB-ID on a bus has one
  producer: two PDOs with the same COB-ID are refused.
- **Transmission**: 0 acyclic synchronous, 1 to 240 every n-th SYNC, 254 or
  255 event-driven. An event-driven TPDO may also have an **event timer**.
- **Mapping**: select a PDO, then **+ Object** picks a mappable object of
  the device file's object dictionary (readable objects for a TPDO,
  writable ones for an RPDO), or **+ Entry** maps one by index, sub-index
  and length. A PDO carries at most 64 bits.
- **Device defaults** puts back the device file's default mapping.
- **I/O entries** adds one I/O entry per mapped object.

At every boot the master writes this configuration to the node in the
order CiA 301 requires: the PDO made invalid, its transmission type, the
mapping count set to 0, the mapped objects, the count, the PDO made valid.
The predefined PDOs 1 to 4 the configuration does not use are made invalid
first, so that the node sends and receives only what is configured.

## Boot SDOs

The **Boot SDOs** tab lists the SDO writes of the node's boot sequence, in
order: index, sub-index, data type and value (decimal or `0x` hex;
`OCTET_STRING` in hex bytes). **+ Parameter** picks a writable parameter of
the device file. PDO parameters (0x1400 to 0x1BFF), the heartbeat time
(0x1017) and the identity (0x1018) are set elsewhere and are refused here.

A typical boot SDO makes the node supervise the master: object 0x1016
sub-index 1, `UNSIGNED32`, value `0x007F01F4` (master node 127, 500 ms).

## Map the process data

The node's input data is its TPDOs one after the other, in the order of the
PDO table, each taking whole bytes; the output data is its RPDOs the same
way. In the **I/O mapping** tab, each entry has a byte offset (and a bit,
for BOOL) in that data, a type and a PLC address; the **PDO** column shows
the PDO and COB-ID carrying it. In the I/O map (**Find references and the
I/O map**), each CANopen point carries its node ID, PDO and COB-ID.

Click **Validate**, then **Apply** (with your e-signature).

A change to any node of a CANopen bus restarts that whole bus (the master
boots its nodes again); other buses keep running. **Last Apply** in the
status line says what was restarted. See [Apply fieldbus changes without
stopping the other devices](/docs/eaxplc/how-to/apply-fieldbus-changes/).

## What happens when the configuration runs

**Diagram: A CANopen node: boot, then SYNC cycles** (sequence)

The eaxPLC CANopen master boots each node on its own. It resets the node's communication and waits for the boot-up message, reads the identity and stops there when it differs from the configuration, writes the PDO configuration, the boot SDOs and the heartbeat time, and starts the node. Then, every SYNC period, it sends the RPDOs from the outputs and SYNC, and the node's TPDOs land in the inputs. A node that stops sending its heartbeat is a fault and is booted again from the start when it is heard again.

**Participants**

- **Process image** (data store)
- **Master** (product)
- **Node** (device or controller)

**Steps, in order**

1. **Master → Node** (command to equipment): NMT reset communication
2. **Node → Master** (data or telemetry): Boot-up message. within the boot-up wait, 5 s by default
3. **Master → Node** (data or telemetry): SDO read of the identity, 0x1018. vendor, product, revision when set
4. The identity differs:
   1. **Master**: Never started: the node stays pre-operational; its status shows the difference
5. The identity matches:
   1. **Master → Node** (configuration or deploy): SDO writes. PDO configuration, boot SDOs, heartbeat time 0x1017
   2. **Master → Node** (command to equipment): NMT start. by default held back while the PLC is stopped
6. Every SYNC period:
   1. **Process image → Master** (data or telemetry): Outputs from %Q
   2. **Master → Node** (command to equipment): RPDOs, then SYNC
   3. **Node → Master** (data or telemetry): TPDOs. synchronous or event-driven
   4. **Master → Process image** (data or telemetry): Inputs into %I
7. No heartbeat within the timeout:
   1. **Master**: Node fault: inputs zeroed or held; booted again from 1 when heard

A node whose identity differs is never started. A failed boot step is shown on the node and the boot is tried again.

For every node, independently (a node that does not answer does not hold
up the others):

1. NMT *reset communication*, then the node's boot-up message (within
   **Boot-up wait**, default 5 s).
2. The identity is read (0x1018). A node with another vendor, product (or
   revision, when set) is **never started**: it stays pre-operational and
   its status shows the difference.
3. The PDO configuration, the boot SDOs, the heartbeat time (0x1017).
4. NMT *start*.

Then, every SYNC period, the master sends the RPDOs from `%Q` and then
SYNC; the TPDOs land in `%I` as they arrive, synchronous or event-driven.

The `%I` inputs a node's TPDOs drive cannot be written from outside the
PLC (HTTP, OPC UA, Modbus TCP, UNS or MQTT commands): such a write is
refused with `IO_INPUT_DRIVEN`, even while the node is disabled or
faulted. A force on such an input is still accepted, and it overrides the
node. See [Constants, outside writes and forces](/docs/eaxplc/reference/constants-writes-and-forces/#refusals-per-path).

## Supervision

- **Heartbeat**: a node that sends no heartbeat for its **heartbeat
  timeout** (default 3 × its heartbeat time) is lost: its status turns to
  fault, its inputs are zeroed (or held, with **Inputs on fault** set to
  hold) and its status bit is cleared; a PDO that still arrives from it is
  not used. When the node is heard again, the master boots it again from
  step 1.
- **Emergencies**: the node's last EMCY (error code, its meaning, error
  register) shows in its diagnostics card and in the Nodes table, and every
  EMCY goes to the PLC's log.

## Outputs when the PLC is not running

- **Outputs on PLC stop** = **preop** (the default): the master sends the
  node to *pre-operational* and sends it no RPDO; the node applies its own
  behaviour for a lost communication. When the PLC runs again, the master
  starts it again.
- **zero**: the node stays operational and receives RPDOs full of zeros.
- When the master stops (a new configuration applied, a download, the
  runtime stopping), every node is sent NMT *stop*.

A node keeps its last outputs if the master disappears without a word (a
cable pulled, the PLC's power lost). Give each node a heartbeat consumer of
the master (boot SDO on 0x1016 and a **Master node ID**) and set its own
reaction to a lost master.

## Virtual nodes

With **CAN port** `sim:`, the runtime simulates the configured nodes (their
identity, the objects their PDOs and boot SDOs name) on an internal bus:
the whole boot sequence, the PDO exchange and the diagnostics run without
hardware, and nothing is opened on any port. Simulated PLCs (eaxSim) never
start a fieldbus at all.

## Troubleshooting

| Status | Meaning | What to do |
|---|---|---|
| `no boot-up message within ... ms` | The node did not answer the NMT reset. | Power, cable, termination; the node ID and the bit rate. |
| `identity mismatch: product ..., configured ...` | Another device answers at this node ID. | Fix the node ID, or import the right device file. |
| `PDO configuration, writing 0x1A00:1 ...: SDO abort` | The node refused a mapping. | Check the object can be mapped in that direction, and the PDO length (64 bits). |
| `node ... lost: no heartbeat` | The node stopped sending its heartbeat. | Cable, power; the heartbeat timeout against the heartbeat time. |
| `the CAN port does not send` | The adapter is unplugged, or the bus is off. | Reconnect the adapter; check termination and bit rate. |
| `serial port COM...: ...` | The SLCAN adapter's port does not exist. | The port name in **CAN port**. |
