Skip to main content

ENI/DENI configuration management

ENI is the EtherCAT network configuration file: which slaves are on the bus, how the PDO is mapped, and how DC and the startup parameters are set are all written in this file. DENI is Darra's version of standard ENI with the deni: extension added. The Java SDK provides no static utility class for reading or writing ENI offline: a configuration file is handed to the SDK through setENI(...) and loaded at build().

Why are there two? A standard ENI is the industry-common format, and the usual EtherCAT configuration tools can all export it; but it has none of these engineering semantics: "this slot may be absent", "bind a slot by identity", "replay the startup parameters after a part swap". DENI adds the deni: extension to fill the gap; the file body (slaves, PDO, DC, startup parameters) is still standard ENI structure.

ItemStandard ENIDENI
Typical sourceExported by other EtherCAT configuration toolsExported by the Darra configuration tool
Slaves, PDO, DC, startup parametersYesYes (the same body)
Optional slot <deni:Optional>NoYes
Identity-bound slots, hot-plug replayNoYes
NICMust be specified with setNetworkThe file carries NIC information, so the card can be selected automatically
Recommended useCompatibility format for importing an existing projectFirst choice for a new project

Which kinds of content the loading entry points accept, and the semantics of each, is described below in Loading a configuration.

Recommended workflow
  1. Connect the slaves with the Darra configuration tool and configure PDO/DC/startup parameters
  2. Export the DENI file (.deni)
  3. Load the configuration in code with setENI() + build()

Loading entry points​

CategoryMethodTypeR/WDescription
Configuration filesetENI(String path)EtherCATMasterWrite-onlySet the ENI/DENI path; returns the current instance for chaining; deferred until build()
setNetwork(String adapter) / setNetwork(String adapter, String redundantAdapter)intWrite-onlySet the NIC directly; when used together with setENI, the call made later overrides the conflicting setting from the earlier one
setEsiFile(String path) / setEsiFiles(String path)EtherCATMasterWrite-onlyAppend an ESI file or directory; can be called several times
enableAutoStartup()EtherCATMasterWrite-onlyEnable automatic startup configuration for slaves that have no startup parameters in the ENI
Buildbuild()BuildResultWrite-onlyValidate the configuration → load ESI → load ENI → match ESI → configure automatically
buildAsync(Consumer<String> progress) / buildAsync()CompletableFuture<BuildResult>Write-onlyAsynchronous build; does not block the calling thread
validate()ValidationResultRead-onlyPre-check whether the chained configuration is complete before build()
Direct JSONloadConfigJson(String json)intWrite-onlyHand a JSON configuration straight to the runtime; returns the underlying execution result code

The ValidationResult returned by validate() has two public fields: IsValid (whether the configuration is valid) and Errors (list of error messages). The field names follow the PascalCase naming used on the C# side so that the names match across languages; they are not Java's customary camelCase, and there is no isValid() getter — read the fields directly.

Which approach to use
  • In production, use setENI(path).build() to load the network configuration in one line.
  • With an existing JSON configuration (for example one supplied by a higher-level system), use loadConfigJson(json).
  • With no configuration file, use setNetwork(...) to scan the NIC and configure automatically.

Loading a configuration​

The user SDK only goes through setENI. setENI(path) only records the path; the file is really read at build().

build() decides which route to take from the file contents (setENI reads the file into text and then goes through the same entry point as loadConfigJson, so the two routes stay consistent):

  • DENI (<EtherCATConfig> + deni: extensions): takes the full engineering semantics — slot identity binding, optional slots, absent/extra station handling, group/watchdog/DC contracts, hot-plug replay — binds the NIC from the port information in the file, then scans the slaves live.
  • JSON configuration text: only injects slave startup parameters; no slot identity binding, and no NIC binding.
  • Anything else (neither parseable DENI XML nor valid JSON): build() fails directly, with a message of the form ENI 加载失败: 路径 (返回码: N) (SDK output, = ENI load failed: path (return code: N)); look up what a return code means with ProtocolCodes.resultDescription(int), and never guess the semantics of an unknown code.

This Java loading entry point has no separate "standard ENI compatibility path": the file must be DENI or JSON configuration text, so a standard ENI without a deni: extension section cannot come in.

NIC override rules: both setENI and setNetwork can supply a NIC, and when both are used the later call overrides the conflicting settings from the earlier one. The slaves, PDO, DC and startup parameters in the ENI/DENI are always kept — only the NIC changes. setENI takes effect only at build(), and build() binds the NIC from the file when it parses the DENI; setNetwork(...) takes effect immediately, so calling setNetwork after build() uses the card you supplied.

build() applies the file's NIC, slaves, PDO, DC, SDO, watchdog and grouping configuration. If no slaves can be scanned the build fails; take the reason from the returned message.

setENI(String path)​

public EtherCATMaster setENI(String path)

Set the ENI/DENI configuration file path. The method only records it and does not read the file immediately; the actual parsing happens inside build(), in the same flow as ESI loading, slave matching and automatic configuration.

Parameters:

  • path (String) — ENI / DENI file path

Returns:

  • EtherCATMaster — the current instance, for chained calls

If the path is null or an empty string, the method throws IllegalArgumentException immediately; an empty path never reaches build().

Path and reading: the path is an ordinary string, and forward slashes and backslashes are equivalent ("C:/EtherCAT/MyProject.deni" and "C:\\EtherCAT\\MyProject.deni" both work). build() reads the whole file as UTF-8; if the file does not exist, cannot be read or cannot be parsed, no exception is thrown — a BuildResult with success = false is returned and the reason is written into message (see "Failure returns" below). The path can be recorded repeatedly; the later call overrides the earlier one.

Exporting a DENI is provided by Darra products

The SDK offers no interface for "saving a configuration" or "scanning the current hardware to generate a DENI" — use the Darra configuration tool to configure and export the DENI. Details are in Generating and editing the configuration file below.

With no DENI and a need for ESI auto-matching, use setEsiFile / setEsiFiles + enableAutoStartup().

validate()​

public EtherCATMaster.ValidationResult validate()

Validates whether the configuration is complete; it does not run build() and is meant for a pre-check.

Returns:

public static class ValidationResult {
public final boolean IsValid; // Whether validation passed
public final List<String> Errors; // List of validation errors (empty when it passes)
}

What is checked today: a NIC or an ENI configuration has been set, and the ENI path is not an empty string.

Passing validate() does not mean build() will succeed: it only checks "is a NIC or a configuration set, and is the ENI path a non-empty string". It does not parse the file contents and it does not touch the bus. Slave declarations, identities and PDO conflicts inside the file only surface at build().

Example:

EtherCATMaster.ValidationResult check =
EtherCATMaster.create().setENI("C:/EtherCAT/MyProject.deni").validate();
if (!check.IsValid) {
for (String err : check.Errors)
System.out.println(err);
return;
}

build() / buildAsync()​

public EtherCATMaster.BuildResult build()
public CompletableFuture<EtherCATMaster.BuildResult> buildAsync()
public CompletableFuture<EtherCATMaster.BuildResult> buildAsync(java.util.function.Consumer<String> progress)

build() is the terminal method and runs the following in order: validate the configuration → load ESI (setEsiFile / setEsiFiles) → load the ENI/DENI → match ESI devices → configure automatically. A failed ESI file or directory load does not block the build; it only means that batch of devices cannot be matched.

BuildResult fields:

public static class BuildResult {
public final boolean success; // Whether the build succeeded
public final int slaveCount; // Number of slaves scanned
public final short masterIndex; // Master number
public final String message; // Success / failure message
public final EtherCATMaster master; // Master instance (null when the configuration / file read fails)
}
FieldTypeMeaning
successbooleanWhether the build succeeded. Judge success by this field alone; it is also false when the slave count is 0
slaveCountintNumber of slaves found
masterIndexshortMaster index
messageStringSuccess / failure message; the failure reason (including the file path) is written here
masterEtherCATMasterMaster instance. null when the configuration is missing / the file cannot be read; still points to the current instance when the slave count is 0

Failure returns: a missing configuration, an unreadable DENI file, a failed ENI load and a failed automatic configuration all return a BuildResult with success = false and throw no exception. On a read failure message has the form 读 DENI 文件失败: 路径 (原因) (SDK output, = failed to read DENI file: path (reason)); on a load failure it has the form ENI 加载失败: 路径 (返回码: N) (SDK output, = ENI load failed: path (return code: N)), and the return code is negative. Look up the Chinese text of a return code with ProtocolCodes.resultDescription(int) (com.darra.ethercat.statics.ProtocolCodes), which covers the whole result_t range (0 success / -1..-7 basic failures / -20..-26 hot-plug rebuild / -30..-32 startup parameters / -40..-52 DENI XML / JSON configuration / NIC open); an unknown code is not given a guessed meaning — the raw number is passed through as is.

Exceptions: calling build() after the master has been released (after close()) throws IllegalStateException.

buildAsync(progress) behaves exactly like build(), except that it runs on a background thread: the progress callback fires on the background thread and receives initialization progress text; switching back to the UI thread is up to the caller. Cancelling the returned future aborts this initialization.

loadConfigJson(String json)​

public int loadConfigJson(String json)

Hand a block of configuration text straight to the runtime, without going through the setENI file path. Both ways use the same loading entry point: setENI(path) reads the file into text inside build() and then hands it over, so the same DENI text can be supplied either as a path or directly as a string.

Parameters:

  • json (String) — JSON configuration text; it can also be DENI XML text

Returns:

  • int — the underlying execution result code; a negative value means the load failed (the same code set as "ENI 加载失败" in build()); look up the Chinese text of each code with ProtocolCodes.resultDescription(int); an unknown code is not given a guessed meaning

Exceptions: calling it after the master has been released (after close()) throws IllegalStateException.

Slave objects when loading a DENI file​

When build() goes through DENI it only binds the NIC and scans slaves; it does not populate the master's slave list (that list is built only when setNetwork(...) scans the NIC). So after a one-step DENI initialization:

  • master.getSlave(n) throws IndexOutOfBoundsException (the check is against the current list length, which is 0);
  • master.slaves() returns an empty list, so for (Slave s : master.slaves()) never enters the loop.

In the current version, construct the slave object directly from the master index and the 1-based slave index, and use that object for all later slave-level calls:

import com.darra.ethercat.slave.CoE;
import com.darra.ethercat.slave.Slave;

Slave slave1 = new Slave(master.MasterIndex, (short) 1, master);
CoE.SdoReadResult r1 = slave1.coe().sdoRead((short) 0x1018, (byte) 0x01);

master.slaveCount() is not affected and still returns the real number of slaves found. Once the DENI path fills in the slave list, both master.getSlave(n) and direct construction work.

Generating and editing the configuration file​

  • ENI/DENI parsing is done by the SDK runtime from the file contents; the caller only supplies a path or a JSON string.
  • When you need to "scan the hardware and generate a configuration file", use the Darra main application / configuration tool: scan the network, assign slaves, configure PDO and DC, then export the ENI/DENI.
  • The SDK provides no API for editing, reading or saving ENI offline; maintain the configuration file in the configuration tool above — at runtime the SDK only loads it.

Troubleshooting a failed build​

Start with the BuildResult fields: success for whether it succeeded, message for the failure reason, slaveCount for the number of slaves scanned, and master for the master instance (null when the configuration is missing / the file cannot be read). BuildResult has no "already built" state: calling build() repeatedly on the same instance runs the loading flow again, so judge success by success alone.

SymptomCommon causeWhat to do
Reports that the file does not existWrong path, or the relative path base is not what you expectUse an absolute path; confirm the runtime working directory
0 slaves scannedWrong NIC, slaves not powered, broken wiring, or the NIC information in the DENI does not match this machine's NICCheck the NIC with NetworkInfo.getAvailableNetworks(); for the specific reason a setNetwork failed, look at master.getLastError()
Identity mismatchThe Vendor/Product declared in the DENI does not match the actual modulePut the correct module back, or change the configuration; a Revision difference on the same model is not an identity mismatch
A required slave is absentThe slot was not declared optionalAdd <deni:Optional>true</deni:Optional>, or plug the module back in
The master instance limit has been reachedThere is still an unclosed master in the same processclose() the unused instances first
validate() passes but build() failsvalidate() only checks the NIC and path settings, it does not parse contentsLook at the failure stage and the return code in message
The DENI loads, but a part swap is not promoted automatically afterwardsThe slot was not declared optional, or the new module's identity is not in the declarationAdd the optional declaration, or follow the part-swap procedure in Hot-plug

How to tell "same-model recovery" from "part swap": read slave.vendorId(), slave.productId() and slave.revId() for that station, or subscribe to SlaveIdentityMismatch (the payload carries the expected identity and the measured identity). Matching Vendor/Product = same model (Revision is only recorded, never grounds for rejection); a different Vendor or Product = a part swap. The master restores the former automatically; for the latter the application layer has to pick the configuration.

What to look at when a station will not reach OP: first look at slave.state() and slave.isLost(), then slave.errorCode() (the full AL Status Code). For the meaning of AL codes and the troubleshooting order see Diagnostics; for identity problems see Hot-plug.

When you need a more detailed failure reason, call master.getLastError() after build(), or call new State(master.MasterIndex).verifyStartupConfiguration() on the built master to get the per-item Chinese details (see Initialization).

Full example​

import com.darra.ethercat.master.EtherCATMaster;
import com.darra.ethercat.data.EcState;

// 1. Pre-check: is a port or a configuration set, and is the ENI path an empty string
EtherCATMaster ecat = EtherCATMaster.create()
.setENI("C:/EtherCAT/MyProject.deni");

EtherCATMaster.ValidationResult check = ecat.validate();
if (!check.IsValid) {
for (String err : check.Errors)
System.out.println(err);
return;
}

// 2. Build (the configuration is really parsed here)
EtherCATMaster.BuildResult r = ecat.build();
if (!r.success) {
throw new RuntimeException("构建失败: " + r.message);
}

// 3. Continue with the master instance you just built
try (EtherCATMaster master = r.master) {
if (!master.setState(EcState.OP)) {
System.err.println("未能进入 OP");
}
// ... process data read/write, diagnostics, events
} // try-with-resources closes automatically

Asynchronous build:

EtherCATMaster master = EtherCATMaster.create().setENI("C:/EtherCAT/MyProject.deni");

master.buildAsync(msg -> System.out.println("[build] " + msg))
.thenAccept(result -> {
if (!result.success) {
System.err.println("构建失败: " + result.message);
return;
}
System.out.println("从站数: " + result.slaveCount);
});
Related features

Use ENI/DENI configuration together with Initialization and construction (streaming initialization with setENI() / build()).