CoE - CANopen protocol
CoE is the most widely used application-layer protocol in EtherCAT. It ports the CANopen object dictionary and communication mechanisms to EtherCAT.
Protocol introduction
Official description:
- Scope: I/O components, drives, encoders, proportional valves, hydraulic controllers, and more
- Compatible mechanisms: object dictionary, PDO, SDO, network management
- Firmware reuse: most CANopen firmware can be reused
- Extensibility: optional extension objects that make use of EtherCAT bandwidth
Applicable devices
- Digital and analog I/O modules
- Servo drives (CiA 402)
- Stepper motor controllers
- Encoders
- Sensors
- Variable-frequency drives
- Proportional valves
- Hydraulic controllers
Core concepts
Object dictionary
The object dictionary is the core of CoE. It is addressed with a 16-bit index plus an 8-bit subindex:
- 0x0000 — reserved
- 0x0001 - 0x0FFF — data type definitions (UNSIGNED8, INTEGER16, etc.)
- 0x1000 - 0x1FFF — communication parameters (device type, Sync Manager configuration)
- 0x2000 - 0x5FFF — manufacturer-specific parameters (device-proprietary functions)
- 0x6000 - 0x9FFF — standardized device profiles (CiA 401, CiA 402, etc.)
- 0xA000 - 0xFFFF — reserved
Common communication objects
| Index | Name | Type | Access | Description |
|---|---|---|---|---|
| 0x1000 | Device Type | UNSIGNED32 | RO | Device type identifier |
| 0x1001 | Error Register | UNSIGNED8 | RO | Error register |
| 0x1008 | Manufacturer Device Name | STRING | RO | Device name |
| 0x1009 | Hardware Version | STRING | RO | Hardware version |
| 0x100A | Software Version | STRING | RO | Software version |
| 0x1018 | Identity Object | RECORD | RO | Identity information (VendorID, ProductCode, etc.) |
| 0x1C00 | Sync Manager Type | ARRAY | RO | SM type configuration |
| 0x1C10-1C13 | SM PDO Assign | ARRAY | RW | SM PDO assignment |
| 0x1C32-1C33 | SM Synchronization | RECORD | RW | SM synchronization configuration |
SDO communication services
SDO (Service Data Object) is used for acyclic parameter access and is carried over mailbox communication.
SDO characteristics
- Non-real-time communication: transferred through the mailbox, so it does not consume a PDO cycle
- Full access: any object in the object dictionary can be read or written
- Segmented transfer: large data blocks are supported
Code example
var coe = slave.CoE;
if (coe == null) return; // The device has no CoE mailbox
// Read the device name: a failed read returns null, which is not the same as "the device name is an empty string"
byte[]? name = coe.SDORead(0x1008, 0);
if (name == null)
{
LogManager.Instance.AddLog(LogCategory.Error, $"从站 {slave.SlaveNum} 读 0x1008 失败"); // Slave {slave.SlaveNum} failed to read 0x1008
return;
}
string deviceName = Encoding.ASCII.GetString(name);
Console.WriteLine($"设备名称: {deviceName}"); // Device name: {deviceName}
// Read the Identity Object (Complete Access only allows subindex 0 or 1)
byte[]? identity = coe.SDORead(0x1018, 0, completeAccess: true);
if (identity != null)
Console.WriteLine($"Identity: {identity.Length} 字节"); // Identity: {identity.Length} bytes
// Write a parameter: returning false means a slave abort or a mailbox failure, not success
if (!coe.SDOWrite(0x6060, 0, new byte[] { 8 })) // Set the mode of operation to CSP
LogManager.Instance.AddLog(LogCategory.Error, $"从站 {slave.SlaveNum} 写 0x6060 失败"); // Slave {slave.SlaveNum} failed to write 0x6060
// Complete Access mode read (the whole object from subindex 0)
byte[]? pdoMapping = coe.SDORead(0x1600, 0, completeAccess: true);
if (pdoMapping != null)
Console.WriteLine($"0x1600 映射: {pdoMapping.Length} 字节"); // 0x1600 mapping: {pdoMapping.Length} bytes
SDO access types
- Normal Access — accesses a single subindex; use it to read or write one parameter
- Complete Access — accesses the whole object in one request; use it for arrays and records
PDO mapping
PDO (Process Data Object) is used for cyclic real-time data exchange and is mapped directly into the logical address space.
PDO types
- RxPDO (Receive PDO): master → slave (output data)
- TxPDO (Transmit PDO): slave → master (input data)
PDO mapping objects
- 0x1600 - 0x17FF — RxPDO Mapping — defines the output data mapping
- 0x1A00 - 0x1BFF — TxPDO Mapping — defines the input data mapping
PDO mapping structure
Each PDO mapping object contains several subindices:
0x1600 - RxPDO Mapping 1
├── 0x00: number of mapped objects (SubIndex 0)
├── 0x01: the 1st mapped object (Index:SubIndex:BitLength)
├── 0x02: the 2nd mapped object
└── ...
Mapping object format (32 bits):
- Bit 31-16: object index (Index)
- Bit 15-8: subindex (SubIndex)
- Bit 7-0: bit length (Bit Length)
Example: servo drive PDO mapping
The following example uses the PDO configuration of a real servo drive (Ezi-SERVO2 EtherCAT):
RxPDO (0x1600) — master to servo (4 mapping objects, 96 bits = 12 bytes in total)
| Subindex | Name | Object address | Bit length |
|---|---|---|---|
| 0x1600:01 | Control word | 0x6040:00 | 16 bits |
| 0x1600:02 | Target position | 0x607A:00 | 32 bits |
| 0x1600:03 | Physical output | 0x60FE:01 | 32 bits |
| 0x1600:04 | Touch probe function | 0x60B8:00 | 16 bits |
TxPDO (0x1A00) — servo to master (7 mapping objects, 176 bits = 22 bytes in total)
| Subindex | Name | Object address | Bit length |
|---|---|---|---|
| 0x1A00:01 | Status word | 0x6041:00 | 16 bits |
| 0x1A00:02 | Actual position | 0x6064:00 | 32 bits |
| 0x1A00:03 | Digital inputs | 0x60FD:00 | 32 bits |
| 0x1A00:04 | Error code | 0x603F:00 | 16 bits |
| 0x1A00:05 | Touch probe status | 0x60B9:00 | 16 bits |
| 0x1A00:06 | Touch probe position 1 | 0x60BA:00 | 32 bits |
| 0x1A00:07 | Touch probe position 2 | 0x60BC:00 | 32 bits |
PDO assignment configuration:
| Object index | Description | Configuration |
|---|---|---|
| 0x1C12 (RxPDO Assignment) | SM2 output mapping | 1 PDO: 0x1600 |
| 0x1C13 (TxPDO Assignment) | SM3 input mapping | 1 PDO: 0x1A00 |
Code example
// Read the TxPDO mapping (whole object, Complete Access)
byte[]? txPdoMap = slave.CoE?.SDORead(0x1A00, 0, completeAccess: true);
if (txPdoMap != null)
Console.WriteLine($"0x1A00 映射: {txPdoMap.Length} 字节"); // 0x1A00 mapping: {txPdoMap.Length} bytes
// Access PDO data (through the SDK)
// Inputs is a read-only whole-frame snapshot; Outputs is a whole-frame setter and the array length must equal slave.Obytes,
// Otherwise throw InvalidOperationException (never silently truncate or pad).
byte[] outputs = slave.PDO.Outputs;
outputs[0] = 0x0F; // The exact byte offsets follow that slave's PDO mapping
slave.PDO.Outputs = outputs;
Sync Manager (SM)
The SM maps PDOs into physical memory areas:
| SM | Type | Direction | Default address | Purpose |
|---|---|---|---|---|
| SM0 | Mailbox | master to slave | 0x1000 | Mailbox Out (SDO, FoE, etc.) |
| SM1 | Mailbox | slave to master | 0x1080 | Mailbox In (SDO responses, etc.) |
| SM2 | Process Data | master to slave | 0x1100 | RxPDO (outputs) |
| SM3 | Process Data | slave to master | 0x1180 | TxPDO (inputs) |
Network management (NMT)
CoE supports CANopen network management functions:
NMT states
- Pre-Operational — configuration state, SDO access available
- Operational — running state, PDO communication active
- Stopped — stopped state
Object dictionary access methods
Through the SDK
// SDO path: a failed read returns null and a failed write returns false; both return values must be handled
var coe = slave.CoE;
if (coe == null) return;
byte[]? data = coe.SDORead(index, subindex);
if (data == null)
{
LogManager.Instance.AddLog(LogCategory.Error, $"从站 {slave.SlaveNum} 读 0x{index:X4}:{subindex:X2} 失败"); // Slave {slave.SlaveNum} failed to read 0x{index:X4}:{subindex:X2}
return;
}
if (!coe.SDOWrite(index, subindex, data))
LogManager.Instance.AddLog(LogCategory.Error, $"从站 {slave.SlaveNum} 写 0x{index:X4}:{subindex:X2} 失败"); // Slave {slave.SlaveNum} failed to write 0x{index:X4}:{subindex:X2}
// PDO mode (real-time cyclic data)
byte[] inputs = slave.PDO.Inputs; // Whole input frame snapshot
slave.PDO.Outputs = outputs; // The output must be a whole frame with length == slave.Obytes
Access rules
- RO (Read Only) — read-only, for example the device type
- WO (Write Only) — write-only, for example some commands
- RW (Read/Write) — readable and writable, for example configuration parameters
- RWW — readable and writable; writing requires the PREOP state
- RXPDO — can be mapped through an RxPDO
- TXPDO — can be mapped through a TxPDO
Complete Access mode
Complete Access reads or writes a whole object (array or record type) in one request:
var coe = slave.CoE;
if (coe == null) return;
// Read the complete PDO mapping
byte[]? mapping = coe.SDORead(0x1600, 0, completeAccess: true);
if (mapping == null)
{
LogManager.Instance.AddLog(LogCategory.Error, $"从站 {slave.SlaveNum} 读 0x1600 整对象失败"); // Slave {slave.SlaveNum} failed to read the whole 0x1600 object
return;
}
// Write the complete PDO mapping: mappingData must be the whole-object bytes matching the read-back length
if (!coe.SDOWrite(0x1600, 0, mappingData, completeAccess: true))
LogManager.Instance.AddLog(LogCategory.Error, $"从站 {slave.SlaveNum} 写 0x1600 整对象失败"); // Slave {slave.SlaveNum} failed to write the whole 0x1600 object
Advantages:
- Atomic operation, so the data stays consistent
- Fewer communication round trips
- Suited to array and record types
Application examples
Read device information
var coe = slave.CoE;
if (coe == null) return;
// Read the device type (UNSIGNED32, 4 bytes)
byte[]? typeData = coe.SDORead(0x1000, 0);
if (typeData == null || typeData.Length < 4)
{
LogManager.Instance.AddLog(LogCategory.Error, $"从站 {slave.SlaveNum} 读 0x1000 失败"); // Slave {slave.SlaveNum} failed to read 0x1000
return;
}
uint deviceType = BitConverter.ToUInt32(typeData, 0);
// Read the device name
byte[]? nameData = coe.SDORead(0x1008, 0);
string deviceName = nameData == null ? "(读取失败)" : Encoding.ASCII.GetString(nameData); // (read failed)
// Read the version information
byte[]? hwVersion = coe.SDORead(0x1009, 0);
byte[]? swVersion = coe.SDORead(0x100A, 0);
Console.WriteLine($"设备: {deviceName}"); // Device: {deviceName}
Console.WriteLine($"类型: 0x{deviceType:X8}"); // Type: 0x{deviceType:X8}
Console.WriteLine($"硬件版本: {(hwVersion == null ? "(读取失败)" : Encoding.ASCII.GetString(hwVersion))}"); // Hardware version: {(hwVersion == null ?
Console.WriteLine($"软件版本: {(swVersion == null ? "(读取失败)" : Encoding.ASCII.GetString(swVersion))}"); // Software version: {(swVersion == null ?
Configure the PDO mapping
var coe = slave.CoE;
if (coe == null) return;
// 1. PDO mapping must be changed in PreOp: writing SafeOp / OP in 0x1C12 / 0x1C13 is rejected by the slave
if (!master.SetState(EcState.PreOp, out string preOpError))
{
LogManager.Instance.AddLog(LogCategory.Error, $"进 PreOp 失败: {preOpError}"); // Failed to enter PreOp: {preOpError}
return;
}
// 2. Release only the SM assignment you are changing (here SM2 / 0x1C12).
// Do not casually clear 0x1C13 (TxPDO) to 0 - clearing it without writing it back leaves the slave with no input process data.
if (!coe.SDOWrite(0x1C12, 0, new byte[] { 0 })) // SM2 PDO Assign
{
LogManager.Instance.AddLog(LogCategory.Error, "解除 0x1C12 分配失败"); // Failed to clear the 0x1C12 assignment
return;
}
// 3. Configure the new mapping: write the entry count as 0 first, write the entries one by one, then write the entry count back
// RxPDO: 0x6040 (control word, 16 bit) -> mapped value 0x60400010
coe.SDOWrite(0x1600, 0, new byte[] { 0 }); // Clear the entries
coe.SDOWrite(0x1600, 1, BitConverter.GetBytes(0x60400010)); // 0x6040:00, 16 bits
coe.SDOWrite(0x1600, 0, new byte[] { 1 }); // Entry count = 1
// 4. Assign 0x1600 to SM2
coe.SDOWrite(0x1C12, 1, BitConverter.GetBytes((ushort)0x1600));
coe.SDOWrite(0x1C12, 0, new byte[] { 1 });
// 5. Continue to OP: SetState walks INIT→PREOP→SAFEOP→OP internally
if (!master.SetState(EcState.OP, out string opError))
LogManager.Instance.AddLog(LogCategory.Error, $"进 OP 失败: {opError}"); // Failed to enter OP: {opError}
If you also need to change 0x1A00 (TxPDO), follow the same order: 0x1C13:00 = 0 → 0x1A00:00 = 0 → write 0x1A00:01..n
→ 0x1A00:00 = n → 0x1C13:01 = 0x1A00 → 0x1C13:00 = 1. The number of mapping entries and their order must match
the field order of the structure on the master side, otherwise the bytes you read back are misaligned.
Comparison with other protocols
| Feature | CoE | SoE | EoE |
|---|---|---|---|
| Origin | CANopen | SERCOS | Ethernet |
| Real-time capability | High | Very high | Medium |
| Complexity | Medium | High | Low |
| Application | General purpose | High-end motion control | Network devices |
| Device support | Most widespread | High-end devices | Network devices |