MDP — modular devices
Modular Device Profile (MDP, ETG.5001) is the standard EtherCAT protocol for describing modular devices.
Get the MDP* pointer with slave.GetMDP(). It returns nullptr when the slave does not support MDP, so check for null before use.
On entering OP, master.SetState(EcState::OP) triggers MDP modular device setup automatically:
it detects the physical modules, writes the configured module list (0xF030) and configures the corresponding SM/PDO.
MDP devices such as the GCAN-8200 need no manual write of 0xF030, which avoids SM3 length=0 causing AL=0x001E when entering SafeOp.
In most scenarios you do not need to operate the MDP class directly.
The SDK supports reconfiguration and self-repair after an MDP module hot-plug. In production, however, MDP module hot-plug is almost never used. An EtherCAT slave's module configuration is fixed once the device is powered up and does not change at runtime. For deploying MDP modular devices, DENI is recommended.
Getting an MDP instance
auto& slave = master.GetSlave(1);
MDP* mdp = slave.GetMDP(); // Returns nullptr when the slave does not support MDP
if (!mdp) {
printf("从站 1 不是 MDP 模块化设备\n"); // Slave 1 is not an MDP modular device
return;
}
GetMDP() returns a non-null pointer only when slave.HasMDP() is true; the instance is created lazily and later calls return the same cached object.
Properties
ConfiguredModules()
std::vector<MdpSlotInfo> ConfiguredModules() const;
The configured module list (object index 0xF030). The underlying library reads each slot's module identification code directly.
Returns:
std::vector<MdpSlotInfo>— the configured module list
Related structure:
struct MdpSlotInfo {
int SlotIndex; // Slot index (from 1)
uint32_t ModuleIdent; // Module identity code (32-bit)
std::string ModuleName; // Module name
uint32_t ModuleType; // Module device type code
std::string Status; // Status ("已配置" / "已检测") (SDK output, = configured / detected)
uint16_t ObjectDictionaryIndex; // Object dictionary base address
std::string ModuleIOType; // I/O type (defaults to "Unknown")
std::string ToString() const; // Formatted as "Slot N: name (0xIDENT)"
};
Example:
MDP* mdp = slave.GetMDP();
if (!mdp) return;
for (auto& slot : mdp->ConfiguredModules()) {
printf("%s\n", slot.ToString().c_str());
}
DetectedModules()
std::vector<MdpSlotInfo> DetectedModules() const;
The detected module list (object index 0xF050), reflecting the modules physically inserted. Read directly by the underlying library.
Returns:
std::vector<MdpSlotInfo>— the detected module list (same structure asConfiguredModules)
Example:
MDP* mdp = slave.GetMDP();
if (mdp) {
for (auto& slot : mdp->DetectedModules())
printf("Slot %d: %s\n", slot.SlotIndex, slot.ModuleName.c_str());
}
GetAvailableModules()
std::vector<MdpAvailableModule> GetAvailableModules() const;
The available module list, derived from DetectedModules() (each detected module maps to one available-module record).
Returns:
std::vector<MdpAvailableModule>— the available module list
Related structure:
struct MdpAvailableModule {
uint32_t ModuleIdent; // Module identity code
uint32_t ModuleType; // Module device type code
std::string ModuleName; // Module name
std::string Description; // Module description
};
Example:
MDP* mdp = slave.GetMDP();
if (mdp) {
for (auto& mod : mdp->GetAvailableModules())
printf("%s (0x%08X)\n", mod.ModuleName.c_str(), mod.ModuleIdent);
}
ModuleIndexDistance() / MaxModuleCount()
uint16_t ModuleIndexDistance() const; // 0xF000:01, module index spacing, default 0x0010
uint16_t MaxModuleCount() const; // 0xF000:02, maximum number of modules
Reads the core properties of the ETG.5001 Modular Device Profile object 0xF000; results are cached.
Methods
GetModulePdoLayout()
std::vector<MdpModulePdoInfo> GetModulePdoLayout() const;
Gets the PDO layout of each module in the slave IOmap. It reads the byte size of every PDO in the PDO assignment (0x1C12/0x1C13) through ReadPdoAssignmentSizes (enumeration and per-PDO sizes are done by the runtime library; the wrapper does not read mapping entries itself) and accumulates the byte offset of each module in positional order.
Requires the slave to be configured with DENI (available after ConfigMap); ESI files are not needed. Returns an empty vector when CoE is unavailable or no module is detected.
Returns:
std::vector<MdpModulePdoInfo>— PDO layout information for each module; an empty vector when it cannot be read
Related structure:
struct MdpModulePdoInfo {
int SlotIndex; // Slot index
uint32_t InputOffset; // Input PDO offset
uint16_t InputSize; // Input PDO byte count
uint32_t OutputOffset; // Output PDO offset
uint16_t OutputSize; // Output PDO byte count
};
Example:
MDP* mdp = slave.GetMDP();
if (mdp) {
for (auto& mod : mdp->GetModulePdoLayout())
printf("Slot %d: In=%uB @%u, Out=%uB @%u\n",
mod.SlotIndex, mod.InputSize, mod.InputOffset,
mod.OutputSize, mod.OutputOffset);
}
Discover()
std::vector<MdpDiscoveredModule> Discover() const;
Discovers MDP modules quickly through the DLL C advanced API and returns each slot's module profile, identification code and PDO offset information.
Related structure:
struct MdpDiscoveredModule {
uint16_t SlotIndex; // Slot index
uint16_t ModuleProfile; // Module Profile
uint16_t ModuleIdent; // Module identity code
uint16_t PdoInputOffset; // Input PDO offset
uint16_t PdoInputSize; // Input PDO byte count
uint16_t PdoOutputOffset; // Output PDO offset
uint16_t PdoOutputSize; // Output PDO byte count
};
DetectModules() / IsModuleConfigConsistent()
bool DetectModules() const; // Trigger the slave to re-scan the installed modules (write 0xF002:00)
bool IsModuleConfigConsistent() const; // Whether the configured modules match the detected modules
AutoConfigureFromDetectedModules()
int AutoConfigureFromDetectedModules() const;
Writes the detected modules (0xF050) into the configured module list (0xF030) to complete automatic configuration.
Returns:
int— number of modules configured successfully;-1means failure
On entering OP, master.SetState() already runs the MDP setup, so you usually do not need to call AutoConfigureFromDetectedModules() manually.
Automatic configuration
When an MDP device enters OP, master.SetState(EcState::OP) completes the module setup automatically (detect → write 0xF030 → configure SM/PDO).
Recommended deployment:
- Use DENI — export it from the Darra configuration tool; loading it with
master.SetENI("xxx.deni")brings the complete MDP configuration
EtherCATMaster itself has no ESI file loading member; loading at runtime is handled by darra::EsiManager. Slave information can also be read automatically from EEPROM during a scan, or taken from the ENI/DENI configuration file loaded by
SetENI().