跳到主要内容

MDP — 模块化设备

Modular Device Profile (MDP) 是 EtherCAT 中描述模块化设备的标准协议。

通过 slave.mdp 访问。从站不支持 MDP 时为 None

自动处理

内部会自动处理 MDP 设备的模块检测和 PDO 配置。 绝大多数场景下,用户无需直接操作 MDP。

关于热插拔

SDK 支持 MDP 模块热插拔再配置自修复。 但生产环境中几乎不会出现 MDP 模块热插拔的使用场景。 部署 MDP 模块化设备推荐使用 DENI; 如需自动配置,请先导入对应的 ESI 文件,再调用 auto_startup()

属性

configured_modules

@property
def configured_modules(self) -> List[MdpSlotInfo]

已配置模块列表。每次访问实时通过 CoE 读取(索引 0xF030)。

MdpSlotInfo 数据类:

@dataclass
class MdpSlotInfo:
slot_index: int # 槽位索引(从 1 开始)
module_ident: int # 模块标识码(32 位)
module_name: str # 模块名称
module_type: int # 模块设备类型码
status: str # 状态("已配置" / "已检测")
object_dictionary_index: int # 对象字典基地址
module_io_type: str # I/O 类型(Input / Output / I/O / Unknown)

示例:

for slot in slave.mdp.configured_modules:
print(f"Slot {slot.slot_index}: {slot.module_name} (0x{slot.module_ident:08X})")

detected_modules

@property
def detected_modules(self) -> List[MdpSlotInfo]

已检测模块列表,反映物理上实际插入的模块。每次访问实时通过 CoE 读取(索引 0xF050)。

示例:

for slot in slave.mdp.detected_modules:
print(f"Slot {slot.slot_index}: {slot.module_name}")

available_modules

@property
def available_modules(self) -> List[MdpAvailableModule]

ESI 中定义的可选模块列表。需要从站已导入 ESI 文件, 否则返回空列表。

相关结构:

@dataclass
class MdpAvailableModule:
module_ident: int # 模块标识码
module_type: int # 模块设备类型码
module_name: str # 模块名称
description: str # 模块描述

示例:

for mod in slave.mdp.available_modules:
print(f"{mod.module_name} (0x{mod.module_ident:08X})")

方法

get_module_pdo_layout()

def get_module_pdo_layout(self, module_index: int) -> Optional[MdpModulePdoInfo]

获取指定模块的 PDO 布局信息(输入/输出字节数和偏移)。

返回值:

@dataclass
class MdpModulePdoInfo:
input_offset: int # 输入 PDO 偏移
input_size: int # 输入字节数
output_offset: int # 输出 PDO 偏移
output_size: int # 输出字节数

自动配置

MDP 设备的自动配置需要先导入对应的 ESI 文件,由以下方法完成:

  • 导入 ESI(主站)set_esi_file() / set_esi_files()
  • 自动配置(主站)enable_auto_startup()
  • 导入 ESI(从站)slave.set_esi_file()
  • 自动配置(从站)slave.auto_startup()