ENI/DENI configuration management
ENI is EtherCAT's network configuration file: which slaves are on the bus, how the PDOs are mapped, and how DC and startup parameters are set are all written in this file. DENI is Darra's version of standard ENI with the deni: extension added.
Why are there two? Standard ENI is the industry-common format: the usual EtherCAT configuration tools can all export it, and the SDK can load it directly; but it has none of these engineering semantics — "this slot may be absent", "bind the slot by identity", "replay the startup parameters after a part swap". DENI adds the deni: extension, while the file body (slaves, PDO, DC, startup parameters) is still standard ENI structure.
| Item | Standard ENI | DENI |
|---|---|---|
| Typical source | Exported by other EtherCAT configuration tools | Exported by the Darra configuration tool |
| Slaves, PDO, DC, startup parameters | Yes | Yes (the same body) |
Optional slot <deni:Optional> | No | Yes |
| Identity-bound slots, hot-plug replay | No | Yes |
| NIC | Must be specified with set_network | The file carries NIC information, so the card can be selected automatically |
| Recommended use | Compatibility format for importing an existing project | First choice for a new project |
- Use the Darra configuration tool to connect to the slaves and configure PDO/DC/startup parameters
- Export a DENI file (
.deni) - Load the configuration in code with
EtherCATMaster::builder().set_eni()+build()
Loading a configuration
The Rust entry point is the EtherCATMaster::builder() chaining builder. set_eni() only records the path; the file is read as UTF-8 and applied at build() — recording itself touches neither the file nor the bus.
build() decides which route to take from the file contents:
- DENI (
EtherCATConfig+ thedeni:extension): takes the full engineering semantics — identity-bound slots, optional slots, absent/extra station handling, group/watchdog/DC contracts, hot-plug replay. - Standard ENI (no
deni:extension): the compatibility path — startup parameters and device characteristics are applied by declared position. It has no optional-slot concept, and it offers neither identity-bound slots nor automatic hot-plug promotion; with this format you must specify the port yourself withset_network. - Other formats (neither DENI nor standard ENI): loading fails outright and returns a negative code, and
build()reportsErr(DarraError::ConfigLoadFailed(ret))rather than guessing what format it is.
Port override rule: set_eni() and set_network() can be set together. build() applies the configuration file contents first, then binds the NIC to the port given by set_network(), so when both are set set_network() takes precedence while the rest of the DENI still takes effect; the order of the two methods in the chain does not change this result. When only the configuration file is set, the port comes from the file.
build() applies the NIC, slave, PDO, DC, SDO, watchdog and grouping configuration held in the file. When the scan finds no slave, the error is reported according to the entry point: the port path returns Err directly, while a configuration-file-only path returns Ok but with success = false and a message stating the reason.
set_eni(path)
pub fn set_eni(self, path: &str) -> Self
Records the ENI / DENI configuration file path. The method consumes the builder and returns it for further chaining.
Parameters:
path(&str) — path to the ENI / DENI configuration file
Returns:
Self— the builder itself, for chaining
Failure returns at build time:
- The file cannot be read —
Err(DarraError::Other(...)), with the path and reason in the message LoadConfigJsonreturns a negative code —Err(DarraError::ConfigLoadFailed(ret))
Example:
let mut master = EtherCATMaster::builder()
.set_eni(r"C:\EtherCAT\MyProject.deni")
.build()?
.master;
build()
pub fn build(self) -> Result<BuildResult>
Reads the recorded configuration and initializes the master. The public BuildResult fields:
pub struct BuildResult {
pub master: EtherCATMaster, // the built master instance
pub slave_count: usize, // number of slaves found by the scan
pub success: bool, // false when the scan found 0 slaves
pub message: String, // success / failure reason
}
On the ENI/DENI path build() still returns Ok when the scan finds 0 slaves, but success = false and message reports that no slave was found. The caller must check success and cannot rely on ? alone.
load_config_json(json)
pub fn load_config_json(&self, json: &str) -> Result<()>
On an already built master, loads configuration text directly: JSON or ENI/DENI text. A negative return code yields Err(DarraError::ConfigLoadFailed(ret)).
Example:
let text = std::fs::read_to_string(r"C:\EtherCAT\MyProject.deni")?;
master.load_config_json(&text)?;
Configuration pre-check
validate()
pub fn validate(&self) -> ValidationResult
Checks whether the builder is configured completely before build(), without performing initialization.
Returns:
pub struct ValidationResult {
pub is_valid: bool, // whether validation passed
pub errors: Vec<String>, // error list (empty when it passes)
}
Checks: a NIC or ENI configuration has been set, the ENI path is not empty, the primary NIC name is not empty. File existence is not checked — a missing path returns an error when build() reads the file.
validate() passing does not mean build() is bound to succeed: it only checks "whether a configuration has been set, whether the ENI path and the primary port name have been filled in, and whether what was filled in is empty", without parsing the file contents and without touching the bus. Slave declarations, identities and PDO conflicts in the file are only surfaced by build().
Example:
let builder = EtherCATMaster::builder().set_eni(r"C:\EtherCAT\MyProject.deni");
let check = builder.validate();
if !check.is_valid {
for err in &check.errors {
eprintln!("配置错误: {err}"); // Configuration error: {err}
}
return Ok(());
}
let mut master = builder.build()?.master;
ESI auto-matching without a DENI
Without a DENI, when devices must be matched through ESI, load the ESI with set_esi_file() and mark automatic configuration with enable_auto_startup():
let built = EtherCATMaster::builder()
.set_network(r"\Device\NPF_{GUID}", None)
.set_esi_file(r"C:\EtherCAT\ESI")
.enable_auto_startup()
.build()?;
set_esi_file(path)— records an ESI file or directory; repeated calls accumulate; atbuild()a file and a directory are distinguished withis_dir()enable_auto_startup()— atbuild(), runs automatic configuration for slaves without startup parametersbuild()— after the scan, matches and binds slaves by Vendor / Product
Rust has no separate set_esi_files(); call set_esi_file() several times to accumulate. When a DENI is already in use, loading ESI separately is usually unnecessary.
Saving a configuration
Saving a configuration is provided by Darra products; the SDK does not expose it.
Exporting the runtime configuration to a DENI file is provided by Darra's own products; it is not exposed through the SDK.
The standard workflow for SDK users is:
- Complete the configuration in the Darra main application or PLC and export a DENI file
- Load the existing ENI/DENI file in code with
set_eni(path).build()
If you need to "scan the current hardware and generate a configuration file automatically", use the wizard in the Darra main application or on the PLC side.
Troubleshooting a failed build
Start with the four fields of BuildResult: success for whether it succeeded, message for the failure or success reason, slave_count for the number of slaves found by the scan, and master for the master instance that was built. build() consumes the builder, so there is no "calling it a second time on the same instance" case: each build() call creates a new master instance, and to rebuild you go through EtherCATMaster::builder() again.
| Symptom | Common cause | What to do |
|---|---|---|
| Reports that the file does not exist | Wrong path, or the relative path base is not what you expect | Use an absolute path; confirm the runtime working directory |
| 0 slaves scanned | Wrong NIC, slaves not powered, broken wiring, or the NIC information in the DENI does not match this machine's NIC | Check the MAC and the link with get_network_adapters(); for a standard ENI, specify the NIC with set_network |
| Identity mismatch | The Vendor/Product declared in the DENI does not match the actual module | Put the correct module back, or change the configuration; a Revision difference on the same model is not an identity mismatch |
| A required slave is absent | The slot was not declared optional | Add <deni:Optional>true</deni:Optional>, or plug the module back in |
| The master instance limit has been reached | There is still an unclosed master in the same process | dispose() the unused instances first; the limit is in EtherCATMaster::max_instance_count() and the current usage in active_instance_count() |
validate() passes but build() fails | validate() only checks whether a configuration is set, it does not parse contents | Look at the failure stage in message and in the log |
| The DENI loads, but a part swap is not promoted automatically afterwards | A standard ENI is in use; or the slot was not declared optional; or the new module's identity is not in the declaration | Switch to DENI, add the optional declaration, or follow the part-swap procedure in Hot-plug |
How to tell "same-model recovery" from "part swap": read slave.vendor_id(), slave.product_id() and slave.rev_id() 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.is_lost(), then slave.error_code() (the full AL Status Code). For the meaning of AL codes and the troubleshooting order see Diagnostics; for identity problems see Hot-plug.
Full example
use darra_ethercat::{EcState, EtherCATMaster};
fn main() -> darra_ethercat::Result<()> {
let builder = EtherCATMaster::builder()
.set_eni(r"C:\EtherCAT\MyProject.deni");
// Pre-check: whether a configuration is set, and whether the ENI path and the primary port name are filled in
let check = builder.validate();
if !check.is_valid {
for err in &check.errors {
eprintln!("配置错误: {err}");
}
return Ok(());
}
let built = builder.build()?;
// Judge the outcome by success alone: build() still returns Ok when the scan finds 0 slaves
if !built.success {
eprintln!("初始化失败: {}", built.message);
return Ok(());
}
let mut master = built.master;
master.set_state(EcState::Operational)?;
master.start();
Ok(())
}
ENI/DENI configuration is used together with Initialization and construction (set_eni() / build() streaming initialization).