Skip to main content

CiA 402 -- Servo drive support

CiA 402 (IEC 61800-7-204) is the CoE-based device protocol for servo drives. Access it through slave.cia402, which returns a CiA402Advanced instance (a subclass of CiA402): state machine control, PDO mapping scan, typed motion parameter read/write, homing / touch probe / diagnostics all live on the same object.

Only available when the slave supports CoE. Confirm the supported drive modes by reading 0x6502 (supported_drive_modes / is_mode_supported()).

Differences from the base class CiA402

slave.cia402 is a CiA402Advanced, and the signatures on this page refer to it. The base class CiA402 is normally not constructed on its own; its disable() / disable_operation() / quick_stop() return bool, and disable() writes Disable Operation (0x07), whereas the three CiA402Advanced methods return None and its disable() writes Disable Voltage (0x00), fully removing power. The base class also has a mode property (reads 0x6061 / writes 0x6060, throws RuntimeError on a write failure), corresponding to operation_mode on this page.

CSP / synchronized axis hard rules
  • Cyclic synchronous position mode is fixed at 0x6060 = 8; under CSP do not write 0x001F to the control word (bit 4 is NewSetpoint in PP and Homing start in HM; under CSP it stays 0).
  • Use (statusword & 0x6F) == 0x27 for state checks = OperationEnabled; use (statusword & 0x4F) == 0x08 for fault detection (0x4F only looks at faults and cannot judge the operating state).
  • While not enabled, during a handshake or during a group stop, the target position always equals the actual position, to avoid jumps.
  • A fault reset sends 0x86 (bit 7 rising edge, bit 2 held at 1, i.e. 0x80 | 0x06); fault_reset() completes the two phases 0x0006 → 0x0086 within a single call (it contains a 1 ms delay) and must not be called in a PDO callback; when it has to be split across cycles, use fault_reset_step(0) / fault_reset_step(1) in two separate cycles.
  • The normal enable chain is 0x06 → 0x07 → 0x0F (Shutdown → SwitchOn → EnableOperation), one process data cycle per step; do not skip the handshake and write 0x0F directly.
  • Under QuickStopActive 0x06 is ineffective: enable() first writes 0x00 (Disable Voltage) back to SwitchOnDisabled, then follows 0x06 → 0x07 → 0x0F; when 0x605A is 5-8 you can also use request_transition() to send 0x0F directly per T16.
  • Under CSP read the following error from status word bit 13 (0x2000); add the position offset via 0x60B0 position_offset on top of the target position, and do not mix it into the unit conversion of 0x607A.
  • With multiple axes, issue each axis inside the same PDO callback (master.on_pdo_cycle) one after another; do not start a thread per axis. The i in master[i] is the slave index (1-based, in topology order), not the drive axis number.
  • The 0x1F of single-axis PP must not be copied to CSP / synchronized axes; synchronized axes use CSP + DC only.

PDO initialization​

scan_pdo_mapping()​

def scan_pdo_mapping(self) -> bool

Initializes all PDO offset caches. For each direction it queries the byte offset of each signal object in the process image (0x1C12 RxPDO / 0x1C13 TxPDO assignment; the offsets are computed by the underlying library, this layer does not scan the assignment table itself). Returns bool — True means at least one known signal was found (the scan succeeded), False means no mapping was found.

note

This method is not called automatically: without it all access goes through the SDO fallback. To enable the PDO fast path, call scan_pdo_mapping() manually first (usually once before entering OP; after a state downgrade, use reset_pdo_offsets() to clear the cache and rescan).

Example:

drv = slave.cia402
drv.scan_pdo_mapping()
print(f"PDO 映射完成: {drv.is_pdo_mapped}") # PDO mapping complete: {drv.is_pdo_mapped}
print(f"映射信号: {drv.pdo_offsets}") # Mapped signals: {drv.pdo_offsets}

State control​

enable()​

def enable(self, max_retries: int = 10) -> bool

Enables the drive: automatically advances the SwitchOnDisabled → ReadyToSwitchOn → SwitchedOn → OperationEnabled state sequence (control word 0x06 → 0x07 → 0x0F, one process data cycle per step). In the Fault / FaultReaction state it does not perform a Fault Reset automatically; it returns False immediately and you must call fault_reset() explicitly before enabling. Under QuickStopActive 0x06 is ineffective, so it recovers via Disable Voltage (0x00) → Shutdown → SwitchOn → EnableOperation (it does not read 0x605A and does not do T16).

Parameters:

  • max_retries (int) — maximum number of retries (default 10)

Returns:

  • bool — True = enabled up to OperationEnabled, False = failure/timeout/currently in Fault or FaultReaction

disable() / disable_operation() / quick_stop()​

def disable(self) -> None            # write Disable Voltage (0x00), -> SwitchOnDisabled, fully removes power
def disable_operation(self) -> None # write Switch On (0x07), motor stays energized, fast re-enable
def quick_stop(self) -> None # write Quick Stop (0x02), stopping behavior set by 0x605A

All three methods are non-blocking and return no value; a write failure (both the process image and the SDO fail) throws RuntimeError. quick_stop() only sends 0x02: with 0x605A = 1/2 the drive decelerates to SwitchOnDisabled, with 0x605A = 5-8 it stays in QuickStopActive. There are two ways to recover from QuickStopActive: enable() goes 0x00 → 0x06 → 0x07 → 0x0F; request_transition(StateCiA402.OPERATION_ENABLED) sends 0x0F directly per T16 when 0x605A is 5-8 (the caller is responsible for the precondition).

Differences in the base class CiA402

The base class disable() / disable_operation() / quick_stop() return bool (True = command issued), and disable() writes Disable Operation (0x07) instead of Disable Voltage (0x00).

fault_reset()​

def fault_reset(self) -> bool

Clears a fault. Clears the drive fault through a Fault Reset (bit 7) rising edge: the low phase writes CW_SHUTDOWN (0x06) (bit 7 = 0, bit 2 = 1), the high phase writes 0x86 (bit 7 = 1, bit 2 held at 1). Do not write 0x0080 alone (bit 2 = 0 also triggers QuickStop), and do not write 0x0000. In a real-time PDO callback use fault_reset_step() across two cycles instead.

Returns:

  • True — both phase control words were written successfully
  • False — either phase failed to write (the reset signal is incomplete and the fault is not cleared); the failure is logged at WARNING level
  • when the low phase write fails the high phase is not issued (no 0→1 rising edge, so issuing it is meaningless)
Do not hand-write the reset word

The complete reset word issued by fault_reset() / fault_reset_step(1) is 0x86. The class attribute CiA402.CW_FAULT_RESET has the value 0x80 (bit 7 only); writing controlword = drv.CW_FAULT_RESET directly misses bit 2 and may also trigger QuickStop. Call the method to reset; do not hand-write the constant.

Do not call it in a PDO callback

fault_reset() contains a 1 ms sleep and is not suitable for a real-time PDO callback; on the real-time path write CW_SHUTDOWN (0x06) and the reset word 0x86 in two separate cycles, or call fault_reset_step(step).

Example:

cia = slave.cia402

# One-shot enable (state machine handled automatically)
if not cia.enable():
print(f"使能失败, 当前状态: {cia.state}") # Enable failed, current state: {cia.state}

# Disable the drive
cia.disable()

# Fault reset
cia.fault_reset()

# Quick stop
cia.quick_stop()

switch_on()​

def switch_on(self) -> None

Non-blocking issue of Shutdown (0x06), requesting the transition from SwitchOnDisabled to ReadyToSwitchOn. The name refers to the step before Switch On in the CiA 402 enable chain; what it actually writes is not 0x07. It is fully equivalent to ready_to_switch_on(). To reach SwitchedOn, use request_transition(StateCiA402.SWITCHED_ON) or write 0x07 through controlword.

Returns no value; when both the process image and the SDO write fail it throws RuntimeError (the write is never silently dropped).

switch_off()​

def switch_off(self) -> None

Non-blocking issue of Disable Voltage (0x00), requesting SwitchOnDisabled (fully removes power); equivalent to disable() (both write 0x00).

Returns no value; when both the process image and the SDO write fail it throws RuntimeError.

ready_to_switch_on()​

def ready_to_switch_on(self) -> None

Non-blocking issue of Shutdown (0x06), requesting ReadyToSwitchOn; fully equivalent to switch_on() (same control word, same destination).

Returns no value; when both the process image and the SDO write fail it throws RuntimeError.

Example:

from darra_ethercat import StateCiA402

drv.switch_on() # 0x06 -> ReadyToSwitchOn
drv.request_transition(StateCiA402.SWITCHED_ON) # 0x07 -> SwitchedOn
drv.switch_off() # 0x00 -> SwitchOnDisabled

State reading​

state / state_drive​

# Base-class property (SDO path)
@property
def state(self) -> CiA402State

# Property on slave.cia402 (real-time statusword parsing, PDO preferred)
@property
def state_drive(self) -> StateCiA402

Parses the current drive state. state (base-class property) returns CiA402State, parsed from an SDO read of 0x6041; state_drive returns StateCiA402, parsed in real time from statusword (PDO preferred) through StateCiA402.from_statusword. Both use the same enum values and parsing masks, but the read path differs (PDO may be stale or invalid); when txpdo_data_invalid is non-zero, double-check with the SDO-based state. Use state_drive in new code. The two enums have the same numeric values but different member names: CiA402State.FAULT_REACTION corresponds to StateCiA402.FAULT_REACTION_ACTIVE, CiA402State.NOT_READY corresponds to StateCiA402.NOT_READY_TO_SWITCH_ON; do not mix the two types when comparing.

StateCiA402 enum (used by CiA402Advanced.state_drive):

class StateCiA402(IntEnum):
NOT_READY_TO_SWITCH_ON = 0 # initializing
SWITCH_ON_DISABLED = 1 # drive disabled
READY_TO_SWITCH_ON = 2 # ready
SWITCHED_ON = 3 # switched on
OPERATION_ENABLED = 4 # operation enabled
QUICK_STOP_ACTIVE = 5 # quick stop
FAULT_REACTION_ACTIVE = 6 # fault reaction active
FAULT = 7 # fault
UNKNOWN = 99 # unknown state

CiA402State enum (top level of darra_ethercat, used by CiA402.state):

class CiA402State(IntEnum):
NOT_READY = 0 # not ready
SWITCH_ON_DISABLED = 1 # enable off
READY_TO_SWITCH_ON = 2 # ready to enable
SWITCHED_ON = 3 # switched on
OPERATION_ENABLED = 4 # running
QUICK_STOP_ACTIVE = 5 # quick stop
FAULT_REACTION = 6 # fault reaction active
FAULT = 7 # fault
UNKNOWN = 99 # unknown

Example:

state = slave.cia402.state          # CiA402State enum
print(f"驱动器状态: {state.name}") # Drive state: {state.name}

parse_cia402_state()​

from darra_ethercat import parse_cia402_state

def parse_cia402_state(statusword: int) -> StateCiA402

Module-level function: parses the 0x6041 status word into StateCiA402; the parsing logic is the same as StateCiA402.from_statusword() (the four operational states use mask 0x6F, the other states use 0x4F, tolerating drives whose bit 5 is still 1 in SwitchOnDisabled).

Parameters:

  • statusword (int) — raw status word value; truncated to 16 bits (& 0xFFFF), higher bits are ignored

Returns:

  • StateCiA402 — the parsed state; returns StateCiA402.UNKNOWN (99) when nothing matches, without raising
  • throws TypeError when the argument cannot be converted to an integer (such as None)
note

For the live state at runtime prefer state_drive (PDO preferred, no SDO overhead); this function suits log replay, offline captures and similar cases, converting a status word you already have into an enum without accessing the bus.

Example:

from darra_ethercat import parse_cia402_state

sw = slave.cia402.statusword
print(parse_cia402_state(sw).name)

status_word​

@property
def status_word(self) -> int

Reads the status word (0x6041). CiA402Advanced also has a statusword alias that reads PDO first.

control_word​

@property
def control_word(self) -> int

@control_word.setter
def control_word(self, value: int) -> None

Writes the control word (0x6040). Note the read-side semantics: reading does not read back 0x6040 but computes the enable command from the current status word. To read back the actual content of 0x6040, use CiA402Advanced's controlword / control_word_pdo (PDO preferred). The setter of the base CiA402.control_word does not check or report the write result (the underlying return value is ignored and a failure does not throw); for failure detection use the CiA402Advanced.controlword setter, which throws RuntimeError when both the process image and the SDO fallback fail.

Related properties:

  • target_reached (bool) — target reached (Bit 10)
  • has_fault (bool) — fault present (Bit 3)
  • has_warning (bool) — warning present (Bit 7)
  • is_remote (bool) — remote mode active (Bit 9)

Example:

cia = slave.cia402
sw = cia.status_word
print(f"StatusWord: 0x{sw:04X}")

if cia.target_reached:
print("目标已到达") # Target reached
if cia.has_fault:
print("存在故障") # A fault is present

Operation mode​

CategoryPropertyTypeRead/writeDescription
Operation modesupported_bitintread-onlyBit index of the mode in 0x6502 Supported Drive Modes; returns -1 when there is no corresponding mode
note

supported_bit is a read-only property on the ModeCiA402 enum members and does not access the bus. The bit indices are fixed: PP=0, VL=1, PV=2, PT=3, HM=5, IP=6, CSP=7, CSV=8, CST=9, CSTCA=10. -1 is not a legal bit index, so check >= 0 before computing the mask (1 << -1 throws ValueError).

Example:

mode = ModeCiA402.CSP
bit = mode.supported_bit # 7
modes = drv.supported_drive_modes # 0x6502, None when the read fails
if modes is not None and bit >= 0:
print("驱动器支持 CSP" if modes & (1 << bit) else "驱动器不支持 CSP") # Drive supports CSP / drive does not support CSP

Operation mode properties​

Operation mode is read and written through properties, not set_mode()/get_mode() methods:

# slave.cia402: read 0x6061, write 0x6060 (PDO preferred on the read side)
@property
def operation_mode(self) -> int
@operation_mode.setter
def operation_mode(self, value: int) -> None

# Base-class property (read 0x6061 / write 0x6060, SDO path), same semantics
@property
def mode(self) -> int
@mode.setter
def mode(self, value: int) -> None

Sets or reads the operation mode. The read goes to 0x6061 (Modes of Operation Display), the write goes to 0x6060; operation_mode prefers PDO on the read side. A write failure (both the process image and the SDO fail, or a base-class mode write failure) throws RuntimeError. operation_mode is the only read entry for 0x6061 (the old name modes_of_operation_display has been removed; do not use it). A read failure is folded to 0 (not a valid mode value); use try_read_operation_mode_display() to distinguish a real value from a read failure.

ModeCiA402 enum:

class ModeCiA402(IntEnum):
PP = 1 # profile position mode
VL = 2 # velocity mode
PV = 3 # profile velocity mode
PT = 4 # profile torque mode
HM = 6 # homing mode
IP = 7 # interpolated position mode
CSP = 8 # cyclic synchronous position mode
CSV = 9 # cyclic synchronous velocity mode
CST = 10 # cyclic synchronous torque mode
CSTCA = 11 # cyclic synchronous torque with commutation angle mode

Example:

from darra_ethercat import ModeCiA402

drv = slave.cia402
drv.operation_mode = ModeCiA402.CSP
print(f"操作模式: {drv.operation_mode}") # Operation mode: {drv.operation_mode}

Motion parameters​

CategoryPropertyTypeRead/writeDescription
Positionactual_positionintread-onlyActual position (0x6064)
Velocityvelocity_actualintread-onlyActual velocity (0x606C)
Torquetorque_actualintread-onlyActual torque, thousandths of rated (0x6077)
Positiontarget_positionintread/writeTarget position (0x607A)
Velocitytarget_velocityintread/writeTarget velocity (0x60FF)
Torquetarget_torqueintread/writeTarget torque, thousandths of rated (0x6071)
Positionposition_actualOptional[int]read-onlyActual position (0x6064), the same-object entry as actual_position; on slave.cia402 it follows the PDO-preferred path together with actual_position
Torqueactual_torqueOptional[int]read-onlyActual torque, thousandths of rated (0x6077), same object as torque_actual; direct SDO read, returns None on a read failure
Failure semantics of the properties in this table

The properties in this table actually return Optional[int] on the read side: on CiA402Advanced a failed read on a PDO hit is folded to 0, an object without mapping falls back to SDO and a failed SDO read returns None; the SDO wrapper properties (same for the profile/homing/extended/limit/I/O tables) always return None on a read failure, so they can be distinguished from a real value of 0.

Example:

drv = slave.cia402
drv.scan_pdo_mapping()

# Read actual values
print(f"位置: {drv.actual_position}") # Position: {drv.actual_position}
print(f"速度: {drv.velocity_actual}") # Velocity: {drv.velocity_actual}

# Write target values
drv.target_position = 100000
drv.target_velocity = 5000

set_target_position()​

def set_target_position(self, position: int) -> bool

Writes the target position (0x607A, int32) through SDO. It always goes through SDO and does not use the PDO fast path; it writes the same object as the writable target_position property (PDO preferred).

Parameters:

  • position (int) — target position; the unit depends on the slave configuration (determined by the 0x6091 gear ratio / 0x6092 feed constant)

Returns:

  • True — the SDO write succeeded
  • False — the write failed (slave abort / timeout / communication exception)
  • a value outside the int32 range throws struct.error during the packing stage

Example:

if not drv.set_target_position(100000):
print("目标位置写入失败") # Failed to write the target position

set_target_velocity()​

def set_target_velocity(self, velocity: int) -> bool

Writes the target velocity (0x60FF, int32) through SDO. Always goes through SDO; it writes the same object as the writable target_velocity property (PDO preferred).

Parameters:

  • velocity (int) — target velocity; the unit depends on the slave configuration (usually user units per second under the 0x6092 feed constant)

Returns:

  • True — the SDO write succeeded
  • False — the write failed (slave abort / timeout / communication exception)
  • a value outside the int32 range throws struct.error during the packing stage

Example:

if not drv.set_target_velocity(5000):
print("目标速度写入失败") # Failed to write the target velocity

set_target_torque()​

def set_target_torque(self, torque: int) -> bool

Writes the target torque (0x6071, int16) through SDO.

Parameters:

  • torque (int) — target torque, unit 0.1% of rated torque (thousandths of rated); the sign determines the direction

Returns:

  • True — the SDO write succeeded
  • False — the write failed (slave abort / timeout / communication exception)
  • a value outside the int16 range throws struct.error during the packing stage

Example:

if not drv.set_target_torque(500):   # 50% of rated torque
print("目标转矩写入失败") # Failed to write the target torque

Profile parameters​

CategoryPropertyTypeRead/writeDescription
Profileprofile_velocityintread/writeProfile velocity (0x6081)
Profileprofile_accelerationintread/writeProfile acceleration (0x6083)
Profileprofile_decelerationintread/writeProfile deceleration (0x6084)
Profilemax_profile_velocityOptional[int]read/writeMaximum profile velocity limit (0x6080), the velocity limit of PP / PV profiles; returns None on a read failure

Example:

drv.profile_velocity = 10000
drv.profile_acceleration = 50000
drv.profile_deceleration = 50000

Polarity and profile configuration​

CategoryPropertyTypeRead/writeDescription
Polaritypolarityintread/writePolarity configuration (0x607E). Bit 6 = velocity polarity inversion, bit 7 = position polarity inversion
Profilemotion_profile_typeintread/writeMotion profile type (0x6086). 0 = trapezoidal (linear ramp), 1 = sinusoidal, 2 = S-curve (parabolic)
Stopquick_stop_decelerationintread/writeQuick stop deceleration (0x6085)
Option codequick_stop_option_codeintread/writeQuick stop option code (0x605A, SDO path). Returns None on a read failure (distinguishable from a real value of 0); for the sentinel convention see quick_stop_option on the same object (the Option code properties (0x605A-0x605E) section)

Example:

# Invert the position direction
drv.polarity = 0x80 # bit 7 = position polarity inversion

# Set an S-curve profile
drv.motion_profile_type = 2

# Set the quick stop deceleration
drv.quick_stop_deceleration = 100000

Touch probe (Touch Probe)​

CategoryPropertyTypeRead/writeDescription
Touch probetouch_probe_pos_edgeOptional[int]read-onlyTouch Probe 1 positive edge captured position (0x60BA), returns None on a read failure
Touch probetouch_probe_neg_edgeOptional[int]read-onlyTouch Probe 1 negative edge captured position (0x60BB), returns None on a read failure
note

Both properties always read through SDO; they read the same object with the same semantics as the touch_probe_positive_value / touch_probe_negative_value of CiA402Advanced, so either set will do. A captured position is only valid after the corresponding status bit in 0x60B9 indicates that a capture has occurred.

configure_touch_probe()​

def configure_touch_probe(self, function: int) -> None

Configures the touch probe function (0x60B8). Enables/disables the touch probe and its trigger conditions by setting the function bits.

Parameters:

  • function (int) — touch probe function word. Bit 0 = enable probe 1, bit 1 = positive edge trigger (1 = positive edge), bit 2 = first event only; bits 8 and up are the corresponding bits for probe 2

Related properties:

  • touch_probe_status (int, read-only) — touch probe status (0x60B9)
  • touch_probe_positive_value (int, read-only) — rising edge captured position (0x60BA)
  • touch_probe_negative_value (int, read-only) — falling edge captured position (0x60BB)

Example:

# Enable touch probe 1, positive edge trigger (bit 0 + bit 1)
drv.configure_touch_probe(0x0003)

# Or use the convenience switch
# drv.enable_touch_probe(positive_edge=True, first_event_only=True)

# Read the touch probe result
if (drv.touch_probe_status & 0x0002) != 0: # positive edge captured
captured_pos = drv.touch_probe_positive_value
print(f"触探捕获位置: {captured_pos}") # Touch-probe captured position: {captured_pos}

enable_touch_probe()​

def enable_touch_probe(self, positive_edge: bool = True,
first_event_only: bool = True) -> None

Convenience switch that enables probe 1: builds the function word from the switches and then calls configure_touch_probe().

Parameters:

  • positive_edge (bool) — True = positive edge trigger (default), False = negative edge trigger
  • first_event_only (bool) — True = first event only (default), False = continuous capture

set_touch_probe_function()​

def set_touch_probe_function(self, value: int) -> bool

Writes the touch probe function word (0x60B8, uint16) through SDO, starting and stopping the probe according to the CiA 402 Part 2 bit definitions. It writes the same object as configure_touch_probe(), but this method returns whether the write succeeded.

Parameters:

  • value (int) — function word, combined bitwise:
    • Bit 0 — enable Touch Probe 1
    • Bit 1 — Touch Probe 1 edge selection (0 = positive edge, 1 = negative edge)
    • Bit 2 — enable Touch Probe 1 continuous mode
    • Bit 8 — enable Touch Probe 2
    • the remaining bits are reserved by CiA 402-2; this method passes the value through unchanged and does no masking or validity check

Returns:

  • True — the function word was written successfully
  • False — the write failed (slave abort / timeout / communication exception)
  • a value outside 0..65535 throws struct.error during the packing stage
Bit definitions differ from configure_touch_probe() / enable_touch_probe()

The same object 0x60B8 has two bit interpretations inside the SDK: with configure_touch_probe() / enable_touch_probe(positive_edge=True), setting Bit 1 to 1 means positive edge and setting Bit 2 to 1 means first event only; this method follows the CiA 402 Part 2 definition, where Bit 1 = 1 reads as negative edge and Bit 2 = 1 reads as continuous mode. The two interpretations of Bit 1 / Bit 2 are opposite; pick one and stay with it within a project, verify the actual meaning against the drive ESI / object description, and do not mix them.

Example:

# Touch Probe 1: positive edge, single capture
if not drv.set_touch_probe_function(0x0001):
print("触探功能写入失败") # Failed to write the touch-probe function

Homing speed and acceleration​

CategoryPropertyTypeRead/writeDescription
Hominghoming_methodintread/writeHoming method (0x6098)
Hominghome_offsetintread/writeHoming offset (0x607C)
Hominghoming_speed_searchintread/writeHoming search speed (0x6099:01), fast search for the reference signal
Hominghoming_speed_zerointread/writeHoming zero speed (0x6099:02), slow fine positioning to the zero position
Hominghoming_accelerationintread/writeHoming acceleration (0x609A)

start_homing()​

def start_homing(self) -> None

Starts homing in HM mode. homing_method must be set first. The CiA402Advanced implementation requires the current state to be OperationEnabled, otherwise it throws RuntimeError (the Fault / FaultReaction states are always rejected; a fault is never treated as enabled when issuing motion commands).

Related properties:

  • homing_attained (bool) — homing completed (Bit 12)
  • homing_error (bool) — homing error (Bit 13)

Example:

drv.operation_mode = ModeCiA402.HM
drv.homing_method = 35 # home at the current position

# Set homing speed and acceleration
drv.homing_speed_search = 5000 # search speed
drv.homing_speed_zero = 500 # zero speed
drv.homing_acceleration = 10000 # homing acceleration

# Enable, then start homing
drv.enable()
drv.start_homing()
# then check drv.homing_attained / drv.homing_error

Extended motion parameters​

CategoryPropertyTypeRead/writeDescription
Torquemax_torqueintread/writeMaximum torque (0x6072), thousandths of rated torque
Torquemotor_rated_torqueintread/writeMotor rated torque (0x6076), unit mNm
Offsetposition_offsetintread/writePosition offset (0x60B0), added to the target position in CSP mode
Offsetvelocity_offsetintread/writeVelocity offset (0x60B1), added to the target velocity in CSV mode
Interpolationinterpolation_time_period_valueintread/writeInterpolation time period value (0x60C2:01)
Interpolationinterpolation_time_period_indexintread/writeInterpolation time period index (0x60C2:02), actual period = Value x 10^Index seconds

Example:

# Torque configuration
drv.max_torque = 1000 # maximum torque = 100% rated
rated = drv.motor_rated_torque

# Offset superposition in CSP mode
drv.position_offset = 100 # additional position offset
drv.velocity_offset = 50 # additional velocity offset

# Interpolation time period (1 ms = 1 x 10^(-3) seconds)
drv.interpolation_time_period_value = 1
drv.interpolation_time_period_index = -3

Torque limits​

CategoryPropertyTypeRead/writeDescription
Limitpositive_torque_limitintread/writePositive torque limit (0x60E0), thousandths of rated torque
Limitnegative_torque_limitintread/writeNegative torque limit (0x60E1), thousandths of rated torque

Example:

# Limit positive and negative torque to 50% of rated
drv.positive_torque_limit = 500
drv.negative_torque_limit = 500

Digital I/O​

CategoryPropertyTypeRead/writeDescription
Inputdigital_inputsintread-onlyDigital inputs (0x60FD), 32-bit bitmap
Outputdigital_outputsintread/writeDigital outputs (0x60FE:01), 32-bit bitmap

Example:

# Read digital inputs
inputs = drv.digital_inputs
limit_switch = (inputs & 0x01) != 0 # bit 0

# Set digital outputs
drv.digital_outputs = 0x03 # outputs bit 0 and bit 1

Software position limits​

CategoryPropertyTypeRead/writeDescription
Position limitsoftware_position_limit_minintread/writeSoftware position limit lower bound (0x607D:01)
Position limitsoftware_position_limit_maxintread/writeSoftware position limit upper bound (0x607D:02)

Example:

# Set the motion range limits
drv.software_position_limit_min = -1000000
drv.software_position_limit_max = 1000000

Rapid motion control​

new_setpoint()​

def new_setpoint(self, position: int, relative: bool = False) -> None

Sends a new positioning command in PP mode. Sets the target position and triggers Controlword Bit 4 (New Setpoint); with relative=True Bit 6 (Relative) is set. The CiA402Advanced implementation requires the current state to be OperationEnabled, otherwise it throws RuntimeError (valid in PP mode only; bits 4-6 are meaningless under CSP).

Parameters:

  • position (int) — target position
  • relative (bool) — True = relative positioning, False = absolute positioning (default)

Example:

drv.operation_mode = ModeCiA402.PP
drv.profile_velocity = 10000
drv.profile_acceleration = 50000

drv.enable()

# Send a positioning command
drv.new_setpoint(100000) # absolute positioning to 100000
# drv.new_setpoint(5000, True) # or move 5000 relatively

clear_new_setpoint()​

def clear_new_setpoint(self) -> None

Clears the NewSetpoint flag in PP mode (Controlword Bit4 = 0). Call it after target_reached to complete the SetPointAck handshake. The CiA402Advanced implementation requires the current state to be OperationEnabled, otherwise it throws RuntimeError.

Example:

if drv.target_reached:
drv.clear_new_setpoint()

Drive information​

supported_drive_modes​

@property
def supported_drive_modes(self) -> Optional[int]

Supported drive modes bitmask (0x6502, read-only). Bit 0=PP, Bit 1=VL, Bit 2=PV, Bit 3=PT, Bit 5=HM, Bit 6=IP, Bit 7=CSP, Bit 8=CSV, Bit 9=CST, Bit 10=CSTCA. CiA402Advanced returns None on a read failure; the base CiA402 folds a read failure to 0.

is_mode_supported()​

def is_mode_supported(self, mode: ModeCiA402) -> bool

Checks whether the drive supports the given operation mode.

Example:

if drv.is_mode_supported(ModeCiA402.CSP):
drv.operation_mode = ModeCiA402.CSP

supported_homing_methods​

@property
def supported_homing_methods(self) -> List[int]

Reads the list of homing method numbers supported by the drive (0x60E3). A read failure also returns an empty list, and callers should treat it as a failure.

Parameters:

  • None

Returns:

  • List[int] — list of homing method numbers (sbyte list, negative values are vendor-specific methods)

What each of the three cases returns:

  • Failure (SDO timeout / communication exception / other abort) — returns an empty list
  • Empty set (SI0=0 and the read succeeded, the slave really returned 0 entries) — returns an empty list
  • Not supported (the slave has no 0x60E3 or no 0x60E3:00, SDO abort 0x06020000 object does not exist / 0x06090011 subindex does not exist) — returns an empty list
note

This property folds the three cases into the same return shape (an empty list), so an empty list must not be read as meaning that 0 homing methods are supported. The underlying read returns -1 on failure, and a genuine return of 0 entries gives 0 (fail-closed, distinguishable at that layer), and the SDK maps both to an empty list; this property's own read primitive sdo_read_value also returns None on a read failure, which is likewise folded inside this property. The entry on this page that can distinguish the three states is try_supported_homing_methods(): it returns the full list together with a CiA402ReadStatus of SUCCESS (value == [] is a genuine empty set and a real value) / NOT_SUPPORTED (not supported) / READ_FAILED (failure). try_read_object() remains the generic route.

Example:

methods = drv.supported_homing_methods
if not methods:
print("回零方法列表为空: 读失败 / 空集 / 不支持,不能当作支持 0 种方法") # Homing method list is empty: read failed / empty set / not supported — do not treat this as supporting 0 methods
else:
print(f"支持 {len(methods)} 种回零方法: {methods}") # Supports {len(methods)} Homing methods: {methods}

# Use the dedicated entry when the three states must be distinguished
result = drv.try_supported_homing_methods()
print(result.status.name, result.value)

try_supported_homing_methods()​

def try_supported_homing_methods(self) -> CiA402ReadResult

Reads the list of homing method numbers supported by the drive (0x60E3), with the real value / read failure / not supported tri-state distinguishable. Uses the same carrier CiA402ReadResult as try_read_error_code().

Parameters:

  • None

Returns:

  • CiA402ReadResult — result with status; value is the list of homing method numbers (meaningful only when status==SUCCESS, otherwise None)

What each of the three cases returns:

  • Real value (status = SUCCESS) — the full list is in value; an empty list = the slave really returned 0 homing methods (it genuinely supports no homing method), which is a real value, not a failure
  • Read failure (status = READ_FAILED, SDO timeout / communication exception / other abort) — value is meaningless (None)
  • Not supported (status = NOT_SUPPORTED, the 0x60E3 object/subindex does not exist, SDO abort 0x06020000 / 0x06090011 / 0x06090012) — value is meaningless (None)
note

A failed subitem read must never fabricate an entry: as soon as one subitem cannot be read, report that state faithfully for the whole result (taking the status and abort code of the first failed subitem); value must not be used as a real value, and a failure must never be pushed into the list as method 0. abort_code still carries the SDO Abort Code (NO_ERROR on success). Method numbers are sbyte (List[int], -128..-1 are vendor-specific methods) and are real values, not sentinels; do not use is_read_fail_sentinel to filter them.

note

The old entries supported_homing_methods and get_supported_homing_methods_dll() fold "failure / empty set / not supported" into the same shape (an empty list), so a failure also yields an empty set; use try_supported_homing_methods() when you need to tell them apart. For subitems that cannot be read, the old entries "skip and do not fabricate an entry".

Example:

r = drv.try_supported_homing_methods()
if r.ok:
if not r.value:
print("从站确认不支持任何回零方法") # The slave confirms it supports no Homing methods
else:
print(f"支持 {len(r.value)} 种回零方法: {r.value}") # Supports {len(r.value)} Homing methods: {r.value}
elif r.not_supported:
print("从站不支持 0x60E3") # The slave does not support 0x60E3
else:
print(f"读取失败: {r.status.name}, abort={r.abort_code}") # Read failed: {r.status.name}, abort={r.abort_code}

Observable read-only access​

The read-failure semantics of read-only return values differ by interface; there are three publicly documented sentinel constants:

  • READ_FAIL_SENTINEL_I16 = -32768 (INT16_MIN) — signed 16-bit option code (0x605A-0x605E) read failure
  • READ_FAIL_SENTINEL_U16 = 0xFFFF — unsigned 16-bit error_code (0x603F) read failure
  • READ_FAIL_SENTINEL_INT = -1 — counting-style read interfaces returning int (get_error_history / get_supported_homing_methods_dll etc.) return -1 as a whole on a read failure (fail-closed)

Choose the predicate of the same domain by return shape: is_read_fail_sentinel_i16(v) only recognizes -32768, is_read_fail_sentinel_u16(v) only recognizes 0xFFFF, is_read_fail_sentinel_int(v) only recognizes -1. The combined entry is_read_fail_sentinel(v) is a legacy cross-domain check with documented false positives, kept for old call sites; new code always uses the three domain-specific predicates above. None of the three sentinels is a legal value (legal option codes are small values including 0; error_code 0x0000 means no error; the legal return of the counting interfaces is an entry count >= 0), so do not use them as real values; after the check, treat them as failures.

note

Choose the predicate by return shape and do not mix domains. The combined entry is_read_fail_sentinel covers all three value domains at once; its documented false positives are: -1 is a legal vendor value of the Fault Reaction option code (0x605E), and 65535 is also a legal count value; both are judged as a read failure by the combined entry. int8 method numbers (0x60E3 list items, -128..-1 are vendor-specific methods) are real values and not sentinels; likewise do not use them for the check.

Three failure classes must be distinguished: (a) sentinel path = the five option-code properties (quick_stop_option / shutdown_option / disable_operation_option / halt_option / fault_reaction_option) and the six underlying direct-read properties of error_code (read failures return the two sentinels -32768 / 0xFFFF); (b) counting sentinel path = counting-style read interfaces returning int (get_error_history / get_supported_homing_methods_dll etc.), where an underlying read failure returns -1 as a whole (fail-closed, READ_FAIL_SENTINEL_INT) and the SDK maps it to an empty list, so callers should treat it as a failure; (c) folded failure path = PDO-preferred numeric getters such as actual_position / torque_actual (a failed read on a PDO hit is folded to 0 and cannot be told apart from a real 0; with no mapping it falls back to SDO and returns None on a read failure) and the SDO wrapper properties (such as quick_stop_option_code, which returns None on a read failure). The try_read_* methods really perform one SDO read and split the result faithfully into three states (success / not supported / read failure), so they can fully distinguish "the slave really returned 0" from a read failure.

note

try_read_* always goes through SDO read-only (even when the object is already PDO-mapped) so that the SDO Abort Code is available to distinguish the states. For high-frequency real-time reads use the corresponding PDO-preferred properties (actual_position, statusword, etc.) instead.

CiA402ReadStatus enum​

class CiA402ReadStatus(IntEnum):
NOT_ATTEMPTED = 0 # not attempted yet
SUCCESS = 1 # read succeeded, the returned value is the real slave value
NOT_SUPPORTED = 2 # the slave does not support the object (SDO abort 0x06020000/0x06090011)
READ_FAILED = 3 # SDO read failed (timeout / communication exception / other abort)

CiA402ReadResult​

The NamedTuple result with status returned by the try_read_* methods.

  • value (Optional[Union[int, List[int]]]) — field — read-only — the value read (meaningful only when status==SUCCESS, otherwise None; int for scalar objects, List[int] for the 0x60E3 list object)
  • status (CiA402ReadStatus) — field — read-only — read status enum
  • abort_code (SDOError) — field — read-only — SDO Abort Code (NO_ERROR = no abort)
  • ok (bool) — property — read-only — whether the read succeeded and the value is trustworthy (status == SUCCESS)
  • not_supported (bool) — property — read-only — whether the slave does not support the object (status == NOT_SUPPORTED)

try_read_object()​

def try_read_object(self, index: int, subindex: int = 0,
dtype: str = 'u32') -> CiA402ReadResult

Generic observable read-only access — performs one SDO read-only attempt on any CiA402 object and returns the result with status. Purely read-only, no side effects. dtype accepts 'u8'/'i8'/'u16'/'i16'/'u32'/'i32'/'u64'/'i64'.

Dedicated try_read_* methods​

  • try_read_operation_mode_display() — object 0x6061 — return width i8 — operation mode display (forces SDO, does not take PDO)
  • try_read_supported_drive_modes() — object 0x6502 — return width u32 — supported drive modes bitmask (ETG.6010 mandatory)
  • try_read_error_code() — object 0x603F — return width u16 — current error code (tri-state return, independent of the 0xFFFF sentinel convention of the error_code property)
  • try_read_torque_actual() — object 0x6077 — return width i16 — actual torque (thousandths of rated)
  • try_read_digital_inputs() — object 0x60FD — return width u32 — digital inputs
  • try_read_position_actual() — object 0x6064 — return width i32 — actual position (SDO path)
  • try_read_velocity_actual() — object 0x606C — return width i32 — actual velocity (SDO path)
  • try_read_statusword() — object 0x6041 — return width u16 — status word (SDO path)
  • try_read_drive_data(subindex) — object 0x6510 — return width u32 — vendor-specific drive data (subindex defined by the ESI)

Every method has the signature def try_read_xxx(self) -> CiA402ReadResult (except try_read_drive_data(self, subindex: int)).

Observable state properties​

  • last_read_status (CiA402ReadStatus) — state — read-only — status of the most recent SDO read-only attempt
  • last_read_abort_code (SDOError) — state — read-only — Abort Code of the most recent failure/not-supported (NO_ERROR = success)
  • last_read_object (Tuple[int, int]) — state — read-only — (object index, subindex) of the most recent attempt
  • supported_drive_modes_readable (bool) — state — read-only — whether the slave really supports the 0x6502 object (based on the read-only attempt result)

Example:

from darra_ethercat import CiA402ReadStatus, is_read_fail_sentinel_u16

# Tri-state discrimination: real value / not supported / read failure (try_read_* series)
result = drv.try_read_supported_drive_modes()
if result.ok:
print(f"支持的驱动模式位掩码: 0x{result.value:08X}") # Supported drive mode bitmask: 0x{result.value:08X}
elif result.not_supported:
print("从站不支持 0x6502 对象") # The slave does not support object 0x6502
else:
print(f"读取失败, abort=0x{int(result.abort_code):08X}") # Read failed, abort=0x{int(result.abort_code):08X}

# Query diagnostics of the most recent read-only attempt
idx, sub = drv.last_read_object
print(f"最近读取 0x{idx:04X}:{sub:02X}, 状态={drv.last_read_status.name}") # Last read 0x{idx:04X}:{sub:02X}, status={drv.last_read_status.name}

# Option code read failure = sentinel -32768, check with is_read_fail_sentinel_i16; error_code read failure = 0xFFFF, check with is_read_fail_sentinel_u16
if is_read_fail_sentinel_u16(drv.error_code):
print("error_code 读取失败, 按失败处理") # error_code read failed, handled as a failure

TxPDO data validity​

txpdo_data_invalid​

@property
def txpdo_data_invalid(self) -> bool

Whether the TxPDO data is invalid (0x603E). A non-zero value means the drive's TxPDO data is not trustworthy, for example the position value is meaningless while the encoder is not ready, in which case do not use actual_position / velocity_actual.

Note: a read failure of this property is also folded to False (fail-open); "not invalid" does not equal "confirmed valid". For critical axes, double-check with an observable read:

Example:

if not drv.txpdo_data_invalid:
pos = drv.actual_position # data is valid, safe to use

# Critical-axis recheck: distinguish "really valid" from "read failure folded"
r = drv.try_read_object(0x603E, 0, 'u8')
if r.ok and r.value == 0:
pos = drv.actual_position

Synchronization functions​

CategoryPropertyTypeRead/writeDescription
Synchronizationsynchronization_settingsintread/writeSynchronization settings (0x60D9:01), synchronization enable bitmask
Synchronizationdrive_sync_statusintread-onlyDrive synchronization status (0x60DA), indicates whether the drive is synchronized to the master clock

Example:

# Read the drive synchronization status
sync_status = drv.drive_sync_status
print(f"同步状态: 0x{sync_status:04X}") # Sync status: 0x{sync_status:04X}

# Configure the synchronization settings
drv.synchronization_settings = 0x0001

Deep compliance API (ETG.6010 + CiA 402-2)​

The following methods/properties cover strict CiA 402-2 state transition validation, option code (0x605A-0x605E) read/write, and the drive-internal error history (0x1003).

request_transition()​

def request_transition(self, target: StateCiA402) -> bool

Requests the given state transition; validity is checked by the underlying library per CiA 402-2 Fig.3 T1-T16. An illegal transition (such as FAULT → OPERATION_ENABLED directly) returns False and no command is sent.

Parameters:

  • target (StateCiA402) — target state

Returns:

  • bool — True = the transition command was issued, False = illegal transition / failure

CiA402Advanced.get_transition_command(dll, current, target)​

@staticmethod
def get_transition_command(dll: DarraCoreDLL, current: StateCiA402,
target: StateCiA402) -> int

Pure query: according to the T1-T16 transition table of CiA 402-2 Fig.3, returns the control word that should be written to switch from current to target. It only computes; it neither issues anything nor reads the bus.

Parameters:

  • dll (DarraCoreDLL) — runtime library instance, obtained with shared_core_dll(); that function returns None when loading fails, and passing None throws AttributeError at the call site
  • current (StateCiA402) — current state
  • target (StateCiA402) — target state

Returns:

  • int — the control word to write to 0x6040; 0xFFFF means the transition is illegal (not a legal control word, do not write it to the control word)
note

This method neither validates the state nor touches the drive: to advance the state machine according to the table use request_transition() (validation and issue in one); if you want to control the timing yourself, write the returned value to controlword afterwards. The incoming current / target are passed through as integers, with no Python-side range check.

Example:

from darra_ethercat import CiA402Advanced, StateCiA402
from darra_ethercat.utils.dll import shared_core_dll

dll = shared_core_dll()
if dll is not None:
cw = CiA402Advanced.get_transition_command(
dll, StateCiA402.SWITCH_ON_DISABLED, StateCiA402.READY_TO_SWITCH_ON)
if cw != 0xFFFF:
drv.controlword = cw

fault_reset_step()​

def fault_reset_step(self, step: int) -> bool

Non-blocking single-step Fault Reset (the PDO callback calls step=0/step=1 in two separate cycles to avoid the sleep inside fault_reset() blocking the RT thread). step=0 writes CW_SHUTDOWN (0x06, bit 2 = 1 does not trigger QuickStop), step=1 writes CW_FAULT_RESET (0x86, producing the bit 7 rising edge).

supported_drive_modes_dll / is_mode_supported_dll()​

@property
def supported_drive_modes_dll(self) -> int

def is_mode_supported_dll(self, mode: int) -> bool

Queries the supported drive modes bitmask (0x6502) and the mode support check through the underlying library; the underlying library does the PDO/SDO split and the bit computation. Equivalent to supported_drive_modes / is_mode_supported().

Option code properties (0x605A-0x605E)​

  • quick_stop_option (int) — read/write — Quick Stop option code (0x605A). 0 = immediate cut-off, 1 = ramp deceleration, 2 = Quick Stop deceleration, 3 = torque stop; 5/6/7/8 = hold QuickStopActive after deceleration (allows T16 directly → OperationEnabled)
  • shutdown_option (int) — read/write — Shutdown option code (0x605B): OperationEnabled → ReadyToSwitchOn deceleration behavior
  • disable_operation_option (int) — read/write — Disable Operation option code (0x605C): OperationEnabled → SwitchedOn behavior
  • halt_option (int) — read/write — Halt option code (0x605D): CW Bit8 Halt behavior (1 = profile ramp, 2 = QS deceleration, 3 = torque stop)
  • fault_reaction_option (int) — read/write — Fault Reaction option code (0x605E): behavior after fault detection (-1 = vendor, 0 = immediate cut-off, 1/2/3 = deceleration)

Return value and read-failure sentinel: normal = the real value; read failure = -32768 (INT16_MIN, READ_FAIL_SENTINEL_I16). -32768 is not a legal value (legal option codes are small values including 0), so do not use it as a real value; check with is_read_fail_sentinel_i16(v) and treat it as a failure (public constants READ_FAIL_SENTINEL_I16 = -32768 / READ_FAIL_SENTINEL_U16 = 0xFFFF / READ_FAIL_SENTINEL_INT = -1; the domain-specific predicates is_read_fail_sentinel_i16 / is_read_fail_sentinel_u16 / is_read_fail_sentinel_int only recognize their own sentinel; the combined entry is_read_fail_sentinel is a legacy cross-domain check with documented false positives).

error_code / error history​

@property
def error_code(self) -> int

def get_error_history(self, max_count: int = 32) -> List[int]

def clear_error_history(self) -> bool
  • error_code (int) — read-only — current Error Code (0x603F, CiA 402 annex). Normal = the real value; read failure = 0xFFFF sentinel (READ_FAIL_SENTINEL_U16). 0xFFFF is not a legal value (0x0000 means no error); do not use it as a real value, check with is_read_fail_sentinel_u16(v)
  • get_error_history(max_count=32) (List[int]) — read-only — reads the Pre-defined Error Field (0x1003), returning the drive-internal persistent error history (lower 16 bits of the Error Code). A read failure returns -1 as a whole (fail-closed), the SDK maps it to an empty list, and callers should treat it as a failure (an empty list does not mean no history is confirmed)
  • clear_error_history() (bool) — write-only — clears the drive-internal error history (0x1003:00 = 0). Returns bool indicating whether the clear command succeeded

try_error_history()​

def try_error_history(self, max_count: int = 32) -> CiA402ReadResult

Tri-state variant for reading the Pre-defined Error Field (0x1003), using the same CiA402ReadResult carrier as try_supported_homing_methods().

Parameters:

  • max_count (int) — maximum number of entries to read, default 32. If the slave reports more entries than this they are truncated to max_count (the same rule as the underlying clamp, not a failure); max_count <= 0 is an invalid request that returns READ_FAILED immediately without touching the bus

Returns:

  • CiA402ReadResult — status is the tri-state; value is the error-code list only when SUCCESS (the u32 real values of 0x1003:nn)

What each of the three cases returns:

  • SUCCESS + value == [] — the slave really returned 0 entries (a real value, not a failure)
  • SUCCESS + non-empty value — the history entries
  • NOT_SUPPORTED — 0x1003 does not exist (SDO abort 0x06020000 / 0x06090011)
  • READ_FAILED — the count subindex or any entry failed to read over SDO
One failed entry fails the whole read

If even one entry cannot be read, the whole call reports that entry's cause (status / abort_code) and value is None — it never fabricates a 0 error-code entry and never returns a partial list.

Difference from the old entry

get_error_history() folds "empty history / not supported / read failure" into the same empty list; use this entry when you need to tell them apart. The tri-state entry for the homing method list is try_supported_homing_methods() on this page (SUCCESS + an empty list = the slave really supports no method).

Example:

r = drv.try_error_history()
if r.ok:
if not r.value:
print("从站确认错误历史为空") # The slave confirms the error history is empty
else:
print(f"历史 {len(r.value)} 条: {[hex(e) for e in r.value]}") # History: {len(r.value)} entries: {[hex(e) for e in r.value]}
elif r.not_supported:
print("从站不支持 0x1003") # The slave does not support 0x1003
else:
print(f"读取失败: {r.status.name}, abort={r.abort_code}") # Read failed: {r.status.name}, abort={r.abort_code}

Homing method interface​

@property
def homing_method_dll(self) -> int

@homing_method_dll.setter
def homing_method_dll(self, value: int) -> None

def get_supported_homing_methods_dll(self, max_count: int = 64) -> List[int]
  • homing_method_dll — reads/writes the homing method (0x6098, sbyte), equivalent to the homing_method property.
  • get_supported_homing_methods_dll() — reads the supported homing method list (0x60E3, sbyte list, may contain negative vendor extensions). A read failure returns -1 as a whole (fail-closed), the SDK maps it to an empty list, and callers should treat it as a failure (an empty list does not mean no homing method is confirmed). Use try_supported_homing_methods() when you need to tell them apart.

What each of the three cases returns from get_supported_homing_methods_dll():

  • Failure (SDO timeout / communication exception / other abort) — the underlying layer returns -1 (fail-closed), this wrapper maps it to an empty list, treat it as a failure
  • Empty set (SI0=0 and the read succeeded, the slave really returned 0 entries) — returns an empty list
  • Not supported (the slave has no 0x60E3 or no 0x60E3:00, SDO abort 0x06020000 / 0x6090011) — the underlying layer returns -1, the same bucket as a failure, this wrapper maps it to an empty list

Example:

from darra_ethercat import StateCiA402

# State transitions validated per CiA 402-2 (illegal transitions return False and send no command)
if not drv.request_transition(StateCiA402.OPERATION_ENABLED):
print("非法转换 / 失败") # Illegal transition / failure

# Read the drive-internal error history (an empty list = no history or a read failure; treat it as a failure)
history = drv.get_error_history()
print(f"错误历史 ({len(history)} 条): {[hex(e) for e in history]}") # Error history ({len(history)} entries): {[hex(e) for e in history]}

# Current error code (a read failure = the 0xFFFF sentinel, not a real error code)
from darra_ethercat import is_read_fail_sentinel_u16
if is_read_fail_sentinel_u16(drv.error_code):
print("error_code 读取失败, 按失败处理") # error_code read failed, handled as a failure
else:
print(f"当前错误码: 0x{drv.error_code:04X}") # Current error code: 0x{drv.error_code:04X}

# Configure the Quick Stop option code (6 = hold QuickStopActive after deceleration); a read returning the -32768 sentinel means failure
drv.quick_stop_option = 6

CiA402Advanced.is_standard_homing_method(dll, method)​

@staticmethod
def is_standard_homing_method(dll: DarraCoreDLL, method: int) -> bool

Pure check: tells whether a homing method number belongs to the standard methods defined by ETG.6010 (1-35 or 37). It only classifies the number; it does not read 0x6098, write parameters or access the bus.

Parameters:

  • dll (DarraCoreDLL) — runtime library instance, obtained with shared_core_dll(); when it is None the call site throws AttributeError
  • method (int) — homing method number (sbyte semantics: negative values are vendor-specific methods)

Returns:

  • True — standard method (1-35 or 37)
  • False — non-standard (including 0, negative vendor methods, 36 and other numbers)
note

"Standard number" does not mean "supported by the drive": a standard method may still be absent from the 0x60E3 support list. To judge support use supported_homing_methods / try_supported_homing_methods(); this method only answers whether the number is in the standard set.

Example:

from darra_ethercat import CiA402Advanced
from darra_ethercat.utils.dll import shared_core_dll

dll = shared_core_dll()
if dll is not None and CiA402Advanced.is_standard_homing_method(dll, 35):
drv.homing_method = 35

validate_profile_parameters()​

def validate_profile_parameters(self) -> bool

Parameter validity check on the base class CiA402. Actual behavior: it reads the status word and the operation mode once each, and returns True when neither read throws; it does not validate position / velocity / torque ranges, and it does not write any parameter to the drive.

Returns:

  • True — neither the status word read nor the operation mode read threw
  • False — a read threw (the exception is swallowed internally and not propagated); a read that returns None is also treated as a failure
At runtime the subclass version is used

slave.cia402 returns CiA402Advanced, whose method of the same name overrides this one and returns a List[str] of warnings instead of bool at runtime (see the same-named entry in the Advanced interface (CiA402Advanced) section). This base-class version is only reachable when CiA402 is constructed directly; do not apply the bool reading to slave.cia402.

Example:

from darra_ethercat import CiA402
from darra_ethercat.utils.dll import shared_core_dll

dll = shared_core_dll()
if dll is not None:
base = CiA402(dll, master.master_index, slave.slave_num)
print(base.validate_profile_parameters())

Advanced interface (CiA402Advanced)​

CiA402Advanced inherits from CiA402, and slave.cia402 returns exactly that: PDO mapping scan, typed position / velocity / torque access, and the state machine / homing / diagnostics APIs all live on the same object with no separate construction.

from darra_ethercat import CiA402Advanced

drv = slave.cia402 # CiA402Advanced instance
isinstance(drv, CiA402Advanced) # True

PDO mapping scan​

# Scan the PDO mapping (0x1C12 / 0x1C13)
drv.scan_pdo_mapping()
print(f"PDO 映射完成: {drv.is_pdo_mapped}") # PDO mapping complete: {drv.is_pdo_mapped}
print(f"映射信号: {drv.pdo_offsets}") # Mapped signals: {drv.pdo_offsets}

After the scan completes, motion parameter reads and writes go through PDO first (zero latency), and fall back to SDO when there is no mapping.

Write semantics after binding to PDO

After the output mapping has been found, writing the control word / operation mode / target position / target velocity / target torque behaves as follows: the object is mapped → write the PDO directly through the versioned read-modify-write transaction on the process image; the process image write fails or the object is not mapped → fall back to SDO. When both paths fail it throws RuntimeError (including the slave index, output offset and SDO Abort Code) and never silently drops the write.

Related properties:

  • status_word_pdo (int, read-only) — read the status word through PDO (0x6041)
  • control_word_pdo (int, read/write) — read/write the control word through PDO (0x6040)

validate_profile_parameters(configured_mode=0)​

def validate_profile_parameters(self, configured_mode: int = 0) -> List[str]

Checks whether the drive profile parameters satisfy the motion requirements of PP(1) / PV(3) mode. It only detects and reports warnings; it never writes any parameter automatically.

Parameters:

  • configured_mode (int) — the operation mode configured at Startup; 0 (default) = read 0x6060 from the drive and determine it automatically

Returns:

  • List[str] — list of warning messages; an empty list = no warnings found or the check was not run

When it checks, and what it warns about:

  • only when the determined mode is PP(1) or PV(3) does it check 0x6080 maximum profile velocity, 0x6083 profile acceleration and 0x6084 profile deceleration item by item
  • an item reads as 0 → appends a warning "the drive cannot generate a motion profile, configure it in Startup"
  • an item read throws → appends a warning "read failed (the drive may not support this object)"
  • an item reads back None (SDO read failed without throwing) → that item is silently skipped and produces no warning; for a failure you can tell apart, re-check it with try_read_object()
  • the mode is not PP/PV, the 0x6060 read failed (folded to 0), or CoE is unavailable as a whole → returns an empty list directly, without throwing
An empty list does not mean the parameters are compliant

An empty list may mean "the check passed", or "no check ran at all" (the mode is not PP/PV, or the 0x6060 read failed). To confirm that a check really ran, pass configured_mode=ModeCiA402.PP (or PV) explicitly and use try_read_object() to re-check whether the drive supports 0x6080 / 0x6083 / 0x6084.

Difference from the same-named base-class method

This is the CiA402Advanced version (slave.cia402 takes this one at runtime, returning List[str]); the base CiA402.validate_profile_parameters() takes no arguments and returns bool, with completely different semantics; see the Deep compliance API (ETG.6010 + CiA 402-2) section.

Example:

from darra_ethercat import ModeCiA402

for warning in drv.validate_profile_parameters(ModeCiA402.PP):
print(f"警告: {warning}") # Warning: {warning}

Standard object index constants​

The table below lists the module-level constants of darra_ethercat.slave.cia402 (from darra_ethercat.slave.cia402 import OD_CONTROLWORD, OD_STATUSWORD etc.), which can be combined with slave.coe.sdo_read / sdo_write to access the object dictionary directly. CiA402 / slave.cia402 also carry a set of same-valued class attributes (drv.OD_CONTROLWORD also works), but only about 26 of them, and three are named differently: the class attributes OD_MODES_OF_OPERATION_DISPLAY / OD_QUICK_STOP_DECELERATION / OD_SUPPORTED_DRIVE_MODES correspond to OD_MODES_DISPLAY / OD_QUICK_STOP_DECEL / OD_SUPPORTED_MODES in the table below. The remaining constants in the table (option codes / touch probe / offsets / limits / diagnostics etc.) exist only at module level; do not write CiA402.OD_ERROR_CODE.

ConstantValueDescription
OD_CONTROLWORD0x6040Control word
OD_STATUSWORD0x6041Status word
OD_QUICK_STOP_OPTION_CODE0x605AQuick stop option code
OD_MODES_OF_OPERATION0x6060Operation mode setting
OD_MODES_DISPLAY0x6061Operation mode display
OD_POSITION_ACTUAL0x6064Actual position
OD_TARGET_TORQUE0x6071Target torque
OD_MAX_TORQUE0x6072Maximum torque
OD_MOTOR_RATED_TORQUE0x6076Motor rated torque
OD_TORQUE_ACTUAL0x6077Actual torque
OD_TARGET_POSITION0x607ATarget position
OD_HOME_OFFSET0x607CHoming offset
OD_SOFTWARE_POSITION_LIMIT0x607DSoftware position limit
OD_POLARITY0x607EPolarity
OD_MAX_PROFILE_VELOCITY0x6080Maximum profile velocity
OD_PROFILE_VELOCITY0x6081Profile velocity
OD_PROFILE_ACCELERATION0x6083Profile acceleration
OD_PROFILE_DECELERATION0x6084Profile deceleration
OD_QUICK_STOP_DECEL0x6085Quick stop deceleration
OD_MOTION_PROFILE_TYPE0x6086Motion profile type
OD_HOMING_METHOD0x6098Homing method
OD_HOMING_SPEEDS0x6099Homing speeds
OD_HOMING_ACCELERATION0x609AHoming acceleration
OD_POSITION_OFFSET0x60B0Position offset (CSP)
OD_VELOCITY_OFFSET0x60B1Velocity offset (CSV)
OD_TORQUE_OFFSET0x60B2Torque offset
OD_TOUCH_PROBE_FUNCTION0x60B8Touch Probe function control
OD_TOUCH_PROBE_STATUS0x60B9Touch Probe status
OD_TOUCH_PROBE_POS_EDGE0x60BATouch Probe positive edge position
OD_TOUCH_PROBE_NEG_EDGE0x60BBTouch Probe negative edge position
OD_INTERPOLATION_TIME_PERIOD0x60C2Interpolation time period
OD_VELOCITY_ACTUAL0x606CActual velocity
OD_DIGITAL_INPUTS0x60FDDigital inputs
OD_DIGITAL_OUTPUTS0x60FEDigital outputs
OD_TARGET_VELOCITY0x60FFTarget velocity
OD_TXPDO_DATA_INVALID0x603ETxPDO data invalid flag
OD_ERROR_CODE0x603FCurrent error code (read-only)
OD_SYNCHRONIZATION_SETTINGS0x60D9Synchronization settings
OD_DRIVE_SYNC_STATUS0x60DADrive synchronization status (read-only)
OD_POSITIVE_TORQUE_LIMIT0x60E0Positive torque limit
OD_NEGATIVE_TORQUE_LIMIT0x60E1Negative torque limit
OD_SUPPORTED_HOMING_METHODS0x60E3Supported homing method list
OD_SUPPORTED_MODES0x6502Supported drive modes bitmask
OD_DRIVE_DATA0x6510Vendor-specific drive data (RECORD, read-only)

Control word command constants​

The module-level constants of darra_ethercat.slave.cia402 (from darra_ethercat.slave.cia402 import CW_SHUTDOWN etc.); the CiA402 class attributes have the same names and values, with the single exception of CiA402.CW_FAULT_RESET = 0x80 (bit 7 only). The complete reset word is 0x86; call fault_reset() / fault_reset_step(1) to reset and do not hand-write the constant.

ConstantValueDescription
CW_SHUTDOWN0x06Shutdown command
CW_SWITCH_ON0x07Switch On command
CW_ENABLE_OPERATION0x0FEnable operation
CW_DISABLE_VOLTAGE0x00Disable voltage
CW_QUICK_STOP0x02Quick stop
CW_FAULT_RESET0x86Fault reset (bit 7 rising edge with bit 2 = 1; never write 0x80 alone)
CW_HALT0x0100Halt bit (Bit 8, pauses motion without disabling)

Status word bitmask constants​

ConstantValueDescription
SW_READY_TO_SWITCH_ON0x0001 (Bit 0)Ready to switch on
SW_SWITCHED_ON0x0002 (Bit 1)Switched on
SW_OPERATION_ENABLED0x0004 (Bit 2)Operation enabled
SW_FAULT0x0008 (Bit 3)Fault
SW_VOLTAGE_ENABLED0x0010 (Bit 4)Voltage enabled
SW_QUICK_STOP0x0020 (Bit 5)Quick stop
SW_SWITCH_ON_DISABLED0x0040 (Bit 6)Switch on disabled
SW_WARNING0x0080 (Bit 7)Warning
SW_REMOTE0x0200 (Bit 9)Remote mode
SW_TARGET_REACHED0x0400 (Bit 10)Target reached
SW_INTERNAL_LIMIT0x0800 (Bit 11)Internal limit active
SW_OP_MODE_SPECIFIC_10x1000 (Bit 12)Mode-specific bit 1 (PP: Set-point acknowledge / HM: Homing attained)
SW_OP_MODE_SPECIFIC_20x2000 (Bit 13)Mode-specific bit 2 (CSP: Following error / HM: Homing error)

Complete examples​

CSP mode -- cyclic synchronous position control​

from darra_ethercat import EtherCATMaster, EcState, ModeCiA402, StateCiA402

with EtherCATMaster() as master:
if master.set_network(r"\Device\NPF_{GUID}") <= 0:
raise SystemExit("空总线: 未扫到从站") # Empty bus: no slaves found
master.config.loop_cycle = 1_000_000 # 1 ms bus cycle (ns)

if not master.set_state(EcState.SAFE_OP):
raise SystemExit(f"进入 SafeOp 失败: {master.last_state_error}") # Failed to enter SafeOp: {master.last_state_error}

drv = master[1].cia402
if not drv.scan_pdo_mapping(): # scan before entering OP, enables the PDO fast path
raise SystemExit("未找到任何 PDO 映射 (访问会全部走 SDO)") # No PDO mapping found (all access will go through SDO)

if master.has_dc is not True:
raise SystemExit("CSP 需要 DC 同步, 但 has_dc 未确认为 True") # CSP requires DC sync, but has_dc is not confirmed True
if master.configure_dc(1_000_000) <= 0:
raise SystemExit("DC 配置未接受任何从站") # DC configuration accepted no slaves
if not master.set_state(EcState.OP):
raise SystemExit(f"进入 OP 失败: {master.last_state_error}") # Failed to enter OP: {master.last_state_error}
master.start()

drv.operation_mode = ModeCiA402.CSP
if not drv.enable():
raise SystemExit(f"使能失败: {drv.state_drive.name}") # Enable failed: {drv.state_drive.name}

limit_min = drv.software_position_limit_min
limit_max = drv.software_position_limit_max

def on_pdo(mi):
if drv.state_drive != StateCiA402.OPERATION_ENABLED:
actual = drv.actual_position
if actual is not None:
drv.target_position = actual # not enabled: target follows actual to avoid jumps
return
target = calculate_next_position()
if (limit_min is not None and limit_max is not None
and not (limit_min <= target <= limit_max)):
raise RuntimeError(f"目标 {target} 超出软件限位 [{limit_min}, {limit_max}]") # Target {target} exceeds the software limits [{limit_min}, {limit_max}]
drv.target_position = target

master.on_pdo_cycle(on_pdo)

import time
time.sleep(10)
drv.disable()
master.stop()

PP mode -- profile position control​

drv = slave.cia402
drv.scan_pdo_mapping()

drv.operation_mode = ModeCiA402.PP
drv.profile_velocity = 10000
drv.profile_acceleration = 50000
drv.profile_deceleration = 50000

drv.enable()

# Send a positioning command
drv.new_setpoint(100000)

# Wait until reached
import time
while not drv.target_reached:
time.sleep(0.01)
drv.clear_new_setpoint()
print("定位完成") # Positioning complete

Direct control through SDO​

slave = master[1]

# Set the operation mode (CSP)
slave.coe.sdo_write_value(0x6060, 0, 8, dtype='i8')

# Write the control word: Shutdown
slave.coe.sdo_write_value(0x6040, 0, 0x06, dtype='u16')

# Write the control word: Switch On
slave.coe.sdo_write_value(0x6040, 0, 0x07, dtype='u16')

# Write the control word: Enable Operation
slave.coe.sdo_write_value(0x6040, 0, 0x0F, dtype='u16')

# Read the status word
sw = slave.coe.sdo_read_value(0x6041, 0, dtype='u16')
print(f"StatusWord: 0x{sw:04X}")

# Write the target position
slave.coe.sdo_write_value(0x607A, 0, 100000, dtype='i32')