MDP — Modular device
Modular Device Profile (MDP, ETG.5001) is the standard protocol for describing modular devices in EtherCAT. An MDP slave (such as the GCAN-8200 or a Beckhoff EK coupler) consists of several pluggable modules, and each module occupies an address range in the object dictionary.
When entering OP, the SDK orchestrates the module configuration of MDP slaves automatically (detect physical modules → compare against the configured list → write back when necessary). Devices such as the GCAN-8200 only need an imported ESI or a DENI; in the vast majority of scenarios there is no need to work with the MDP API manually.
Module-level API
The MDP features of the Rust SDK are provided as free functions in the darra_ethercat::slave::mdp module, not as methods on the slave object. All functions locate a slave with master_index + slave_index (1-based).
use darra_ethercat::slave::mdp::{
mdp_discover, mdp_discover_safety, mdp_is_mdp_device,
read_configured_address_list, read_detected_address_list,
read_module_profile_list, get_module_pdo_layout,
is_module_config_consistent, check_module_match,
auto_enumerate, auto_configure_from_detected_modules,
MdpModule, MdpModuleClass, MdpModuleProfile, MdpModulePdoInfo,
};
Detecting a device
mdp_is_mdp_device()
pub fn mdp_is_mdp_device(master_index: u16, slave_index: u16) -> bool
Determines whether a slave is an MDP modular device by the readability of 0xF000:00.
Discovering modules
mdp_discover()
pub fn mdp_discover(master_index: u16, slave_index: u16) -> Result<Vec<MdpModule>>
Reads 0xF050 (module description list) to discover all MDP modules of the slave. The slave must be in PreOp or higher.
pub struct MdpModule {
pub module_number: u8, // module number (1-based, matches the 0xF050 subindex)
pub vendor_id: u32, // vendor ID
pub product_code: u32, // product code
pub revision_no: u32, // revision
pub module_class: MdpModuleClass, // module class (enum)
pub raw_ident: u32, // raw module identifier (full u32 value of 0xF050:sub)
}
impl MdpModule {
pub fn is_safety(&self) -> bool; // whether this is an FSoE functional safety module
pub fn is_drive(&self) -> bool; // whether this is a drive axis module
}
The module class is the MdpModuleClass enum, parsed from the upper 16 bits of raw_ident:
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MdpModuleClass {
DigitalInput = 0x0001, // digital input
DigitalOutput = 0x0002, // digital output
AnalogInput = 0x0003, // analog input
AnalogOutput = 0x0004, // analog output
CounterInput = 0x0005, // counter input
DriveAxis = 0x0006, // drive axis
FunctionalSafety = 0x0007, // functional safety (FSoE)
EncoderInterface = 0x0008, // encoder interface
CommunicationBridge = 0x0009, // communication bridge
Unknown = 0xFFFF, // unknown class
}
MdpModule and MdpModuleClass both implement Display and can be formatted directly.
mdp_discover_safety()
pub fn mdp_discover_safety(master_index: u16, slave_index: u16) -> Result<Vec<MdpModule>>
Returns only the functional safety modules that support FSoE (the mdp_discover() result filtered by is_safety()).
Example:
use darra_ethercat::slave::mdp::{mdp_discover, mdp_is_mdp_device};
if mdp_is_mdp_device(master.index(), 1) {
let modules = mdp_discover(master.index(), 1)?;
for m in &modules {
// Display: "module[01] class:digital input VID:0x... PC:0x... Rev:0x..."
println!("{}", m);
}
}
Module address lists
read_configured_address_list() / read_detected_address_list()
pub fn read_configured_address_list(master_index: u16, slave_index: u16) -> Result<Vec<u32>>
pub fn read_detected_address_list(master_index: u16, slave_index: u16) -> Result<Vec<u32>>
Return the module identifier (ident) list of each slot:
- configured — configured module list (
0xF030, read by the runtime) - detected — detected module list, reflecting the modules that are physically inserted (
0xF050, read by the runtime)
read_module_profile_list()
pub fn read_module_profile_list(master_index: u16, slave_index: u16) -> Result<Vec<MdpModuleProfile>>
Reads the module Profile list (0xF010) and also reads the corresponding module identifier from 0xF050. The slave must be in PreOp or higher.
pub struct MdpModuleProfile {
pub slot_index: u8, // slot index (subindex, 1-based)
pub profile_number: u32, // Profile Number (u32 value of 0xF010:sub)
pub module_ident: u32, // module identifier (the corresponding value read from 0xF050)
}
Module consistency check
is_module_config_consistent()
pub fn is_module_config_consistent(master_index: u16, slave_index: u16) -> bool
Checks whether the configured modules match the detected modules (performed by the runtime). Equivalent to the ETG.5001 ModuleIdListMismatch (AL 0x0035) check semantics.
check_module_match()
pub fn check_module_match(master_index: u16, slave_index: u16) -> Option<(bool, i32)>
Validates the module lists and returns Option<(is_match, first_mismatch_slot)>: None means the underlying call failed (<0 in the underlying tri-state), and only Some((is_match, first_mismatch_slot)) is a validation result. On a mismatch, first_mismatch_slot is a 0-based slot index.
Module PDO layout
get_module_pdo_layout()
pub fn get_module_pdo_layout(master_index: u16, slave_index: u16) -> Result<Vec<MdpModulePdoInfo>>
Gets the PDO layout of each module in the slave IOmap. It reads the PDO Assignment (0x1C12/0x1C13) and PDO Mapping entries over CoE and accumulates the byte offset of each module. Offsets in the return value are relative to slave.input_offset() / slave.output_offset() (u32, byte offsets relative to the whole IOmap).
pub struct MdpModulePdoInfo {
pub slot_index: u8, // slot index
pub input_offset: u32, // input PDO offset
pub input_size: u16, // input PDO byte count
pub output_offset: u32, // output PDO offset
pub output_size: u16, // output PDO byte count
}
Example:
use darra_ethercat::slave::mdp::get_module_pdo_layout;
let layout = get_module_pdo_layout(master.index(), 1)?;
for m in &layout {
println!("Slot {}: In={}B @{}, Out={}B @{}",
m.slot_index, m.input_size, m.input_offset,
m.output_size, m.output_offset);
}
Automatic orchestration and configuration
auto_enumerate()
pub fn auto_enumerate(master_index: u16) -> i32
Automatically enumerates the modules of all MDP slaves under this master (performed by the runtime). Returns the number of slaves/modules enumerated successfully; a negative value means failure.
auto_configure_from_detected_modules()
pub fn auto_configure_from_detected_modules(master_index: u16, slave_index: u16) -> Result<u8>
Configures automatically from the detected modules: reads 0xF050 (detected modules) and writes them one by one to 0xF030 (configured modules) so that the configured list matches the detected list. Returns the number of modules written successfully. The slave must be in PreOp and support 0xF030 writes.
Configuration of MDP devices is best done through a DENI file (exported by the Darra configuration tool) or by importing the matching ESI file:
- Import ESI —
EtherCATMaster::builder().set_esi_file(path)(see Initialization) - Master automatic startup parameters —
EtherCATMaster::builder().enable_auto_startup()
When entering OP, the SDK orchestrates MDP modules automatically; auto_enumerate() / auto_configure_from_detected_modules() are only for explicit control in tooling applications or diagnostic scripts.
The SDK supports self-healing reconfiguration after an MDP module hot-plug. In production, however, MDP module hot-plug scenarios almost never occur — the module configuration of an EtherCAT slave is fixed once the device is powered on and does not change dynamically during operation.
Complete example
use darra_ethercat::{EtherCATMaster, EcState};
use darra_ethercat::slave::mdp::{
mdp_is_mdp_device, mdp_discover,
read_configured_address_list, read_detected_address_list,
get_module_pdo_layout, check_module_match, auto_enumerate,
};
fn main() -> darra_ethercat::Result<()> {
// build() returns BuildResult (implements Deref only, no DerefMut).
// set_state needs &mut self, so take the owned EtherCATMaster out of .master and bind it with let mut.
let mut master = EtherCATMaster::builder()
.set_eni(r"C:\EtherCAT\MyProject.deni")
.build()?
.master;
master.set_state(EcState::PreOp)?;
// before entering OP, let the MDP slaves finish automatic module enumeration
let enumerated = auto_enumerate(master.index());
println!("MDP 自动枚举: {} 项", enumerated); // MDP auto-enumeration: {} items
let slave_count = master.slave_count();
for i in 1..=slave_count {
if !mdp_is_mdp_device(master.index(), i) {
continue;
}
println!("从站 {} 是 MDP 设备", i); // Slave {} is an MDP device
// discover modules
for m in &mdp_discover(master.index(), i)? {
println!(" {}", m);
}
// configured / detected comparison
let configured = read_configured_address_list(master.index(), i)?;
let detected = read_detected_address_list(master.index(), i)?;
println!(" 已配置 {} 个, 已检测 {} 个", configured.len(), detected.len()); // {} configured, {} detected
// check_module_match returns Option: None means the underlying call failed
match check_module_match(master.index(), i) {
Some((true, _)) => {}
Some((false, first_mismatch)) => {
println!(" ⚠ 模块列表不一致, 首个不匹配槽位: {}", first_mismatch); // ⚠ Module list mismatch, first mismatching slot: {}
}
None => println!(" ⚠ 模块一致性校验调用失败"), // ⚠ Module consistency check call failed
}
// PDO layout
for m in &get_module_pdo_layout(master.index(), i)? {
println!(" PDO: Slot {} In={}B @{}, Out={}B @{}",
m.slot_index, m.input_size, m.input_offset,
m.output_size, m.output_offset);
}
}
master.set_state(EcState::Operational)?;
Ok(())
}