Skip to main content

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 MDP

master.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().

About hot-plug

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​

CategoryMethodTypeRead/writeDescription
Module listconfigured_moduleslist or Noneread-onlyConfigured modules; None means the read failed, not that there are no modules
detected_moduleslist or Noneread-onlyModules physically inserted; None as above
Module detectiondiscoverlist or Noneread-onlyReads 0xF050 and returns a list of MdpModule (slot / profile_id / module_type)
rescanlist or Noneread-onlyRescans the configured and detected lists and returns the detected slots
Validationcheck_module_match(bool or None, int)read-onlyCompares 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 layoutget_module_pdo_layoutlist or Noneread-onlyInput/output offsets and byte counts of each module in the process image
Configuration write-backauto_configure_from_detected_modulesintwrite-onlyRewrites 0xF030 from the detection result (four-step sequence); returns the number of modules written on success, -1 on failure
Automatic enumerationauto_enumerateintwrite-onlyMaster-level automatic enumeration and comparison of the module lists of all slaves; >=0 is the enumerated count, <0 failure

Properties​

CategoryPropertyTypeRead/writeDescription
Module listconfigured_modulesOptional[List[MdpSlotInfo]]read-onlyConfigured module list (implemented by the underlying library, 0xF030); None = the read failed / undeterminable (unknown, not "no modules")
detected_modulesOptional[List[MdpSlotInfo]]read-onlyDetected module list, reflecting what is physically inserted (implemented by the underlying library, 0xF050); None = the read failed / undeterminable
config_module_identsOptional[List[int]]read-onlyReads the 0xF030 ConfigModuleIdent array through the underlying library; None = unknown
detected_module_identsOptional[List[int]]read-onlyReads the 0xF050 DetectedModuleIdent array through the underlying library; None = unknown
modulesList[MdpModule]read-onlySnapshot of the most recent discover() result
Device propertiesmodule_index_distanceintread-onlyModule object dictionary index distance (0xF000:01; falls back to 0x0010 when unreadable or 0)
max_module_countintread-onlyMaximum 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=True all match; False explicitly 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; 0 means no modules were detected; -1 means 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 (>=0 is the number of enumerated modules/slaves, <0 indicates 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 during build(); 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​

SymptomCauseHandling
Fewer detected modules than actually present, or none at allThe slave does not perform module detection, or the ENI has no module definitionsBuild 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 matchA module was replaced but the configuration was not updatedReconfigure from the physical reality: slave.mdp.auto_configure_from_detected_modules(), or re-import the DENI
PDO offsets do not match the actual modulesThe PDO layout in the ENI/DENI does not match the current modulesRebuild after reconfiguring the modules, then read get_module_pdo_layout
configured_modules or detected_modules returns NoneThe 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