MDP — Modular devices
The Modular Device Profile (MDP) is the standard EtherCAT protocol for describing modular devices (ETG.5001).
Accessed through slave.MDP(). The sub-object is created lazily and always returns an instance (never null); check whether the slave supports MDP with slave.hasMDP().
The SDK handles module detection and PDO configuration for MDP devices automatically. In the vast majority of scenarios, users do not need to work with MDP directly.
The master can detect and configure modular devices (GCAN-8200 and similar) automatically when entering OP.
enableAutoStartup() is a master-level chainable entry point (a method of EtherCATMaster; MDP does not have this method): once enabled, the SDK reads the detected modules automatically and sends the corresponding startup parameters, with no manual MDP work.
The SDK supports reconfiguration self-repair after an MDP module hot-plug.
In production environments, however, hot-plugging MDP modules is almost never a real scenario.
The module configuration of an EtherCAT slave is fixed once the device is powered on and does not change dynamically at runtime.
DENI is recommended for deploying MDP modular devices;
if automatic configuration is required, import the corresponding ESI file first, then call the master enableAutoStartup() when creating the master.
Method overview
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| Module lists | configuredModules() | List<MDP.MdpSlotInfo> | read-only | Configured modules (0xF030); an empty list = explicitly 0 modules, null = read failure / unknown |
| Module lists | detectedModules() | List<MDP.MdpSlotInfo> | read-only | Detected modules (0xF050); an empty list = explicitly 0 modules, null = read failure / unknown |
| Module lists | detectModules() | List<MDP.MdpSlotInfo> | read-only | Alias of detectedModules() with identical behavior |
| Identity arrays | configModuleIdents() | int[] | read-only | Raw array of configured module ident codes |
| Identity arrays | detectedModuleIdents() | int[] | read-only | Raw array of detected module ident codes |
| Validation | checkModuleMatch() | int | read-only | 1 = match, 0 = mismatch, 2 / 3 / -1 = cannot be determined |
| PDO layout | getModulePdoLayout() | List<MDP.MdpModulePdoInfo> | read-only | Input/output offset and byte count of each module; returns null when it cannot be determined |
| Refresh | rescan() | List<MDP.MdpSlotInfo> | read-only | Clears the cache and re-reads the detected modules |
| Refresh | invalidateStaticCache() | void | write-only | Clears the read cache for the module index distance / maximum module count |
| Device information | moduleIndexDistance() | short | read-only | Module index distance (0xF000:01); when it cannot be read, the ETG.5001.1 default 0x0010 is used |
| Device information | maxModuleCount() | short | read-only | Maximum module count (0xF000:02); 0 = unknown |
| Optional modules | availableModules() | List<MDP.MdpAvailableModule> | read-only | Optional modules declared by the ESI; currently always an empty list |
| Auto start | master.enableAutoStartup() | EtherCATMaster | write-only | Master-level chainable entry point (not an MDP method; MDP has no enableAutoStartup); detects and configures modular devices automatically when entering OP |
Properties
configuredModules()
public List<MDP.MdpSlotInfo> configuredModules()
Configured module list (0xF030). Every call reads again and never returns a cached copy.
Returns:
List<MDP.MdpSlotInfo>— configured module list. An empty list = the slave explicitly answers 0 modules;null= read failure / unknown (unknown is not the same as "no modules configured")
Related structures:
MDP.MdpSlotInfo fields:
| Field | Type | Read/write | Description |
|---|---|---|---|
| SlotIndex | int | read-only | Slot index (starting at 1) |
| ModuleIdent | int | read-only | Module ident code (32-bit) |
| ModuleName | String | read-only | Module name; the Java side does not implement ESI module name parsing, so it is currently formatted ident text (for example Module 0x00000001) |
| ModuleType | int | read-only | Module device type code; on the Java side it currently has the same value as ModuleIdent |
| Status | String | read-only | Status: "已配置" (SDK output, = configured) (from configuredModules()) / "已检测" (SDK output, = detected) (from detectedModules()) |
| ObjectDictionaryIndex | short | read-only | Object dictionary base address = module index distance × slot index |
| ModuleIOType | String | read-only | Module I/O type ("Input" / "Output" / "I/O" / "Unknown"); the Java side does not implement the ESI TxPdo / RxPdo determination, so it is always "Unknown" |
Example:
for (MDP.MdpSlotInfo slot : slave.MDP().configuredModules()) {
System.out.printf("Slot %d: %s (0x%08X)%n",
slot.SlotIndex, slot.ModuleName, slot.ModuleIdent);
}
detectedModules()
public List<MDP.MdpSlotInfo> detectedModules()
Detected module list (0xF050), reflecting the modules physically inserted. Every call reads again and never returns a cached copy.
Returns:
List<MDP.MdpSlotInfo>— detected module list (same structure asconfiguredModules()). An empty list = the slave explicitly answers 0 modules;null= read failure / unknown (unknown is not the same as "no modules")
detectModules() and detectedModules() are two entry points for the same capability with fully identical behavior; new code should use detectedModules().
Example:
for (MDP.MdpSlotInfo slot : slave.MDP().detectedModules()) {
System.out.printf("Slot %d: %s%n", slot.SlotIndex, slot.ModuleName);
}
availableModules()
public List<MDP.MdpAvailableModule> availableModules()
List of optional modules declared in the ESI.
"Optional modules declared in the ESI" requires the SDK to parse the ESI <Modules> XML node; the Java SDK does not implement that parsing capability, so this method honestly returns an empty list (it invents no data and throws no exception).
To query detected modules use detectedModules(), and to query configured modules use configuredModules() — both of these read real data from the underlying layer.
Returns:
List<MDP.MdpAvailableModule>— optional module list (currently always an empty list)
Related structures:
MDP.MdpAvailableModule fields:
| Field | Type | Read/write | Description |
|---|---|---|---|
| ModuleIdent | int | read-only | Module ident code |
| ModuleType | int | read-only | Module device type code |
| ModuleName | String | read-only | Module name |
| Description | String | read-only | Module description |
Methods
configModuleIdents() / detectedModuleIdents()
public int[] configModuleIdents()
public int[] detectedModuleIdents()
Reads the raw ModuleIdent arrays directly from 0xF030 (configured) / 0xF050 (detected). configuredModules() / detectedModules() assemble their results from these.
Returns:
int[]— module ident code array. An empty array = the slave explicitly answers 0 modules;null= read failure / unknown (unknown is not the same as "no modules")
checkModuleMatch()
public int checkModuleMatch()
Checks whether the configured module list (0xF030) and the detected module list (0xF050) match (the semantics of ETG.5001 AL 0x0035 ModuleIdListMismatch).
Returns:
| Return value | Meaning |
|---|---|
1 | Exact match |
0 | Mismatch (the first mismatching slot is written to the log) |
2 | Cannot be determined (the object does not exist on one side) |
3 | Cannot be determined (read failure / incomplete list) |
-1 | Invalid argument, or neither side could be read |
2 / 3 / -1 are neither "match" nor "mismatch"; the caller must display them as "cannot be determined" and must not use them as a match or a mismatch.
getModulePdoLayout()
public List<MDP.MdpModulePdoInfo> getModulePdoLayout()
Gets the PDO layout of each module in the slave IOmap: the input/output byte offset and byte count of each module are accumulated from the PDO Assignment (0x1C12 / 0x1C13) and PDO Mapping entries.
It requires the slave to be configured through DENI (available after ConfigMap) and does not depend on an ESI file. It returns null when reading the detected modules fails, when there are explicitly 0 modules, or when the PDOs cannot be read.
Returns:
List<MDP.MdpModulePdoInfo>— PDO layout information of each module; returnsnullwhen it cannot be determined (nullmeans "cannot be determined", not "no PDOs")
Related structures:
MDP.MdpModulePdoInfo fields:
| Field | Type | Read/write | Description |
|---|---|---|---|
| SlotIndex | int | read-only | Slot index |
| InputOffset | int | read-only | Input PDO offset (relative to the slave input area offset) |
| InputSize | short | read-only | Input PDO byte count |
| OutputOffset | int | read-only | Output PDO offset (relative to the slave output area offset) |
| OutputSize | short | read-only | Output PDO byte count |
Example:
List<MDP.MdpModulePdoInfo> layout = slave.MDP().getModulePdoLayout();
if (layout != null) {
for (MDP.MdpModulePdoInfo mod : layout) {
System.out.printf("Slot %d: In=%dB @%d, Out=%dB @%d%n",
mod.SlotIndex, mod.InputSize, mod.InputOffset,
mod.OutputSize, mod.OutputOffset);
}
}
Refresh and cache
rescan()
public List<MDP.MdpSlotInfo> rescan()
Clears the cache and re-reads the modules currently inserted, equivalent to invalidateStaticCache() followed by detectedModules(). Call it when the list of physically inserted modules must be refreshed after plugging or unplugging modules at runtime.
Returns:
List<MDP.MdpSlotInfo>— detected module list. An empty list = explicitly 0 modules;null= read failure / unknown
invalidateStaticCache()
public void invalidateStaticCache()
Clears the device information cached by this object (module index distance, maximum module count) so that the next read fetches it from the slave again. It does not clear any data on the slave side.
Device information
moduleIndexDistance()
public short moduleIndexDistance()
Module index distance (0xF000:01): the object dictionary address of each slot = module index distance × slot index. The ETG.5001.1 default is 0x0010 (16); when it cannot be read, that default is returned (and the log states that it is a fallback value).
Returns:
short— module index distance
maxModuleCount()
public short maxModuleCount()
Maximum module count (0xF000:02).
Returns:
short— maximum module count; a failed read returns0(0means unknown and does not mean the device reports 0 modules)
Automatic configuration
Automatic configuration of MDP devices requires the corresponding ESI file to be imported first, and is performed by the following methods:
- Import ESI (master) —
setEsiFile()/setEsiFiles() - Automatic orchestration (master) —
enableAutoStartup(): detects and configures modular devices automatically when entering OP - Rescan (slave) —
slave.MDP().rescan()re-reads the modules and clears the cache - Clear cache (slave) —
slave.MDP().invalidateStaticCache()clears the module scan cache
Full example
import com.darra.ethercat.master.EtherCATMaster;
import com.darra.ethercat.slave.MDP;
import com.darra.ethercat.slave.Slave;
import java.util.List;
EtherCATMaster.BuildResult r = EtherCATMaster.create()
.setEsiFiles("C:/EtherCAT/Esi") // import the ESI directory
.setENI("C:/EtherCAT/MyProject.deni")
.enableAutoStartup() // orchestrate OP modules automatically when entering MDP
.build();
// Judge success only by success: r.master is null when configuration is missing / the file cannot be read (using .master directly would NPE);
// success is also false when the slave count is 0, but master still points to the current instance
if (!r.success) {
System.out.println("构建失败: " + r.message); // (SDK output, = Build failed: )
return;
}
EtherCATMaster master = r.master;
// The DENI path does not populate the slave list: construct the slave object directly from the master index + station number
Slave slave = new Slave(master.MasterIndex, (short) 1, master);
MDP mdp = slave.MDP();
// Manual detection: re-read the currently inserted modules
List<MDP.MdpSlotInfo> detected = mdp.rescan();
if (detected != null) {
for (MDP.MdpSlotInfo slot : detected) {
System.out.printf("槽位 %d: %s (0x%08X)%n", slot.SlotIndex, slot.ModuleName, slot.ModuleIdent); // Slot %d: %s (0x%08X)%n
}
}
// Whether the configured modules match the physically inserted modules (1 = match)
int match = mdp.checkModuleMatch();
if (match == 0) {
System.out.println("模块配置与实插不一致,需要重新配置"); // The module configuration does not match what is actually inserted, reconfiguration is needed
} else if (match != 1) {
System.out.println("无法判定模块是否一致: " + match); // Cannot determine whether the modules match: {match}
}
// PDO layout of each module
List<MDP.MdpModulePdoInfo> layout = mdp.getModulePdoLayout();
if (layout != null) {
for (MDP.MdpModulePdoInfo mod : layout) {
System.out.printf("槽位 %d: 输入 %d 字节 @%d, 输出 %d 字节 @%d%n", // Slot %d: input %d bytes @%d, output %d bytes @%d%n
mod.SlotIndex, mod.InputSize, mod.InputOffset,
mod.OutputSize, mod.OutputOffset);
}
}
Failures and handling
| Symptom | Cause | Handling |
|---|---|---|
The module list returns null | Read failure (timeout / no response / the object does not exist / incomplete list), not "no modules" | Call configuredModules() or rescan() again; if it still fails, check the slave communication state |
| The module list is empty | The slave explicitly answers 0 modules | Send the module configuration through DENI; when the slave has an ESI, import the ESI and enable the master enableAutoStartup() |
checkModuleMatch() returns 0 | The configured modules and the physically inserted modules do not match | Reconfigure according to the physically inserted modules, then enable the master enableAutoStartup() |
checkModuleMatch() returns 2 / 3 / -1 | Cannot be determined (the object does not exist on one side / read failure / invalid argument) | Display "cannot be determined" and retry the read; do not treat it as a match or a mismatch |
getModulePdoLayout() returns null | The detected modules cannot be read / there are explicitly 0 modules / the PDOs cannot be read | Call rescan() first to confirm the modules are present, reconfigure the modules, then read again |