Skip to main content

Slave groups

Slave grouping lets you assign slaves to different groups (1-7; group=0 means unassigned, and is folded into group 1 before mapping). Each group can carry its own PDO cycle divider, so different groups exchange data at different rates.

Typical use cases:

  • Servo drives (group 1): default group, sent every cycle, 31 µs (= 31,000 ns, derived frequency about 32.26 kHz)
  • IO modules (group 2): sent every 4 cycles, 8000 Hz at 125 µs
  • Sensors (group 3): sent every 6400 cycles, 5 Hz at 200 ms
Key simplifications
  • No manual group enabling — on entering SafeOp the system enables groups that have slaves and disables empty groups
  • Property-style divider — set it directly through set_group_cycle_divider()
  • Independent traffic per group — each group maps to its own PDO data frame

Quick start​

let mut master = EtherCATMaster::from_json_file("config.json")?;

// 1. Assign slaves to groups (must happen before SAFE_OP)
// leave slaves 1~2 unset: they keep group=0 (unassigned, folded into group 1 before mapping, sent every cycle)
master.slave(3).set_group(2); // IO modules -> group 2
master.slave(4).set_group(2);
master.slave(5).set_group(3); // sensors -> group 3

// 2. Set the group dividers (group-level configuration accepts group numbers 1-7 only)
master.set_group_cycle_divider(2, 4); // group 2: send every 4 cycles
master.set_group_cycle_divider(3, 10); // group 3: send every 10 cycles
// group 1 (the default group) has divider=1 by default; nothing else to set

// 3. Switch to OP — the system enables the groups that have slaves
master.set_state(EcState::Operational)?;

// 4. Query group information
println!("组2: {} 个从站", master.group_slave_count(2)); // Group 2: {} slaves
println!("组3: {} 个从站", master.group_slave_count(3)); // Group 3: {} slaves

Group semantics​

GroupMeaning
0Unassigned marker — stays 0 when you do not set it; folded into group 1 before the SAFE_OP mapping and does not send or receive on its own
1-7Valid PDO groups — assigned by the user; group numbers need not be contiguous; slaves never assigned explicitly end up in group 1
note
  • Valid group numbers are 1-7; each group sends and receives its own PDO data
  • slave.set_group() accepts 0-7; group-level configuration and queries (set_group_cycle_divider(), set_group_enabled(), group_expected_wkc(), group_slave_count(), per-group frame-loss statistics) accept 1-7 only — setting them for group 0 has no effect
  • Group numbers need not be contiguous (for example 1, 3, 5); the system skips empty groups
  • Entering SafeOp enables groups that have slaves and disables empty groups

Assigning slaves to groups​

slave.group() / slave.set_group()​

pub fn group(&self) -> u8
pub fn set_group(&self, group: u8) -> Result<()>

Gets or sets the slave's group membership (0-7; 0 = unassigned, folded into group 1 before mapping). Must be set before SAFE_OP.

Example:

// assign slaves to groups
master.slave(1).set_group(1); // explicitly to group 1
master.slave(2).set_group(2); // explicitly to group 2
// master.slave(3) left unset: stays 0 (unassigned, folded into group 1 before mapping)

// read the group the slave belongs to
let group = master.slave(1).group();

group_slave_count()​

pub fn group_slave_count(&self, group: u8) -> u16

Gets the number of slaves in the group. Group numbers accept 1-7 only (group 0 always returns 0).

active_group_count()​

pub fn active_group_count(&self) -> u8

Gets the number of active groups (computed by scanning the slave set).

group_expected_wkc()​

pub fn group_expected_wkc(&self, group: u8) -> u16

Gets the expected WKC of the group. Group numbers accept 1-7 only (group 0 always returns 0).

Group divider​

set_group_cycle_divider()​

pub fn set_group_cycle_divider(&self, group: u8, divider: u8) -> bool

Sets the PDO cycle divider of the group (1-255). Group numbers accept 1-7 only (group 0 is the unassigned marker; setting it has no effect); every group's divider defaults to 1.

  • 1 — send every cycle (1000 Hz with a 1 ms main cycle)
  • 2 — send every 2 cycles (500 Hz)
  • 4 — send every 4 cycles (250 Hz)
  • 10 — send every 10 cycles (100 Hz)

Example:

// set the divider (group numbers 1-7)
master.set_group_cycle_divider(2, 4); // group 2: every 4 cycles
master.set_group_cycle_divider(3, 10); // group 3: every 10 cycles
// group 1 (the default group) has divider=1 by default (every cycle); nothing to set

set_group_enabled() / get_group_enabled()​

pub fn set_group_enabled(&self, group: u8, enabled: bool) -> bool
pub fn get_group_enabled(&self, group: u8) -> bool

Enables or disables a group (group numbers 1-7), and queries the current enable state. You normally do not call these: the system manages them automatically on entering SafeOp.

Automatic enable and disable​

On entering the SafeOp state the system scans every group (1-7) for slaves:

  • Group with slaves -> enabled automatically, with the divider forced to at least 1
  • Empty group -> disabled automatically, PDO traffic skipped

You do not call set_group_enabled() manually, and group numbers need not be contiguous.

Group diagnostics​

Each group tracks its own PDO frame-loss statistics.

Query frame loss per group​

// frame-loss statistics for the specified group
let stats = master.diagnostics_info().pdo().frame_loss_stats(1);
println!("组1: 累计丢帧={}, 连续={}", stats.total_lost, stats.consecutive_lost); // Group 1: total frame loss={}, consecutive={}

let stats2 = master.diagnostics_info().pdo().frame_loss_stats(2);
println!("组2: 累计丢帧={}", stats2.total_lost); // Group 2: total frame loss={}

Group-level WKC diagnostics​

Each PDO group maps to its own frame and its own WKC. Group diagnostics such as the group's actual WKC, the consecutive shortfall count and the total frame count are queried per group through the EcGroupConfigHelper static methods.

WKC hard rule

The group expected WKC is a fixed true value determined at configuration time and is never lowered. get_group_actual_wkc() < get_group_expected_wkc() means slaves in that group dropped out — an accurate report of the fault, so raise an alarm and diagnose instead of lowering the expected value to hide it. After the slaves recover, the actual WKC rises back naturally to match the fixed expected value.

EcGroupConfigHelper​

EcGroupConfigHelper is a set of static methods that parse group diagnostics from the raw group configuration data by group number (0-7). Valid PDO group numbers are 1-7; group 0 is the unassigned marker and is folded into group 1 after mapping.

  • get_group_enabled(raw, group) (bool) — whether the group is enabled
  • get_group_cycle_divider(raw, group) (u8) — group cycle divider
  • get_group_expected_wkc(raw, group) (u16) — group expected WKC (fixed true value)
  • get_group_slave_count(raw, group) (u16) — number of slaves in the group
  • get_group_frame_repeat_eligible(raw, group) (bool) — group frame-repeat eligibility (ETG.1500 5.4.3)
  • get_group_actual_wkc(raw, group) (u16) — group actual WKC (result of this cycle's exchange)
  • get_group_consecutive_miss(raw, group) (u16) — consecutive cycles the group's WKC fell short (actual < expected)
  • get_group_total_frames(raw, group) (u32) — total TX frames of the group
  • get_group_mismatch_frames(raw, group) (u32) — total frames with a WKC mismatch in the group

set_group_enabled / set_group_cycle_divider / set_group_frame_repeat_eligible are the matching write methods; they update the group diagnostic data in place.

Example:

use darra_ethercat::EcGroupConfigHelper;

// raw is the raw group diagnostic data (per-group WKC / frame counters and other diagnostics)
fn report_group_health(raw: &[u8]) {
for g in 1..=7u8 {
let slaves = EcGroupConfigHelper::get_group_slave_count(raw, g);
if slaves == 0 { continue; } // skip empty groups

let expected = EcGroupConfigHelper::get_group_expected_wkc(raw, g);
let actual = EcGroupConfigHelper::get_group_actual_wkc(raw, g);
let miss = EcGroupConfigHelper::get_group_consecutive_miss(raw, g);

if actual < expected {
println!("⚠ 组 {}: WKC {}/{} (连续不足 {} 次) — 有从站掉了", // ⚠ Group {}: WKC {}/{} (short {} times in a row) — a slave has dropped
g, actual, expected, miss);
} else {
println!("组 {}: WKC {}/{} 正常", g, actual, expected); // Group {}: WKC {}/{} normal
}
}
}
When to use EcGroupConfigHelper

Group-level WKC diagnostics are a low-level / advanced API that needs the raw group diagnostic data as input. For routine group-deviation monitoring use master.diagnostics_info() and pdo().frame_loss_stats(group) (see above); EcGroupConfigHelper is for diagnostic tools or custom monitoring panels that need exact per-group WKC values.

PDOFrameLoss events​

The group parameter of the PDO consecutive-frame-loss event identifies which group lost frames:

master.events().on_pdo_frame_loss(|_, group, consecutive, total| {
println!("组 {} 丢帧: 连续={}, 累计={}", group, consecutive, total); // Group {} frame loss: consecutive={}, total={}

if group == 1 {
// frame loss in the servo group: handle immediately
println!("警告: 伺服组通信异常!"); // Warning: servo group communication abnormal!
}
});

Configuration sequence​

INIT → PRE_OP → SAFE_OP → OP
| | |
| | +- group configuration is locked; PDO starts sending per group
| |
| +- set slave group membership: slave.set_group(n)
| set group dividers: set_group_cycle_divider(n, divider)
| (entering SafeOp enables the groups that have slaves)
|
+- initialize the master
caution
  • slave.set_group() takes effect when entering SAFE_OP
  • Set the group dividers after initialization and before set_state(Operational)
  • Group configuration is locked automatically after entering SAFE_OP

Full example​

let mut master = EtherCATMaster::from_json_file("config.json")?;

// 1. Assign slaves to groups
// leave slaves 1~3 unset: they keep group=0 (servo drives, unassigned, folded into group 1 before mapping)
for i in 4..=5 {
master.slave(i).set_group(2); // last 2 slaves -> group 2 (IO modules)
}
// the remaining slaves keep group=0 (folded into group 1 before mapping, sent every cycle)

// 2. Set the group divider (group numbers 1-7)
master.set_group_cycle_divider(2, 4); // group 2: 250 Hz
// group 1 (the default group) has divider=1 by default (1000 Hz); nothing to set

// 3. Cycle time
master.config().set_loop_cycle(1_000_000); // 1 ms

// 4. PDO frame-loss monitoring (independent per group)
master.events().on_pdo_frame_loss(|_, group, consecutive, _| {
println!("组 {} 丢帧: 连续={}", group, consecutive); // Group {} frame loss: consecutive={}
});

// 5. Start — groups that have slaves are enabled automatically
master.set_state(EcState::Operational)?;

// 6. Inspect the group state
println!("活跃组: {}", master.active_group_count()); // Active groups: {}
println!("组1: {} 个从站", master.group_slave_count(1)); // Group 1: {} slaves
println!("组2: {} 个从站", master.group_slave_count(2)); // Group 2: {} slaves

// 7. Cycle callback (synchronous, for real-time control such as FSoE; the PDO data path is real-time process image pointer polling)
master.events().on_pdo_cyclic_sync(|_| {
// fast PDO reads and writes only
});