Skip to main content

ENI/DENI configuration management

ENI is the EtherCAT network configuration file: which slaves are on the bus, how the PDOs are mapped, and how DC and the startup parameters are set are all written in this file. DENI is the standard ENI with the deni: extension added by Darra.

Why are there two of them? The standard ENI is the common industry format: the usual EtherCAT configuration tools can 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 body of the file (slaves, PDO, DC, startup parameters) is still the 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 set_networkThe file carries NIC information, so the card can be selected automatically
Recommended useCompatibility format for importing an existing projectFirst choice for a new project
Recommended workflow
  1. Use the Darra configuration tool to connect to the slaves and configure PDO/DC/startup parameters
  2. Export a DENI file (.deni)
  3. Load the configuration in code with set_eni()

Loading a configuration​

The Python loading entry point is set_eni(). The file is read at the call site and applied immediately, not deferred to build(). Path and content errors therefore surface on the set_eni() line instead of during the build phase.

set_eni() decides which path this call takes from the file contents, and that decision is made at the moment of the call:

  • DENI (EtherCATConfig + the deni: extension): takes the full engineering semantics — identity-bound slots, optional slots, absent/extra slave handling, group/watchdog/DC contracts, and hot-plug replay. A DENI carries port information, so the NIC is selected automatically and the bus is scanned at load time.
  • Standard ENI (without the deni: extension): the compatibility path, which applies the startup parameters and device characteristics by declared position. It has no concept of optional slots, and it offers neither identity-bound slots nor automatic hot-plug promotion; with this format you have to specify the port yourself with set_network.
  • Any other format (neither DENI nor standard ENI): fails outright and lists the supported formats; nothing is guessed.

Port override rule: both set_eni() and set_network() can set the port, and when both are used, the later call overrides the conflicting configuration of the earlier call — call set_network() first and then set_eni(), and the port in the file wins; call set_eni() first and then set_network(), and the port from set_network() wins. The slaves, PDO, DC and startup parameters in the DENI are always kept; only the port configuration is affected by this rule.

set_eni() applies the NIC, slaves, PDO, DC, SDO, watchdog and group configuration from the file in one pass. build() only performs the finishing steps (ESI auto-matching, auto-configuration, compatibility log) and does not read the configuration file again. If no slaves are scanned, set_network() raises; take the reason from the message and from master.last_error.

set_eni(eni_path)​

def set_eni(self, eni_path: str) -> "EtherCATMaster"

Reads the file as UTF-8 and applies the configuration; both ENI/DENI configuration files and JSON configuration text are supported.

Parameters:

  • eni_path (str) — path to the ENI / DENI / JSON configuration file

Returns:

  • EtherCATMaster — the current instance, for chaining

Raises:

  • FileNotFoundError — the path is not an existing file
  • RuntimeError — the underlying call returned a negative code and the configuration did not take effect; the message carries the path and the return code

Example:

master = EtherCATMaster().set_eni(r"C:\EtherCAT\MyProject.deni")
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"; for how it is done, see Saving a configuration.

Differences from the other SDKs

SetENI in the C# / Java / C++ / Rust SDKs only records the path and reads it at Build(); Python reads and applies the configuration at the set_eni() call, and build() only performs ESI auto-matching, auto-configuration and the compatibility log.

load_config_json(json_str)​

def load_config_json(self, json_str: str) -> int

Hands configuration text to the underlying engine directly, without a file path. set_eni() uses the same entry point internally.

Parameters:

  • json_str (str) — JSON configuration text, or ENI/DENI XML text

Returns:

  • int — the underlying return code: 0 on success, negative on failure. Convert a failure code to a readable reason with describe_native_result(); unknown codes are not guessed and the raw number is returned

Example:

from darra_ethercat import describe_native_result

with open(r"C:\EtherCAT\MyProject.deni", encoding="utf-8") as f:
rc = master.load_config_json(f.read())
if rc < 0:
print(describe_native_result(rc))

Configuration pre-check​

validate()​

def validate(self) -> ValidationResult

Checks the configuration before build() without performing initialization.

Returns:

@dataclass
class ValidationResult:
is_valid: bool # whether validation passed
errors: List[str] # error list (empty when it passes)

The field names follow Python's snake_case convention, not the C# IsValid / Errors.

Checks: the registered configuration file path exists, and the ETG.1500 configuration check passes. It does not scan slaves and does not compare slave identity.

A passing validate() does not mean build() will succeed: it only checks the file path and the configuration validation, and never touches the bus. Python reads and dispatches the configuration at the set_eni() call, so what is added here is the "configuration validation" layer; slave declarations, identity and PDO conflicts in the file only surface at set_network() / set_state().

Example:

result = EtherCATMaster().set_eni(r"C:\EtherCAT\MyProject.deni").validate()
if not result.is_valid:
for err in result.errors:
print(err)

Use validate_config() -> int when you need the raw code: 0 = passed, non-0 = an ETG.1500 error code.

ESI auto-matching without a DENI​

Without a DENI, when devices must be matched through ESI, load the ESI with set_esi_file() / set_esi_files() and mark automatic configuration with enable_auto_startup():

master = (EtherCATMaster()
.set_network(r"\Device\NPF_{GUID}")
.set_esi_files(r"C:\EtherCAT\ESI")
.enable_auto_startup())
master.build()
  • set_esi_file(file_path) / set_esi_files(path) — load immediately; the path may be a file or a directory, and the methods may be called several times; a missing path raises FileNotFoundError
  • enable_auto_startup() — only sets a flag; build() then runs automatic configuration for slaves without startup parameters
  • build() — after the scan, matches and binds slaves by Vendor / Product

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.

For use inside Darra products only

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:

  1. Complete the configuration in the Darra main application or PLC and export a DENI file
  2. Load the existing ENI/DENI file in code with set_eni(path)

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 result that build().deconstruct() gives back: success for whether it succeeded, slave_count for how many slaves were scanned, master_index for the master number obtained, esi_matched / esi_matched_count for the outcome of ESI auto-matching, and auto_startup_rc for the return code of automatic configuration (a negative value = it did not run). The failure reason comes from the exception message raised by set_eni() / set_network().

Calling build() again on the same instance redoes the finishing steps and overwrites the previous result; it does not report "already built". To get the result, call deconstruct() again.

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 adapter name and the link with get_network_info(); for a standard ENI, specify the NIC with set_network
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() / dispose() the unused instances first
validate() passes but a later step failsvalidate() only checks the file path and the configuration validation, it does not touch the busLook at the exception message, auto_startup_rc and the failure stage in the log
The DENI loads, but a part swap is not promoted automatically afterwardsA standard ENI is in use; or the slot was not declared optional; or the new module's identity is not in the declarationSwitch 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​

from darra_ethercat import EtherCATMaster, EcState

with EtherCATMaster() as master:
# 1. Pre-check: file path and configuration validation
check = master.set_eni(r"C:\EtherCAT\MyProject.deni").validate()
if not check.is_valid:
for err in check.errors:
print(err)
raise RuntimeError("配置预检查未通过")

# 2. Finish initialization: ESI auto-matching, auto-configuration, compatibility log
_, result = master.build().deconstruct()
if not result["success"]:
raise RuntimeError(f"初始化失败: {result}")

# 3. Enter OP
if not master.set_state(EcState.OP):
raise RuntimeError(f"未能进入 OP: {master.last_state_error}")

print(f"主站已到 OP,从站 {master.slave_count} 个")

build() returns the instance itself; take the build result with deconstruct(). success means the master index is valid and automatic configuration did not return a negative code.

Related

ENI/DENI configuration is used together with Initialization and construction (set_eni() / build() chained initialization).