MDP — modular devices
Modular Device Profile (MDP, ETG.5001) is the EtherCAT standard protocol for describing modular devices (slots + pluggable modules).
Accessed through slave.mdp (returns MdpDiscovery). None when the slave does not support MDP.
enable_auto_startup() does not orchestrate MDPmaster.enable_auto_startup() only performs automatic configuration of the slave SM physical parameters (AutoConfigureSM); it neither discovers nor orchestrates MDP modules. Module detection / comparison / configuration write-back are all triggered manually as needed: discover() / check_module_match() / auto_configure_from_detected_modules().
The SDK supports reconfiguration self-repair after an MDP module hot-plug.
In production, hot-plugging an MDP module is a scenario that almost never occurs.
To deploy MDP modular devices, using DENI is recommended;
for automatic configuration, import the matching ESI file first, then call the master enable_auto_startup() or the slave-level configuration.
Method overview
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| Module list | configured_modules | list or None | read-only | Configured modules; None means the read failed, not that there are no modules |
| detected_modules | list or None | read-only | Modules physically inserted; None as above | |
| Module detection | discover | list or None | read-only | Reads 0xF050 and returns a list of MdpModule (slot / profile_id / module_type) |
| rescan | list or None | read-only | Rescans the configured and detected lists and returns the detected slots | |
| Validation | check_module_match | (bool or None, int) | read-only | Compares the configured and detected modules; True = match, False = mismatch, None = undeterminable (not the same as mismatch); the second item is the first differing slot on mismatch, otherwise -1 |
| PDO layout | get_module_pdo_layout | list or None | read-only | Input/output offsets and byte counts of each module in the process image |
| Configuration write-back | auto_configure_from_detected_modules | int | write-only | Rewrites 0xF030 from the detection result (four-step sequence); returns the number of modules written on success, -1 on failure |
| Automatic enumeration | auto_enumerate | int | write-only | Master-level automatic enumeration and comparison of the module lists of all slaves; >=0 is the enumerated count, <0 failure |
Properties
| Category | Property | Type | Read/write | Description |
|---|---|---|---|---|
| Module list | configured_modules | Optional[List[MdpSlotInfo]] | read-only | Configured module list (implemented by the underlying library, 0xF030); None = the read failed / undeterminable (unknown, not "no modules") |
| detected_modules | Optional[List[MdpSlotInfo]] | read-only | Detected module list, reflecting what is physically inserted (implemented by the underlying library, 0xF050); None = the read failed / undeterminable | |
| config_module_idents | Optional[List[int]] | read-only | Reads the 0xF030 ConfigModuleIdent array through the underlying library; None = unknown | |
| detected_module_idents | Optional[List[int]] | read-only | Reads the 0xF050 DetectedModuleIdent array through the underlying library; None = unknown | |
| modules | List[MdpModule] | read-only | Snapshot of the most recent discover() result | |
| Device properties | module_index_distance | int | read-only | Module object dictionary index distance (0xF000:01; falls back to 0x0010 when unreadable or 0) |
| max_module_count | int | read-only | Maximum number of modules supported by the device (0xF000:02) |
MdpSlotInfo class
Module slot information (ETG.5001), an ordinary class:
class MdpSlotInfo:
slot_index: int # slot index (starts at 1)
module_ident: int # module ident code (32-bit)
module_name: str # module name (of the form "Module 0x........")
module_type: int # module device type code (low 16 bits of module_ident)
status: str # status ("已配置" / "已检测") (SDK output, = configured / detected)
object_dictionary_index: int # module object dictionary base address (= index_distance × slot_index)
module_io_type: str # I/O type; the Python layer does not populate it yet, fixed to "Unknown"
Example:
for slot in (slave.mdp.configured_modules or []):
print(f"Slot {slot.slot_index}: {slot.module_name} (0x{slot.module_ident:08X})")
for slot in (slave.mdp.detected_modules or []):
print(f"Slot {slot.slot_index}: 检测到模块 0x{slot.module_ident:08X}") # Slot {slot.slot_index}: module 0x{slot.module_ident:08X} detected
MdpModule class
Module information returned by discover():
class MdpModule:
slot: int # slot number
profile_id: int # module Profile ID (high 16 bits of raw)
vendor_id: int # fixed 0: the 0xF050 range has no standalone vendor ID object, the SDK does not invent one
module_type: int # module type (low 16 bits of raw)
revision: int # fixed 0: the 0xF050 range has no standalone revision object, the SDK does not invent one
Methods
discover()
def discover(self) -> Optional[List[MdpModule]]
Performs MDP module discovery: reads the 0xF050 module list object through CoE (count + ident of each slot) and returns a list of MdpModule. The whole 0xF050…0xF05F range is the Detected Module Ident List instance range (ETG.5001.1 §4.2.3.10); there is no standalone vendor ID / revision object, so vendor_id / revision are always 0 (nothing is invented).
Returns: None = the 0xF050 read failed / the list is incomplete (unknown, not "no modules"); empty list = the slave explicitly answered 0 modules.
rescan()
def rescan(self) -> Optional[List[MdpSlotInfo]]
Rescans the configured (0xF030) and detected (0xF050) module lists, clears the index distance / maximum module count cache and returns the detected module list. None = the 0xF050 read failed (unknown, not "no modules"); empty list = the slave explicitly answered 0 modules.
check_module_match()
def check_module_match(self) -> Tuple[Optional[bool], int]
Implemented by the underlying library; checks whether the configured modules match the detected modules.
Returns:
Tuple[Optional[bool], int]—(is_match, first_mismatch_slot).is_match=Trueall match;Falseexplicitly mismatched (the second item is the first mismatching slot);None= undeterminable (the object does not exist on one side / the read failed or the list is incomplete / wrong parameter), in which case the slot is-1. Undeterminable is neither a match nor a mismatch, and the caller must display it as such.
Example:
ok, mismatch_slot = slave.mdp.check_module_match()
if ok is None:
print("模块一致性无法判定(读取失败 / 列表不完整),不要当成匹配或不匹配") # Module consistency cannot be determined (read failed / incomplete list); do not treat it as a match or a mismatch
elif not ok:
print(f"模块配置不一致, 首个不匹配槽位: {mismatch_slot}") # Module configuration mismatch, first mismatching slot: {mismatch_slot}
get_module_pdo_layout()
def get_module_pdo_layout(self) -> Optional[List[MdpModulePdoInfo]]
Gets the PDO layout of each module in the slave process image (input/output byte counts and offsets). The byte size of each PDO is provided by the master library; it is split evenly across the module slots and accumulated to compute the byte offset of each module in the process image. Returns None when there are no usable modules or the read failed.
MdpModulePdoInfo class:
class MdpModulePdoInfo:
slot_index: int # slot index
input_offset: int # byte offset of the input PDO in the process image
input_size: int # input byte count
output_offset: int # byte offset of the output PDO in the process image
output_size: int # output byte count
Example:
layout = slave.mdp.get_module_pdo_layout()
if layout:
for info in layout:
print(f"Slot {info.slot_index}: "
f"输入 {info.input_size}B @{info.input_offset}, " # Input {info.input_size}B @{info.input_offset},
f"输出 {info.output_size}B @{info.output_offset}") # Output {info.output_size}B @{info.output_offset}
auto_configure_from_detected_modules()
def auto_configure_from_detected_modules(self) -> int
Configures automatically from the detected modules: reads 0xF050 (detected modules) and writes each one into 0xF030 (configured modules) so that the configured list matches the physical reality.
Returns:
int— number of modules configured successfully;0means no modules were detected;-1means the write failed
Example:
n = slave.mdp.auto_configure_from_detected_modules()
if n > 0:
print(f"已按物理实际配置 {n} 个模块") # Configured {n} modules to match the physical reality
elif n < 0:
print("模块配置写入失败") # Failed to write the module configuration
auto_enumerate()
def auto_enumerate(self) -> int
Triggers MDP automatic enumeration (master level). It reads the 0xF030 (Config) / 0xF050 (Detected) module lists of all slaves and compares them for consistency; the underlying library performs the automatic enumeration. This interface applies to the whole master, not to a single slave.
Returns:
int— return code (>=0is the number of enumerated modules/slaves,<0indicates failure)
Example:
rc = slave.mdp.auto_enumerate()
if rc < 0:
print("MDP 自动枚举失败") # MDP auto-enumeration failed
Automatic configuration
Automatic configuration of MDP devices requires importing the matching ESI file first:
- Import the ESI (master) —
master.set_esi_file()/master.set_esi_files() - Automatic SM configuration (master) —
master.enable_auto_startup()(runs duringbuild(); it only performs automatic configuration of the slave SM physical parameters and does not orchestrate MDP modules) - Import the ESI (slave) —
slave.set_esi_file()
Chained example (note that set_network() returns the number of slaves and must be on its own line):
from darra_ethercat import EtherCATMaster, EcState
master = EtherCATMaster()
# set_network() returns the number of discovered slaves (int), not master, so it cannot be chained
count = master.set_network(r"\Device\NPF_{GUID}")
# the remaining configuration methods return master and can stay chained
master = (master
.set_esi_files(r"C:\EtherCAT\ESI")
.enable_auto_startup() # only configures the slave SM physical parameters automatically, does not orchestrate MDP modules
.build())
master.set_state(EcState.OP)
Failures and handling
| Symptom | Cause | Handling |
|---|---|---|
| Fewer detected modules than actually present, or none at all | The slave does not perform module detection, or the ENI has no module definitions | Build the network with DENI and import the matching ESI, then rebuild and re-read with rescan / discover; first confirm that slave.has_mdp is True |
| Configured and detected modules do not match | A module was replaced but the configuration was not updated | Reconfigure from the physical reality: slave.mdp.auto_configure_from_detected_modules(), or re-import the DENI |
| PDO offsets do not match the actual modules | The PDO layout in the ENI/DENI does not match the current modules | Rebuild after reconfiguring the modules, then read get_module_pdo_layout |
| configured_modules or detected_modules returns None | The read failed or the list is incomplete (unknown, not "no modules") | Read the property again; if it is still None, display it as unknown and do not treat it as 0 modules |