Master object dictionary (Master OD)
A master object dictionary that follows ETG.1510, exposing master identity and diagnostic data. Together with the mailbox gateway, it gives remote diagnostic tools standard access to the master.
diagnostics_etg1510_read() implements only two fast paths: 0x1018 subindexes 1..4 and 0xF120 subindex 0; every other index returns -4 (no usable implementation).
The slave configuration / information / diagnosis objects (0x8nnn / 0x9nnn / 0xAnnn) have two read paths: ① take the equivalent fields with GetSlave() / GetSlaveDetailedInfo(); ② use the generic ETG.1510 OD read entry point (DarraEcat_Etg1510_ReadObject, no short-name wrapper; the declaration is in darra_ethercat_shell.h), which covers the standard subindexes of 0x8nnn / 0x9nnn / 0xAnnn (per-row availability is marked in the tables below).
The tables below describe the master object dictionary itself; with the mailbox gateway, an external CoE diagnostic tool can reach it in the standard way.
Object index overview
| Index | Name | Category | Subindexes | Read/write | Description |
|---|---|---|---|---|---|
| 0x1000 | Device Type | Standard object | 0 | Read-only | 0x00001389 (EtherCAT master) |
| 0x1008 | Device Name | Standard object | 0 | Read-only | "Darra EtherCAT Master" |
| 0x1009 | Hardware Version | Standard object | 0 | Read-only | The mailbox gateway and GetMasterIdentity return "1.0"; the generic ETG.1510 OD read entry point returns "x64" (64-bit) / "x86" (32-bit) — see Known difference below |
| 0x100A | Software Version | Standard object | 0 | Read-only | SDK version |
| 0x1018 | Identity Object | Standard object | 4 | Read-only | Master identity |
| 0x8nnn | Configuration Data | Slave configuration | 40 | Read-only | Configuration data of slave n (address, name, vendor, mailbox, and so on) |
| 0x9nnn | Information Data | Slave information | 32 | Read-only | Detected information of slave n (actual address, vendor ID, DL Status) |
| 0xAnnn | Diagnosis Data | Slave diagnosis | 19 | Partially writable | Diagnostic data of slave n (AL Status, error counters, link, and so on) |
| 0xF002 | Detect Modules | Detection command | 3 | Read-only | Slave scan status |
| 0xF120 | Master Diag Data | Master diagnosis | 16 | Read-only | Master diagnostic data (lost-frame count, frame rate, state) |
| 0xF200 | Diag Interface Control | Diagnostic control | 16 | Writable | Diagnostic interface control (reset diagnostic information) |
The index of slave n is the base address plus n (1-based): configuration 0x8000 | n, information 0x9000 | n, diagnosis 0xA000 | n. Slave 1, for example, is 0x8001 / 0x9001 / 0xA001.
0x1009 has two read paths and two return values: the mailbox gateway and GetMasterIdentity() return "1.0", while the generic ETG.1510 OD read entry point (no short-name wrapper; the declaration is in darra_ethercat_shell.h) returns "x64" (64-bit) / "x86" (32-bit). This records the current implementation as it is; a later version will unify them.
Identity Object (0x1018)
| Subindex | Name | Category | Type | Read/write | Description |
|---|---|---|---|---|---|
| 0x01 | Vendor ID | Standard object | uint32 | Read-only | Vendor ID |
| 0x02 | Product Code | Standard object | uint32 | Read-only | Product code |
| 0x03 | Revision Number | Standard object | uint32 | Read-only | Revision number |
| 0x04 | Serial Number | Standard object | uint32 | Read-only | Serial number |
Configuration Data (0x8nnn) — Slave configuration
The configuration data index of slave n is 0x8000 | n (n = 1..slave_count; the 1-based slave index lands directly in the low 12 bits). Slave 1, for example, is 0x8001 and slave 2 is 0x8002.
| Subindex | Name | Category | Type | Read/write | Description |
|---|---|---|---|---|---|
| 0x00 | Number of Entries | Slave configuration | byte | Read-only | Fixed at 40 |
| 0x01 | Fixed Station Address | Slave configuration | uint16 | Read-only | Configured address (ConfigAddr) |
| 0x02 | Type | Slave configuration | string | Read-only | Device type string (the C read path currently returns the same device name as 0x03) |
| 0x03 | Name | Slave configuration | string | Read-only | Device name |
| 0x04 | Device Type | Slave configuration | uint32 | Read-only | Device type code (always 0 at present; Dtype no longer has a real source) |
| 0x05 | Vendor ID | Slave configuration | uint32 | Read-only | Vendor ID |
| 0x06 | Product Code | Slave configuration | uint32 | Read-only | Product code |
| 0x07 | Revision Number | Slave configuration | uint32 | Read-only | Revision number |
| 0x08 | Serial Number | Slave configuration | uint32 | Read-only | Serial number |
| 0x21 | Mailbox Out Size | Slave configuration | uint16 | Read-only | SM0 mailbox output size |
| 0x22 | Mailbox In Size | Slave configuration | uint16 | Read-only | SM1 mailbox input size |
| 0x23 | Link Status | Slave configuration | byte | Read-only | 0x8nnn:35: bit0 = slave lost (the criterion is the live verdict for the current cycle, not a sticky latch); bit(4+p) = port p currently has a link (p=0..3); the remaining bits are always 0. All high bits 0 can also mean "this slave's link state was never sampled", so a 0 alone does not prove all four ports are down |
| 0x24 | Link Preset | Slave configuration | byte | Read-only | 0x8nnn:36: 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 linked ports → 0x11 / 0x33 / 0x77 / 0xFF. The input is the popcount of the ports active in the current cycle (200ms DLSTAT refresh), the same per-cycle sample as :35; it is not the link count from configuration time. 0 = no port is expected to have a link (also returned as 0 when the input is unknown) |
| 0x25 | Flags | Slave configuration | byte | Read-only | Bit3 reserved; currently 0 |
| 0x26 | Port Physics | Slave configuration | uint16 | Read-only | Port physical type |
| 0x27 | Mailbox Protocols | Slave configuration | uint16 | Read-only | Supported mailbox protocols (CoE=0x04, FoE=0x08, and so on) |
| 0x28 | Diag History Supported | Slave configuration | byte | Read-only | In the specification, "whether the 0x10F3 diagnostic history object is supported"; the C read path has no data source and returns -5 (subindex does not exist) |
Information Data (0x9nnn) — Slave detection information
Each slave has one 0x9nnn object holding the actual information detected at runtime.
The detection information index of slave n is 0x9000 | n (n = 1..slave_count; the 1-based slave index lands directly in the low 12 bits). Slave 1, for example, is 0x9001 and slave 2 is 0x9002.
| Subindex | Name | Category | Type | Read/write | Description |
|---|---|---|---|---|---|
| 0x00 | Number of Entries | Slave information | byte | Read-only | Fixed at 32 |
| 0x01 | Station Address | Slave information | uint16 | Read-only | Actual configured address |
| 0x05 | Vendor ID | Slave information | uint32 | Read-only | Detected vendor ID |
| 0x06 | Product Code | Slave information | uint32 | Read-only | Detected product code |
| 0x07 | Revision Number | Slave information | uint32 | Read-only | Detected revision number |
| 0x08 | Serial Number | Slave information | uint32 | Read-only | Detected serial number |
| 0x20 | DL Status | Slave information | uint16 | Read-only | DL Status register (ESC 0x0110-0x0111, read with a blocking register read); the mailbox gateway path does not provide this subindex |
Diagnosis Data (0xAnnn) — Slave diagnosis
Each slave has one 0xAnnn object holding live diagnostic data. It is updated automatically on every read.
The diagnostic data index of slave n is 0xA000 | n (n = 1..slave_count; the 1-based slave index lands directly in the low 12 bits). Slave 1, for example, is 0xA001 and slave 2 is 0xA002.
| Subindex | Name | Category | Type | Read/write | Description |
|---|---|---|---|---|---|
| 0x00 | Number of Entries | Slave diagnosis | byte | Read-only | Fixed at 19 |
| 0x01 | AL Status | Slave diagnosis | uint16 | Read-only | Current AL state |
| 0x02 | AL Control | Slave diagnosis | uint16 | Read/write | Written through to the slave (writes ESC 0x0120 and needs 2 bytes; the register can also be read) |
| 0x03 | Last AL Status Code | Slave diagnosis | uint16 | Read-only | Most recent AL error code (ESC 0x0134) |
| 0x04 | Link Conn. Status | Slave diagnosis | byte | Read-only | Link Conn. Status (the per-port link byte decoded from ESC 0x0110: bit(p) = port p has communication established, bit(4+p) = port p has a link, p = 0..3); it is not "which port of the parent this slave is attached to" — use GetSlaveParentPort for that |
| 0x05 | Link Control | Slave diagnosis | byte | Read-only | Link control (DL Control register 0x0101) |
| 0x06 | Fixed Addr Conn. Port 0 | Slave diagnosis | uint16 | Read-only | Configured address of the slave connected to port 0 (the upstream parent); 0 = this port reports no connected slave, which does not mean nothing is connected; to find which port of the parent this slave is attached to, use GetSlaveParentPort |
| 0x07 | Fixed Addr Conn. Port 1 | Slave diagnosis | uint16 | Read-only | Configured address of the slave connected to port 1 (a downstream child); 0 = this port reports no connected slave, which does not mean nothing is connected |
| 0x08 | Fixed Addr Conn. Port 2 | Slave diagnosis | uint16 | Read-only | Configured address of the slave connected to port 2 (a downstream child); 0 = this port reports no connected slave, which does not mean nothing is connected |
| 0x09 | Fixed Addr Conn. Port 3 | Slave diagnosis | uint16 | Read-only | Configured address of the slave connected to port 3 (a downstream child); 0 = this port reports no connected slave, which does not mean nothing is connected |
| 0x0A | Frame Error Port 0 | Slave diagnosis | uint32 | Read-only | Port 0 frame error count (reads ESC 0x0300, low byte zero-extended) |
| 0x0B | Frame Error Port 1 | Slave diagnosis | uint32 | Read-only | Port 1 frame error count (ESC 0x0302) |
| 0x0C | Frame Error Port 2 | Slave diagnosis | uint32 | Read-only | Port 2 frame error count (ESC 0x0304) |
| 0x0D | Frame Error Port 3 | Slave diagnosis | uint32 | Read-only | Port 3 frame error count (ESC 0x0306) |
| 0x0E | Cyclic WC Error Counter | Slave diagnosis | uint32 | Read-only | In the specification, "cyclic working counter errors"; the C read path has no data source and returns -5 (subindex does not exist) |
| 0x0F | Slave Not Present Counter | Slave diagnosis | uint32 | Read-only | In the specification, "count of slaves not present"; the C read path has no data source and returns -5 (subindex does not exist) |
| 0x10 | Abnormal State Change Counter | Slave diagnosis | uint32 | Read-only | In the specification, "count of abnormal state changes"; the C read path has no data source and returns -5 (subindex does not exist) |
| 0x11 | Disable Auto Link Control | Slave diagnosis | byte | Read-only | In the specification, "automatic link control disable flag"; the C read path has no data source and returns -5 (subindex does not exist) |
| 0x12 | Last CoE/SoE Protocol Error | Slave diagnosis | uint32 | Read-only | In the specification, "most recent CoE/SoE protocol error code"; the C read path has no data source and returns -5 (subindex does not exist) |
| 0x13 | New Diag Messages | Slave diagnosis | byte | Read-only | In the specification, "whether there are new diagnostic messages (0x10F3)"; the C read path has no data source and returns -5 (subindex does not exist) |
The table is marked with the actual coverage of the generic ETG.1510 OD read entry point (DarraEcat_Etg1510_ReadObject). The mailbox gateway (an external CoE tool) answers only part of it: 0x8nnn:0x28, 0x9nnn:0x20 and 0xAnnn:0x02 / 0x04 / 0x05 / 0x0A..0x13 return "subindex does not exist" on the gateway path.
Master identity
GetMasterIdentity()
BOOL GetMasterIdentity(uint16_t master_index, ec_master_identity_t* identity);
Gets the master identity information.
Parameters:
master_index(uint16_t) — master indexidentity(ec_master_identity_t*) — output identity information
Returns:
BOOL—TRUEon success
ec_master_identity_t
typedef struct {
uint32_t VendorId; /* Vendor ID */
uint32_t ProductCode; /* Product code */
uint32_t RevisionNo; /* Revision number */
uint32_t SerialNo; /* Serial number */
char DeviceName[64]; /* Device name */
char HwVersion[32]; /* Hardware version */
char SwVersion[32]; /* Software version */
} ec_master_identity_t;
Master diagnostic data (0xF120)
The C SDK wires the fast path only on subindex 0: when diagnostics_etg1510_read() reads 0xF120:00 it calls GetMasterDiagData(), which returns the whole ec_master_diag_data_t in one go (20 bytes = 4 × uint32 + uint16 + 2 bytes of alignment padding) rather than splitting it per subindex; every other subindex on that fast-path entry point has no usable implementation and returns -4. To read 0..4 and 16 subindex by subindex, use the generic ETG.1510 OD entry point (see above). How the struct fields map to the ETG.1510 subindexes:
| Offset | Field | Category | Type | Read/write | ETG.1510 subindex | Description |
|---|---|---|---|---|---|---|
| 0 | CyclicLostFrames | Master diagnosis | uint32 | Read-only | 01 | Cyclic lost-frame count (5-second sliding-window value, not a percentage) |
| 4 | AcyclicLostFrames | Master diagnosis | uint32 | Read-only | 02 | Acyclic lost-frame count (counted by timed-out frames, also a 5-second sliding-window value) |
| 8 | CyclicFramesPerSec | Master diagnosis | uint32 | Read-only | 03 | Cyclic frames per second |
| 12 | AcyclicFramesPerSec | Master diagnosis | uint32 | Read-only | 04 | Acyclic frames per second (this field is not filled at present; the reading is always 0) |
| 16 | MasterState | Master diagnosis | uint16 | Read-only | 16 | Current EtherCAT state of the master |
GetMasterDiagData()
BOOL GetMasterDiagData(uint16_t master_index, ec_master_diag_data_t* diag);
Gets the master diagnostic data (ETG.1510 0xF120).
Parameters:
master_index(uint16_t) — master indexdiag(ec_master_diag_data_t*) — output diagnostic data
Returns:
BOOL—TRUEon success
ec_master_diag_data_t
typedef struct {
uint32_t CyclicLostFrames; /* cyclic frame loss count (5-second sliding-window value) */
uint32_t AcyclicLostFrames; /* acyclic frame loss count (counted by timed-out frames, also a 5-second sliding-window value) */
uint32_t CyclicFramesPerSec; /* cyclic frames per second */
uint32_t AcyclicFramesPerSec; /* acyclic frames per second (this field is not filled at present; the reading is always 0) */
uint16_t MasterState; /* current master state */
} ec_master_diag_data_t;
0xF200 — Diagnostic interface control
| Subindex | Name | Category | Type | Read/write | Description |
|---|---|---|---|---|---|
| 0x00 | Number of Entries | Diagnostic control | byte | Read-only | Fixed at 16 |
| 0x10 | Reset Diag Info | Diagnostic control | byte | Writable | Writing 1 resets the diagnostic counters of all slaves and of the master (triggered on a rising edge) |
ETG.1510 index constants
Object index macros defined in master/diagnostics_ext.h:
| Macro | Value | Object |
|---|---|---|
| ETG1510_DEVICE_TYPE | 0x1000 | Device Type |
| ETG1510_DEVICE_NAME | 0x1008 | Manufacturer Device Name |
| ETG1510_HW_VERSION | 0x1009 | Hardware Version |
| ETG1510_SW_VERSION | 0x100A | Software Version |
| ETG1510_IDENTITY | 0x1018 | Identity Object |
| ETG1510_CONFIG_DATA_BASE | 0x8000 | Base address of the slave configuration data |
| ETG1510_INFO_DATA_BASE | 0x9000 | Base address of the slave information data |
| ETG1510_DIAG_DATA_BASE | 0xA000 | Base address of the slave diagnostic data |
| ETG1510_DETECT_MODULES | 0xF002 | Detect Modules Command |
| ETG1510_MASTER_DIAG_DATA | 0xF120 | Master Diag Data |
| ETG1510_DIAG_INTERFACE_CTRL | 0xF200 | Diag Interface Control |
Generic OD access
The functions below (declared in master/diagnostics_ext.h) forward only two fast paths: 0x1018 subindexes 1..4 route to GetMasterIdentity and 0xF120 subindex 0 routes to GetMasterDiagData. Every other index has no usable implementation in the C SDK: reads and writes return the matching failure code directly instead of being mixed up with "the slave did not answer / the index does not exist". These two SDK-level functions are called directly with the master index and need no context handle.
diagnostics_etg1510_read()
int diagnostics_etg1510_read(uint16_t master_index, uint16_t index, uint8_t subindex,
uint8_t* outBuf, int bufSize);
Reads a master object through the ETG.1510 OD (an SDO Upload wrapper).
Parameters:
master_index(uint16_t) — master indexindex(uint16_t) — OD index (0x1000-0xFFFF)subindex(uint8_t) — OD subindexoutBuf(uint8_t*) — output bufferbufSize(int) — buffer size
Returns:
int— the number of bytes actually written;-1= parameter error;-3= buffer too small;-4= no usable implementation for this index (every index except 0x1018:1..4 and 0xF120:0, including 0x1018:0)- 0x1018:1..4 fills in 4 bytes (uint32) each time; a buffer smaller than 4 bytes returns
-3 - 0xF120:0 copies the whole struct in one go (
ec_master_diag_data_t, 20 bytes under MSVC); a smaller buffer truncates tobufSizeand returns the number of bytes actually written
diagnostics_etg1510_write()
int diagnostics_etg1510_write(uint16_t master_index, uint16_t index, uint8_t subindex,
const uint8_t* data, int len);
Writes a master object through the ETG.1510 OD (an SDO Download wrapper). It is meant for the writable master objects such as 0xF200 Diag Interface Control and 0xF002 Detect Modules; this entry point goes through the master SDO route (slave index 0), which is currently rejected, so the call always returns -2. To reset the diagnostic counters or write AL Control, use the generic ETG.1510 OD entry point below.
Returns:
int—0success (no index reaches it at present);-1parameter error;-2SDO failure (request rejected / Abort / timeout);-4SDK unavailable (entry point not ready, nothing sent)
Example:
/* Read 0x1018:01 VendorId (fast path, 4 bytes) */
uint8_t buf[32] = {0};
int n = diagnostics_etg1510_read(mi, 0x1018, 0x01, buf, sizeof(buf));
if (n >= 4) {
uint32_t vendor = (uint32_t)buf[0] | ((uint32_t)buf[1] << 8)
| ((uint32_t)buf[2] << 16) | ((uint32_t)buf[3] << 24);
printf("VendorId: 0x%08X\n", vendor);
}
/* Read 0xF120:0 master diagnostics (fast path, whole struct) */
uint8_t diag[32] = {0};
int m = diagnostics_etg1510_read(mi, 0xF120, 0x00, diag, sizeof(diag));
printf("GetMasterDiagData 快路径写入 %d 字节\n", m); /* GetMasterDiagData fast path wrote %d bytes */
Generic ETG.1510 OD entry point
The generic read / write entry points covering the standard subindexes such as 0x8nnn / 0x9nnn / 0xAnnn; declared in darra_ethercat_shell.h (no short-name wrapper; call DarraEcat_Etg1510_* directly).
DarraEcat_Etg1510_ReadObject()
int DarraEcat_Etg1510_ReadObject(uint16_t master_index, uint16_t index, uint8_t subindex,
uint8_t* out_buf, int out_cap,
int* out_len, uint16_t* out_abort);
Reads a master object dictionary entry. The call needs no context handle; out_len / out_abort are cleared on entry.
Parameters:
master_index(uint16_t) — master indexindex(uint16_t) — object index (0x1000 / 0x8nnn / 0x9nnn / 0xAnnn / 0xF002 / 0xF120 / 0xF200)subindex(uint8_t) — subindexout_buf/out_cap— output buffer (must not be NULL) and its capacity in bytesout_len(int*) — may beNULL; on success it receives the number of bytes actually writtenout_abort(uint16_t*) — may beNULL; on failure it receives the CoE abort code (0 on success)
Returns:
int— >= 0 = number of bytes written; a negative value = error code:-1parameter error /-2invalid master index /-3not ready (master not initialized / shutting down)-4object does not exist (CoE abort 0x06020000) /-5subindex does not exist (0x06090011) /-6read-only (0x06010002)-7not supported by this entry point (0x06010000) /-8buffer too small /-9register or bus I/O failure (no valid answer)
Coverage — 0x1000 / 0x1008 / 0x1009 / 0x100A / 0x1018 (subindexes 0..4); 0x8nnn's 0..8, 33..39; 0x9nnn's 0, 1, 5..8, 32; 0xAnnn's 0..13; 0xF002's 0..3; 0xF120's 0..4, 16; 0xF200's 0, 16. Subindexes not listed return -5 (subindex does not exist); it does not return 0 to pass off a value.
DarraEcat_Etg1510_WriteObject()
int DarraEcat_Etg1510_WriteObject(uint16_t master_index, uint16_t index, uint8_t subindex,
const uint8_t* data, int len, uint16_t* out_abort);
Writes a master object dictionary entry. Only two writable entry points are supported:
0xF200:16— diagnostic reset level (data[0] & 1; a0→1rising edge triggers one diagnostic reset, and reading back returns this level)0xAnnn:2— AL Control (writes ESC register 0x0120; needs 2 bytes)
0xF002 (a scan at runtime would lose the configuration) and all other read-only indexes are always rejected.
Returns:
int—0success; a negative value = the same error code set asDarraEcat_Etg1510_ReadObject(-6read-only for 0xF002 and the other read-only objects,-9register write failure)
Example:
uint8_t buf[8];
int len = 0;
uint16_t abort = 0;
int rc = DarraEcat_Etg1510_ReadObject(mi, 0xA001, 0x01, buf, sizeof(buf), &len, &abort);
if (rc >= 0)
printf("从站 1 AL Status: 0x%04X\n", (uint16_t)(buf[0] | (buf[1] << 8))); /* Slave 1 AL Status: 0x%04X */
else
printf("读失败 rc=%d abort=0x%04X\n", rc, abort); /* Read failed rc=%d abort=0x%04X */
uint8_t one = 1;
DarraEcat_Etg1510_WriteObject(mi, 0xF200, 0x10, &one, 1, &abort); /* Reset the diagnostic counters */
AL status code classification
diagnostics_classify_al_error()
DarraAlErrorClass diagnostics_classify_al_error(uint16_t alStatusCode);
Classifies AL Status Codes per code into the 5 ETG.1020 error classes (none / transient / configuration / hardware / unknown), so a UI can group alarms for display. The single authority is the AL status table built into the runtime (status_codes.c in k_al_status_table[].recovery_class, implemented once by the runtime); the C SDK keeps no second classification table and does not bucket by the high-order segment. The per-code results match C++ / C# / Java / Python / Rust exactly.
Returns:
DarraAlErrorClass— the error class enumeration; returnsAL_ERR_UNKNOWNwhen the runtime is unavailable (neverAL_ERR_NONE)
Related structure:
typedef enum {
AL_ERR_NONE = 0, /* no error (0x0000) */
AL_ERR_TRANSIENT = 1, /* transient error */
AL_ERR_CONFIGURATION = 2, /* configuration error */
AL_ERR_HARDWARE = 3, /* hardware error */
AL_ERR_UNKNOWN = 4 /* unknown / unlisted / classification unavailable */
} DarraAlErrorClass;
Full example
#include "ethercat.h"
#include <stdio.h>
int main(void)
{
uint16_t master = Initialize();
if (master == 0 || master == (uint16_t)-1) return 1; /* returns (uint16_t)-1 on failure */
uint16_t slave_count = SetNetwork(master, "\\Device\\NPF_{...}", "");
if (slave_count == 0 || slave_count == (uint16_t)-1) { /* >0 = number of slaves found by the scan */
Dispose(master); return 1;
}
if (!SetStateSequence(master, EC_STATE_OPERATIONAL, 10000)) {
Dispose(master); return 1;
}
if (!Start(master)) {
Dispose(master); return 1;
}
/* ===== Read the master identity (0x1018) ===== */
ec_master_identity_t id;
if (GetMasterIdentity(master, &id)) {
printf("=== 主站信息 (0x1018) ===\n"); /* === Master information (0x1018) === */
printf("设备名称: %s\n", id.DeviceName); /* Device name: %s */
printf("软件版本: %s\n", id.SwVersion); /* Software version: %s */
printf("硬件版本: %s\n", id.HwVersion); /* Hardware version: %s */
printf("VendorId: 0x%08X\n", id.VendorId);
printf("ProductCode: 0x%08X\n", id.ProductCode);
printf("RevisionNo: 0x%08X\n", id.RevisionNo);
printf("SerialNo: 0x%08X\n", id.SerialNo);
}
/* ===== Read the master diagnostic data (0xF120) ===== */
/* the fields map to ETG.1510 subindexes 01/02/03/04/16; the lost-frame count is a 5-second sliding-window value, not a percentage */
ec_master_diag_data_t diag;
if (GetMasterDiagData(master, &diag)) {
printf("\n=== 主站诊断 (0xF120) ===\n"); /* === Master diagnostics (0xF120) === */
printf("周期帧频率: %u Hz\n", diag.CyclicFramesPerSec); /* Cyclic frame rate: %u Hz */
printf("非周期帧频率: %u Hz\n", diag.AcyclicFramesPerSec); /* Acyclic frame rate: %u Hz */
printf("周期帧丢失计数: %u\n", diag.CyclicLostFrames); /* Cyclic frame loss count: %u */
printf("主站状态: 0x%04X\n", diag.MasterState); /* Master state: 0x%04X */
}
/* ===== Generic ETG.1510 OD entry point reads slave diagnostics (0xA001:01 AL Status) ===== */
uint8_t al[8] = {0};
int len = 0;
uint16_t abort = 0;
if (DarraEcat_Etg1510_ReadObject(master, 0xA001, 0x01, al, sizeof(al), &len, &abort) >= 2)
printf("从站 1 AL Status: 0x%04X\n", (uint16_t)(al[0] | (al[1] << 8))); /* Slave 1 AL Status: 0x%04X */
/* ===== Walk all slaves (equivalent-field path) ===== */
printf("\n=== 从站诊断 ===\n"); /* === Slave diagnostics === */
for (uint16_t i = 1; i <= slave_count; i++) {
char name[128];
GetSlaveName(master, i, name, sizeof(name));
uint8_t al_state = GetSlaveState(master, i); /* state byte */
uint16_t al_code = GetSlaveALStatusCode(master, i); /* AL Status Code */
int16_t link_quality = GetSlaveLinkQuality(master, i); /* -1 = unknown / never sampled */
printf("从站 %d [%s]: AL=0x%02X, Code=0x%04X, 链路=%d%%\n", /* Slave %d [%s]: AL=0x%02X, Code=0x%04X, link=%d%% */
i, name, al_state, al_code, link_quality);
}
/* ===== PDO frame loss statistics (per group) ===== */
printf("\n=== PDO 丢帧统计 ===\n"); /* === PDO frame loss statistics === */
for (uint8_t g = 0; g < 8; g++) {
uint32_t total = 0, consecutive = 0, max_consecutive = 0;
GetPDOFrameLossStats(master, g, &total, &consecutive, &max_consecutive);
if (total > 0 || GetGroupSlaveCount(master, g) > 0) {
printf("组 %d: 累计=%u, 连续=%u, 最大连续=%u\n", /* Group %d: total=%u, consecutive=%u, max consecutive=%u */
g, total, consecutive, max_consecutive);
}
}
if (!Stop(master)) {
/* the cycle thread was not fully reclaimed: Stop can be retried */
}
if (!Dispose(master)) {
/* not fully released: Dispose can be retried */
}
return 0;
}