Skip to main content

Slave groups

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

Typical use cases:

  • Servo drives (group 1): the default group, sent every cycle
  • IO modules (group 2): sent once every 4 cycles
  • Sensors (group 3): sent once every 6400 cycles

The main cycle can be as short as 31 µs; the actual group frequency = main cycle frequency ÷ divider value.

Key simplifications
  • No manual group enabling — on entering SafeOp the system enables the groups that contain slaves and disables empty groups
  • Property-style divider — set it directly with master.divider(group, value)
  • Independent traffic per group — each group has its own PDO data frames and its own WKC
  • Group-level alarms — frame loss statistics and group WKC shortage events are reported per group, so a fault can be located by group

Quick start​

try (EtherCATMaster master = EtherCATMaster.create()) {
int slaveCount = master.setNetwork("\\Device\\NPF_{...}"); // returns the slave count; -1 = failure (getLastError() gives the reason)

// 1. Assign slaves to groups (must happen before SAFE_OP)
// master.getSlave(1~2) is left unset and keeps group=0 (unassigned, folded into group 1 before mapping, sent every cycle)
master.getSlave(3).group((byte) 2); // IO module -> group 2
master.getSlave(4).group((byte) 2);
master.getSlave(5).group((byte) 3); // sensor -> group 3

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

// 3. Switch to OP — groups that contain slaves are enabled automatically
boolean ok = master.setState(EcState.OP); // true = transition succeeded, false = failed
master.start();

// 4. Inspect the group state
System.out.println("活跃组: " + master.activeGroupCount()); // Active groups: {master.activeGroupCount()}
}

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 that are never assigned explicitly end up in group 1
note
  • Valid group numbers are 1-7; each group sends and receives PDO data independently
  • slave.group() accepts 0-7; group-level configuration and queries (divider, per-group frame loss statistics) accept 1-7 only and have no effect for group 0
  • Group numbers need not be contiguous (for example 1, 3, 5); empty groups are skipped
  • Entering SafeOp enables groups that contain slaves and disables empty groups

Method overview​

CategoryMethodTypeR/WDescription
Group assignmentslave.group() / slave.group(byte)byte / voidR/WGroup membership of the slave (0-7; 0 = unassigned, folded into group 1 before mapping); an out-of-range value throws IllegalArgumentException, and writing after SAFE_OP throws IllegalStateException
Group dividermaster.divider(byte) / master.divider(byte, byte)byte / voidR/WPDO cycle divider of the group (1-255, group numbers 1-7); writing 0 throws IllegalArgumentException
Group statemaster.activeGroupCount()byteRead-onlyNumber of distinct group numbers that occur in the current slave set
Group diagnosticsmaster.diagnostics().getPDO().getFrameLossStats(int)int[]Read-onlyCumulative, consecutive and maximum consecutive lost frames of the group; group numbers 0-7, passing 255 returns the summary over all groups, any other out-of-range value throws IllegalArgumentException
Group diagnosticsmaster.diagnostics().getPDO().getTotalLost() / getConsecutiveLost()intRead-onlyCumulative lost frames summed over all groups / the largest current consecutive loss across all groups
Group eventsmaster.events().addPDOFrameLossListener(...)voidWrite-onlyGroup PDO consecutive frame loss event (carries the group number)
Group eventsmaster.events().addWkcShortageOccurredListener(...)voidWrite-onlyGroup WKC shortage event (carries the group number and the actual/expected WKC)

To iterate the slaves of a group, walk the network-wide 1-based index and filter on slave.group(); the SDK has no entry point that returns a slave by its index within a group. With a 1ms main cycle, dividers 1 / 2 / 4 / 10 correspond to 1000 / 500 / 250 / 100 Hz.

Dividers 128-255 need a cast

The parameters of divider(byte group, byte value) are Java signed byte (-128..127), while the valid divider range is 1-255. Writing 128-255 requires a cast, for example 200 → master.divider((byte) 2, (byte) 200); the value read back by divider(group) is also a signed byte, so restore values above 127 with & 0xFF, for example int n = master.divider((byte) 2) & 0xFF;. Values other than 0 are passed to the runtime unchanged, with no range clipping.

API details​

slave.group() / slave.group(byte value)​

public byte group()
public void group(byte value)

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

Parameters:

  • value (byte) — group number 0-7. byte is signed, so negative values are equally invalid

Returns:

  • byte — the current group membership

Exceptions:

  • IllegalArgumentException — group number outside 0-7 (for example a negative value)
  • IllegalStateException — the runtime refuses the write (the change is only allowed before SAFE_OP)

Example:

// assign slaves to groups
master.getSlave(1).group((byte) 1); // explicitly assigned to group 1
master.getSlave(2).group((byte) 2); // explicitly assigned to group 2
// slaves left unset stay at 0 (unassigned, folded into group 1 before mapping)

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

master.divider(byte group) / master.divider(byte group, byte value)​

public byte divider(byte group)
public void divider(byte group, byte value)

Gets or sets the PDO cycle divider of a 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.

Parameters:

  • group (byte) — group number 1-7; for group 0 or an out-of-range value the write has no effect and a read returns 0
  • value (byte) — divider 1-255 (values above 127 need a cast, see the note above)

Returns:

  • byte — the current divider value; returns 0 for an invalid group number

Exceptions:

  • IllegalArgumentException — value is 0

Divider meaning (with a 1ms main cycle):

  • 1 — send every cycle (1000 Hz)
  • 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
master.divider((byte) 1, (byte) 4); // group 1: every 4 cycles
master.divider((byte) 2, (byte) 10); // group 2: every 10 cycles

// read the divider
byte div = master.divider((byte) 2); // 10

master.activeGroupCount()​

public byte activeGroupCount()

Counts the distinct group numbers that occur in the current slave set (computed by scanning; group values are 0-7 and the same number is counted once).

Returns:

  • byte — number of distinct group numbers that occur; returns 0 when there are no slaves

Example:

// confirm the groups that took effect after startup
System.out.println("组号数: " + master.activeGroupCount()); // Group count: {master.activeGroupCount()}

master.diagnostics().getPDO().getFrameLossStats(int group)​

public int[] getFrameLossStats(int group)

Reads the PDO frame loss statistics of the specified group.

Parameters:

  • group (int) — group number 0-7; passing 255 returns the summary over all groups (cumulative summed, current consecutive taken as the maximum, maximum consecutive taken as the maximum)

Returns:

  • int[] — length 3: [0] cumulative lost frames, [1] current consecutive lost frames, [2] historical maximum consecutive lost frames

Exceptions:

  • IllegalArgumentException — group number neither within 0-7 nor equal to 255
  • IllegalStateException — the master has already been released

Example:

int[] stats = master.diagnostics().getPDO().getFrameLossStats(1);
System.out.printf("组1: 累计=%d, 连续=%d, 最大连续=%d%n", // Group 1: cumulative=%d, consecutive=%d, max consecutive=%d%n
stats[0], stats[1], stats[2]);

int[] all = master.diagnostics().getPDO().getFrameLossStats(255); // summary over all groups
int total = master.diagnostics().getPDO().getTotalLost();
int worst = master.diagnostics().getPDO().getConsecutiveLost();

master.events().addPDOFrameLossListener(...)​

void onPDOFrameLoss(short masterIndex, byte group,
int consecutiveLostCount, int totalLostCount)

The group parameter of the PDO consecutive frame loss event identifies which group lost frames. Unsubscribe with removePDOFrameLossListener(...).

Related structure:

ParameterTypeDescription
masterIndexshortMaster index
groupbyteGroup number that lost frames
consecutiveLostCountintCurrent consecutive lost frames
totalLostCountintCumulative lost frames

Example:

master.events().addPDOFrameLossListener((masterIndex, group, consecutive, total) -> {
System.out.printf("组 %d 丢帧: 连续=%d, 累计=%d%n", group, consecutive, total); // Group %d frame loss: consecutive=%d, cumulative=%d%n

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

master.events().addWkcShortageOccurredListener(...)​

void onWkcShortageOccurred(WkcShortageEventArgs args)

Group WKC shortage event: the actual WKC of a group is smaller than the expected WKC (a mapped slave did not contribute). Unsubscribe with removeWkcShortageOccurredListener(...).

Related structure WkcShortageEventArgs:

FieldTypeDescription
masterIndexintMaster index
groupintGroup number (0-7)
actualWkcintActual WKC (returned as an unsigned 16-bit value)
expectedWkcintExpected WKC (returned as an unsigned 16-bit value; a fixed true value determined at configuration time)
timestampUtcjava.time.InstantEvent time (UTC)

Trigger semantics:

  • Triggered only on entering a shortage or on a change of the shortage value; while the shortage persists the event is not repeated
  • After subscribing, the check runs at a period of about 1 second; the event is not an instantaneous alarm and may arrive up to about 1 second later
  • The actual value faithfully reflects the slaves that responded in that group during the cycle; do not lower the expected value to hide a fault

Example:

master.events().addWkcShortageOccurredListener(args ->
System.out.printf("组 %d WKC 短缺: 实测=%d, 期望=%d%n", // Group %d WKC shortfall: measured=%d, expected=%d%n
args.group, args.actualWkc, args.expectedWkc));

Divider frequency calculation​

How the divider value relates to the actual frequency:

Main cycleDividerActual frequencyTypical use
1ms (1000Hz)11000 HzServo drives
1ms (1000Hz)4250 HzIO modules
1ms (1000Hz)10100 HzSensors
1ms (1000Hz)2005 HzSlow monitoring
31 µs (minimum cycle)1about 32 kHzHigh-speed servo
31 µs (minimum cycle)4about 8 kHzHigh-speed IO
31 µs (minimum cycle)64005 HzSlow sensors

Formula: actual frequency = main cycle frequency / divider value

Automatic enable/disable​

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

  • Groups that contain slaves -> enabled automatically, with the divider guaranteed to be at least 1
  • Empty groups -> disabled automatically, PDO traffic is skipped

Groups never need to be enabled manually, and group numbers need not be contiguous.

Group WKC and group offline alarms​

Each group has its own frames and its own WKC; the actual value faithfully reflects the slaves that responded in that group during the cycle.

SymptomCriterionAction
Group WKC shortageWkcShortageEventArgs: the actual WKC of the group is smaller than the expected WKCWhile the shortage persists no repeat alarm is raised; locate the slave that stopped responding, group by group
Consecutive group frame lossgetFrameLossStats(group)[1] keeps growing, or PDOFrameLoss events keep arrivingSame as above; narrow the scope by group
The whole group does not respondNone of the slaves in the group contributes process dataCheck the slave states and the link of that group; do not change the divider to hide the fault
Do not lower the expected value to hide a fault

The expected WKC is a fixed true value determined at configuration time; an actual value below the expected one = a slave has dropped out. The correct response is to raise an alarm and locate it by group, not to lower the expected value until the two "match".

For the other group-level diagnostics see diagnostics.

Configuration sequence​

INIT → PRE_OP → SAFE_OP → OP
| | |
| | +-- Group configuration locked; PDO sent per group
| |
| +-- Set slave group assignment: slave.group(N)
| Set group divider: master.divider(N, divider)
| (groups that contain slaves are enabled automatically on entering SAFE_OP)
|
+-- Initialize the master
caution
  • slave.group(N) must be set before entering SAFE_OP; a write after that is refused by the runtime and throws IllegalStateException
  • Set the group dividers after initialization and before OP
  • Group configuration is locked automatically after entering SAFE_OP

Full example​

try (EtherCATMaster master = EtherCATMaster.create()) {
int slaveCount = master.setNetwork("\\Device\\NPF_{...}"); // returns the slave count; -1 = failure (getLastError() gives the reason)

// 1. Assign slaves to groups
// master.getSlave(1~3) is left unset and keeps group=0 (servo drives, unassigned, folded into group 1 before mapping)
master.getSlave(4).group((byte) 2); // IO module -> group 2
master.getSlave(5).group((byte) 2);
master.getSlave(6).group((byte) 3); // sensor -> group 3

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

// 3. Set the cycle time
master.config().loopCycle(1_000_000); // 1ms

// 4. PDO frame loss monitoring (independent per group)
master.events().addPDOFrameLossListener((masterIndex, group, consecutive, total) -> {
System.out.printf("组 %d 丢帧: 连续=%d, 累计=%d%n", group, consecutive, total); // Group %d frame loss: consecutive=%d, cumulative=%d%n
});

// 4.1 Group WKC shortage alarm (group-level loss of response)
master.events().addWkcShortageOccurredListener(args ->
System.out.printf("组 %d WKC 短缺: 实测=%d, 期望=%d%n", // Group %d WKC shortfall: measured=%d, expected=%d%n
args.group, args.actualWkc, args.expectedWkc));

// 5. Start -- groups that contain slaves are enabled automatically
boolean ok = master.setState(EcState.OP); // true = transition succeeded, false = failed
master.start();

// 6. Inspect the group state
System.out.println("活跃组: " + master.activeGroupCount()); // Active groups: {master.activeGroupCount()}

// 7. Iterate the slaves and show their group membership
for (Slave slave : master.slaves()) {
System.out.printf("从站 %d: 组 %d%n", slave.SlaveNum, slave.group()); // Slave %d: group %d%n
}

// 8. Poll copyInputPdo / writeOutputPdo per group in the application thread
new Thread(() -> {
while (running) {
for (Slave servo : master.slaves()) {
if (servo.group() == 1) {
// group 1 servo: servo.PDO().copyInputPdo / writeOutputPdo
}
}
try { Thread.sleep(1); } catch (InterruptedException e) { break; }
}
}).start();

// 9. Query the frame loss statistics of each group
MasterDiagnosticsInfo.MasterPDODiagnostics pdo = master.diagnostics().getPDO();
int[] g1 = pdo.getFrameLossStats(1);
int[] g2 = pdo.getFrameLossStats(2);
System.out.printf("组1 丢帧: %d, 组2 丢帧: %d%n", g1[0], g2[0]); // Group 1 frame loss: %d, group 2 frame loss: %d%n
}

Failures and handling​

SymptomMeaningAction
slave.group(byte) throws IllegalArgumentExceptionGroup number outside 0-7 (including negative values)Check the argument
slave.group(byte) throws IllegalStateExceptionThe runtime refuses the write (SAFE_OP has already been entered)Set the group membership earlier, before SAFE_OP
master.divider(g, v) throws IllegalArgumentExceptionDivider written as 0Valid divider values are 1-255
divider(group) reads back 0Group number outside 1-7Group 0 is the unassigned marker; group-level configuration applies to 1-7 only
getFrameLossStats throws IllegalArgumentExceptionGroup number neither within 0-7 nor equal to 255Check the argument; 255 = summary over all groups
PDOFrameLoss / WkcShortage events keep arrivingA slave in that group stopped respondingLocate it by group; do not lower the expected WKC