Master object dictionary (Master OD)
A master object dictionary that follows ETG.1510, exposing master identity plus slave configuration, state and diagnostic data to external diagnostic tools and HMI over the standard SDO interface.
The master object dictionary is implemented to the ETG.1510 specification. Together with the mailbox gateway, it gives remote diagnostic tools standard access to the master.
Object index overview
| Index | Name | Category | Subindexes | Read/write | Description |
|---|---|---|---|---|---|
| 0x1000 | Device Type | Identity | 0 | Read-only | 0x00001389 (EtherCAT Master) |
| 0x1008 | Device Name | Identity | 0 | Read-only | "Darra EtherCAT Master" |
| 0x1009 | Hardware Version | Identity | 0 | Read-only | x64 |
| 0x100A | Software Version | Identity | 0 | Read-only | SDK version |
| 0x1018 | Identity Object | Identity | 4 | Read-only | Master identity |
| 0x8nnn | Configuration Data | Configuration | 40 | Read-only | Configuration data of slave n |
| 0x9nnn | Information Data | Information | 32 | Read-only | Detected information of slave n |
| 0xAnnn | Diagnosis Data | Diagnosis | 19 | Partially writable | Diagnostic data of slave n |
| 0xF002 | Detect Modules | Diagnosis | 3 | Read-only | Slave scan status |
| 0xF120 | Master Diag Data | Diagnosis | 16 | Read-only | Master diagnostic data |
| 0xF200 | Diag Interface Control | Control | 16 | Writable | Diagnostic interface control |
nnn = slave index (1-based); the indexes are generated dynamically from the slave count.
MasterObjectDictionary
namespace darra::ethercat {
class MasterObjectDictionary {
public:
MasterObjectDictionary(dll_t& dll, uint16_t master);
std::optional<ec_master_identity_t> master_identity();
std::optional<ec_master_diag_data_t> master_diag_data();
uint16_t ALStatusCode(uint16_t slaveIndex);
int16_t SlaveLinkQuality(uint16_t slaveIndex);
uint32_t PdoLostFrames(uint8_t group = 0);
uint32_t PdoConsecutiveLost(uint8_t group = 0);
uint32_t PdoMaxConsecutiveLost(uint8_t group = 0);
};
}
Construct it directly:
MasterObjectDictionary od(dll, master.MasterNumber());
master_identity()
std::optional<ec_master_identity_t> master_identity();
Reads the master identity (ETG.1510 0x1018). Fields of the returned ec_master_identity_t:
VendorId— vendor IDProductCode— product codeRevisionNo— revision numberSerialNo— serial numberDeviceName— device nameHwVersion— hardware versionSwVersion— software version
master_diag_data()
std::optional<ec_master_diag_data_t> master_diag_data();
Reads the master diagnostic data (ETG.1510 0xF120) and returns the whole structure in one call; the fields map one-to-one onto the ETG.1510 subindexes:
CyclicLostFrames— cumulative cyclic lost-frame count (the raw lost-frame counter, not a percentage)AcyclicLostFrames— acyclic lost-frame count (the current implementation always returns 0; cyclic and acyclic lost frames are not distinguished yet)CyclicFramesPerSec— cyclic frames per secondAcyclicFramesPerSec— acyclic frames per second (the current implementation always returns 0)MasterState— current EtherCAT state of the master
ALStatusCode()
uint16_t ALStatusCode(uint16_t slaveIndex);
Reads the slave AL Status Code (ETG.1510 0xAnnn:1).
MasterObjectDictionary only wraps the master's own objects and the slave fields listed on this page, and does not provide read methods for those three subindex groups. When you need these three quantities, get them from the direct-call entry points that the C header provides:
- 0x8nnn:35 Link Status (1 byte) — bit0 = the current-tick lost verdict (not a sticky latched lost marker); bit(4+p) = port p currently has a link (p = 0..3); the remaining bits are always 0.
- 0x8nnn:36 Link Preset (1 byte) — low nibble = mask of the ports expected to have a link (bit0..3 = P0..P3), high nibble = the same mask shifted left by 4 (N ports → 0x11 / 0x33 / 0x77 / 0xFF); the input is the measured active port mask of the current tick, not the link count from configuration time.
- 0xAnnn:06..09 — one fixed u16 address per port.
addrs[0]= the upstream parent,addrs[1..3]= the downstream children; the caller allocates ≥ 4 ints, and the lower layer does not check the capacity.
Unified return contract: 0 = success (outputs written); -1 = bad parameter; -2 = not ready. When -1 / -2 is returned, not a single byte of output is written. 0 is a definite value ("no connected slave reported") and does not mean "definitely nothing connected"; for a tri-state you must combine it with ParentPort().
Also note: 0xAnnn:04 is Link Conn. Status (two bits of connectivity per port), not "which port of the parent this station is attached to". The only answer to which port this station is attached to is ParentPort(): 0..3 = port, -1 = connected directly to the master / not applicable.
SlaveLinkQuality()
int16_t SlaveLinkQuality(uint16_t slaveIndex);
Reads the slave link quality as a percentage (100 = perfect, -1 = unknown).
PdoLostFrames() / PdoConsecutiveLost() / PdoMaxConsecutiveLost()
uint32_t PdoLostFrames(uint8_t group = 0);
uint32_t PdoConsecutiveLost(uint8_t group = 0);
uint32_t PdoMaxConsecutiveLost(uint8_t group = 0);
PDO frame-loss statistics: cumulative lost frames / current consecutive lost frames / historical maximum consecutive lost frames (per group).
Full example
#include "ethercat.hpp"
using namespace darra::ethercat;
void dump_master_od(EtherCATMaster& master) {
MasterObjectDictionary od(master.Dll(), master.MasterNumber());
// Master identity
auto identity = od.master_identity();
if (identity) {
printf("VendorId: 0x%08X\n", identity->VendorId);
printf("设备名称: %s\n", identity->DeviceName); // Device name: %s
printf("软件版本: %s\n", identity->SwVersion); // Software version: %s
}
// Master diagnostics
auto diag = od.master_diag_data();
if (diag) {
printf("周期帧频率: %u Hz\n", diag->CyclicFramesPerSec); // Cyclic frame rate: %u Hz
printf("周期帧丢失计数: %u\n", diag->CyclicLostFrames); // Cyclic frames lost: %u
printf("主站状态: 0x%04X\n", diag->MasterState); // Master state: 0x%04X
}
// Slave diagnostics
for (uint16_t i = 1; i <= master.SlaveCount(); ++i) {
printf("从站%d: AL_Code=0x%04X, LinkQuality=%d\n", // Slave %d: AL_Code=0x%04X, LinkQuality=%d
i, od.ALStatusCode(i), od.SlaveLinkQuality(i));
}
// PDO frame loss statistics
for (uint8_t g = 0; g < 8; ++g) {
uint32_t total = od.PdoLostFrames(g);
if (total > 0) {
printf("组 %d: 累计=%u, 连续=%u, 最大连续=%u\n", // Group %d: total=%u, consecutive=%u, max consecutive=%u
g, total, od.PdoConsecutiveLost(g), od.PdoMaxConsecutiveLost(g));
}
}
}