Skip to main content

CiA 402 — Servo drive support

CiA 402 (IEC 61800-7-204) is the CoE-based device protocol for servo drives. CiA402Instance wraps the state machine, the operating modes and access to the motion parameters.

CiA 402 runs on top of CoE (SDO) and is available only when the slave supports CoE.

Accessed through slave.CoE.CiA402. null when the slave does not support CiA 402.​

CSP / synchronized axis hard rules
  • Cyclic synchronous position mode is fixed at 0x6060 = 8; under CSP do not write 0x001F (bit 4 is the PP/HM NewSetpoint).
  • Use (statusWord & 0x6F) for state checks: == 0x27 = OperationEnabled. To detect a fault use (statusWord & 0x4F) == 0x08 (0x4F only looks at faults and cannot be used to judge the operating state).
  • While not enabled, during a handshake and during a group stop, the target position always equals the actual position, to avoid jumps.
  • A fault reset sends 0x86 in the OP process data (bit 7 rising edge + bit 2 = 1); do the two-phase form as 0x0006 → 0x0086 over two cycles, and do not Sleep inside the PDO callback.
  • Issue all axes from the same PDO callback (ProcessDataCyclicSync), one axis after another; do not start a thread per axis.
  • The 0x1F of single-axis PP must not be copied to CSP / synchronized axes; synchronized axes use CSP + DC only.

PDO initialization​

InitializePdoOffsets()​

public void InitializePdoOffsets()

Reads the 0x1C12 / 0x1C13 PDO Assignment objects and resolves each object's offset in the IOmap. Accessing a PDO property such as StateDrive for the first time also initializes them, so a manual call is usually unnecessary.

var drv = slave.CoE.CiA402;
drv.InitializePdoOffsets();
drv.OperationMode = ModeCiA402.CSP;

Data source: PDO first, SDO fallback​

Motion parameters are read from the PDO offset first (zero bus overhead); when the offset is unresolved the class first tries to resolve it, and if the offset still cannot be obtained it goes to SDO (not counted in PdoFallbackCount). When the PDO bounds check fails it falls back to SDO truthfully and increments PdoFallbackCount. Configuration parameters (profile, limits, option codes and so on) go over SDO. For cyclic control use the properties directly and do not issue a manual SDORead every cycle.

State and state machine​

StateDrive​

public StateCiA402 StateDrive { get; }
public enum StateCiA402
{
NotReadyToSwitchOn = 0, // initializing
SwitchOnDisabled = 1, // drive disabled
ReadyToSwitchOn = 2, // ready to switch on
SwitchedOn = 3, // switched on
OperationEnabled = 4, // operation enabled
QuickStopActive = 5, // quick stop
FaultReactionActive = 6, // fault reaction active
Fault = 7, // fault
Unknown = 99 // unknown state
}

Example:

var state = slave.CoE.CiA402.StateDrive;
Console.WriteLine(state.ToString()); // "OperationEnabled"

ParseState(ushort statusword)​

public static StateCiA402 ParseState(ushort statusword)

Parses the drive state from the status word; StateDrive returns this parse result. Pure computation, no slave access.

Parameters: statusword — raw status word value.

Return value: StateCiA402 — drive state enum.

Statusword​

public ushort Statusword { get; }

Raw status word value. Commonly used derived properties:

CategoryPropertyTypeRead/writeDescription
Status wordTargetReachedboolread-onlyTarget reached (Bit 10)
HasFaultboolread-onlyFault present (Bit 3)
HasWarningboolread-onlyWarning present (Bit 7)
IsRemoteboolread-onlyRemote mode active (Bit 9)
HomingAttainedboolread-onlyHoming attained (Bit 12)
HomingErrorboolread-onlyHoming error (Bit 13)

Controlword​

public ushort Controlword { get; set; }

Read/write control word. Commonly used constants:

CategoryConstantValueDescription
Control wordCW_DISABLE_VOLTAGE0x00Disable voltage
CW_QUICK_STOP0x02Quick stop
CW_SHUTDOWN0x06Shutdown command
CW_SWITCH_ON0x07Switch-on command
CW_ENABLE_OPERATION0x0FEnable operation
CW_FAULT_RESET0x86Fault reset (bit 7 rising edge + bit 2 = 1; 0x80 alone is forbidden)
CW_HALT0x0100Halt bit (Bit 8, halt without disabling)
Status wordSW_OPERATION_ENABLED0x0004Operation enabled (Bit 2)
SW_FAULT0x0008Fault (Bit 3)
SW_TARGET_REACHED0x0400Target reached (Bit 10)

Example:

ushort sw = slave.CoE.CiA402.Statusword;
slave.CoE.CiA402.Controlword = 0x000F; // hold only after 0x06→0x07→0x0F has completed; to enable, call Enable() directly

For the full set of status word bit constants see status word bitmask constants; for runtime decisions prefer the derived properties above.

Enable(int maxRetries = 10)​

public bool Enable(int maxRetries = 10)

Writes 0x06 → 0x07 → 0x0F following the CiA 402-2 state machine and returns OperationEnabled only when the state parses as true. When the current state is Fault / FaultReaction it returns false directly: it does not reset automatically and does not treat a fault state as enabled. Recovery from QuickStopActive goes DisableVoltage → Shutdown → SwitchOn → EnableOperation; it does not read 0x605A and does not perform T16.

Parameters: maxRetries — maximum number of retries, default 10.

Return value: true = enabled up to OperationEnabled; false = failure / timeout / current fault (including Fault, which needs FaultReset first).

if (drv.Enable())
{
drv.TargetPosition = nextPosition;
}
else
{
Console.WriteLine($"使能失败, 当前状态: {drv.StateDrive}"); // Enable failed, current state: {drv.StateDrive}
}

Disable()​

public void Disable()

Disables the servo (→ SwitchOnDisabled), switching the power off completely.

DisableOperation()​

public void DisableOperation()

Disables operation (Transition 5: OperationEnabled → SwitchedOn). The motor stays powered, so Enable() can be called again quickly.

QuickStop()​

public void QuickStop()

Quick stop (→ QuickStopActive).

FaultReset()​

public void FaultReset()

Clears the fault. The low phase writes Shutdown 0x0006 (bit 2 = 1, does not trigger QuickStop); the high phase writes 0x0086 (bit 7 rising edge + bit 2 = 1). 0x0000 / 0x0080 are forbidden (bit 2 is active low and would also trigger QuickStop).

The reset pulse takes effect only in the OP process data; calling it outside OP reports an error directly and never silently falls back to SDO to fake the pulse. After sending the pulse the full implementation checks 0x7500 and clears the sync error counter (several SDO reads and writes), so it must not be called from a PDO callback; on the real-time path use FaultResetStep below.

FaultResetStep(int step)​

public bool FaultResetStep(int step)

A non-blocking single step of the fault reset, for use in PDO callbacks: the first cycle writes step=0 with 0x0006, the second cycle writes step=1 with 0x0086. Do not Thread.Sleep.

int fr = 0;
master.Events.ProcessDataCyclicSync += (mi) =>
{
if (drv.HasFault && fr < 2)
drv.FaultResetStep(fr++); // cycle 0 writes 0x06, cycle 1 writes 0x86
};

Disable / DisableOperation / QuickStop only write the control word; Enable advances the state machine according to maxRetries; FaultReset performs an SDO clear and read-back and belongs to the non-real-time path. Writing the control word itself does not block waiting for a state, but it is only transmitted over PDO in OP: writing Controlword in a non-OP state throws InvalidOperationException, and writing the control word over SDO produces no output effect.

RequestTransition(StateCiA402 target)​

public bool RequestTransition(StateCiA402 target)

Validates the transition against the CiA 402-2 T1–T16 transition diagram; an illegal transition (for example jumping straight from Fault → OperationEnabled) returns false and sends no command.

Parameters: target — target state. Return value: true = the transition is legal and the corresponding control word has been sent.

When the control word of the target transition is Fault Reset (for example Fault → SwitchOnDisabled), the full fault reset sequence actually runs (including SDO reads and writes), so do not call it from a PDO callback.

if (drv.RequestTransition(StateCiA402.SwitchedOn))
Console.WriteLine("已请求 → SwitchedOn"); // Requested → SwitchedOn

GetTransitionCommand(StateCiA402 current, StateCiA402 target)​

public static ushort GetTransitionCommand(StateCiA402 current, StateCiA402 target)

Looks up the legal control word for (current → target); pure computation. Returns 0xFFFF for an illegal transition.

ushort cw = CiA402Instance.GetTransitionCommand(
StateCiA402.SwitchOnDisabled, StateCiA402.ReadyToSwitchOn);
if (cw != 0xFFFF)
drv.Controlword = cw;

Operation modes​

public ModeCiA402 OperationMode { get; set; }
public enum ModeCiA402 : sbyte
{
PP = 1, // profile position
VL = 2, // velocity
PV = 3, // profile velocity
PT = 4, // profile torque
HM = 6, // homing
IP = 7, // interpolated position
CSP = 8, // cyclic synchronous position
CSV = 9, // cyclic synchronous velocity
CST = 10, // cyclic synchronous torque
CSTCA = 11 // cyclic synchronous torque with commutation angle
}
drv.OperationMode = ModeCiA402.CSP;
Console.WriteLine(drv.OperationMode); // "CSP"

Use IsModeSupported(ModeCiA402 mode) to check whether a mode is supported (reads the 0x6502 bitmask). Before switching modes, first confirm CanSwitchModeViaPdo or that the slave state allows the switch.

IsModeSupported(ModeCiA402 mode)​

public bool IsModeSupported(ModeCiA402 mode)

Parameters: mode — the operating mode to check. Return value: whether the slave's bitmask declares support for that mode.

if (drv.IsModeSupported(ModeCiA402.CSP))
drv.OperationMode = ModeCiA402.CSP;

When CanSwitchModeViaPdo is true the mode switch goes over PDO (0x6060 is already in the RxPDO and the IOmap has been allocated); when the slave is in OP but has no usable RxPDO mapping the class throws directly, and falling back to SDO is forbidden — only a non-OP state uses SDO. A failed switch is never silent: read back OperationMode to confirm whether the slave accepted it. TryReadOperationModeDisplay() reads the mode the drive actually applies (0x6061).

Parameter table​

CategoryPropertyTypeRead/writeDescription
MotionPositionActualintread-onlyActual position (0x6064)
VelocityActualintread-onlyActual velocity (0x606C)
TorqueActualshortread-onlyActual torque, thousandths of rated (0x6077)
TargetPositionintread/writeTarget position (0x607A)
TargetVelocityintread/writeTarget velocity (0x60FF)
TargetTorqueshortread/writeTarget torque, thousandths of rated (0x6071)
ProfileProfileVelocityuintread/writeProfile velocity (0x6081)
ProfileAccelerationuintread/writeProfile acceleration (0x6083)
ProfileDecelerationuintread/writeProfile deceleration (0x6084)
MotionProfileTypeshortread/write0 = linear ramp, 1 = sine, 2 = parabolic (S-curve, 0x6086)
PolarityPolaritybyteread/write0x607E; bit 6 = velocity inversion, bit 7 = position inversion
LimitsSoftwarePositionLimitMin / Maxintread/writeSoftware position limits (0x607D:01/02)
HomingHomingMethodsbyteread/writeHoming method (0x6098)
HomeOffsetintread/writeHoming offset (0x607C)
HomingSpeedSearch / HomingSpeedZerouintread/writeHoming search / zero speed (0x6099:01/02)
HomingAccelerationuintread/writeHoming acceleration (0x609A)
TorqueMaxTorqueushortread/writeMaximum torque, thousandths of rated (0x6072)
MotorRatedTorqueuintread/writeMotor rated torque, mNm (0x6076)
PositiveTorqueLimit / NegativeTorqueLimitushortread/writePositive / negative torque limits (0x60E0/0x60E1)
OffsetsPositionOffset / VelocityOffsetintread/writeAdded to the CSP / CSV target (0x60B0 / 0x60B1)
InterpolationInterpolationTimePeriodValue / Indexbyte / sbyteread/write0x60C2; period = Value × 10^Index seconds
StopQuickStopDecelerationuintread/writeQuick stop deceleration (0x6085)
Digital IODigitalInputsuintread-onlyDigital input bitmap (0x60FD)
DigitalOutputsuintread/writeDigital output bitmap (0x60FE:01)
SynchronizationSynchronizationSettingsushortread/writeSynchronization settings (0x60D9:01)
DriveSyncStatusushortread-onlyRaw drive synchronization status (0x60DA:00)
Touch probeTouchProbeStatus / TouchProbePositiveEdge / TouchProbeNegativeEdgeushort / int / intread-onlyTouch probe status and captured positions (0x60B9 / 0x60BA / 0x60BB)
var drv = slave.CoE.CiA402;

// Motion parameters: read actual values
Console.WriteLine($"位置: {drv.PositionActual}"); // Position: {drv.PositionActual}
Console.WriteLine($"速度: {drv.VelocityActual}"); // Velocity: {drv.VelocityActual}
short torque = drv.TorqueActual; // thousandths of rated torque

// Motion parameters: write target values
drv.TargetPosition = 100000;
drv.TargetVelocity = 5000;
drv.TargetTorque = 200; // thousandths of rated torque

// Profile parameters
drv.ProfileVelocity = 10000;
drv.ProfileAcceleration = 50000;
drv.ProfileDeceleration = 50000;

// Polarity and profile configuration
drv.Polarity = 0x80; // invert position direction
drv.MotionProfileType = 2; // S-curve
drv.QuickStopDeceleration = 100000;

// Extended motion parameters
drv.MaxTorque = 1000; // 100% of rated
uint rated = drv.MotorRatedTorque; // motor rated torque (0x6076), unit mNm
drv.PositionOffset = 100; // CSP offset
drv.VelocityOffset = 50; // CSV offset
drv.InterpolationTimePeriodValue = 1; // interpolation time period: 1ms = 1 × 10^(-3) s
drv.InterpolationTimePeriodIndex = -3;

// Torque limits (thousandths of rated torque)
drv.PositiveTorqueLimit = 500;
drv.NegativeTorqueLimit = 500;

// Digital IO
uint inputs = drv.DigitalInputs;
bool limitSwitch = (inputs & 0x01) != 0; // bit 0
drv.DigitalOutputs = 0x03; // output bits 0 and 1

// Software position limits
drv.SoftwarePositionLimitMin = -1000000;
drv.SoftwarePositionLimitMax = 1000000;

// Synchronization
ushort syncStatus = drv.DriveSyncStatus;
Console.WriteLine($"同步状态: 0x{syncStatus:X4}"); // Sync status: 0x{syncStatus:X4}
drv.SynchronizationSettings = 0x0001;

Writes to profile parameters throw InvalidOperationException on failure; they are never silently dropped.

A few read/write conventions:

  • PositionOffset / VelocityOffset are added to the target value only in CSP / CSV mode and have no effect in other modes.
  • InterpolationTimePeriodValue + InterpolationTimePeriodIndex express the actual period as Value × 10^Index seconds; for example 1 ms is written as Value=1, Index=-3.
  • DigitalInputs is a 32-bit bitmap: bit0 = negative limit, bit1 = positive limit, bit2 = home switch; the remaining bits are defined by the drive.
  • The bit definitions of TouchProbeStatus are implemented by the drive and correspond to the function bits of ConfigureTouchProbe; captured positions are in TouchProbePositiveEdge / TouchProbeNegativeEdge.
  • DriveSyncStatus is the raw register value of 0x60DA:00; whether the drive is already synchronized to the master clock must be interpreted with the drive manual.
  • Stop parameters (QuickStopDeceleration) take effect on a fault or a quick stop; after changing them, read back to confirm.

Fast motion control​

NewSetpoint(int position, bool relative = false)​

public void NewSetpoint(int position, bool relative = false)

Sends a positioning command in PP mode. Requires the current state to be OperationEnabled; in any other state (including a fault) it throws InvalidOperationException. On success it writes the target position and sets Controlword bit 4 (0x1F).

Parameters: position — target position; relative — true = relative positioning, false = absolute positioning (default).

ClearNewSetpoint()​

public void ClearNewSetpoint()

Clears bit 4 in PP mode; call it after TargetReached to complete the SetPointAck handshake. Also requires the current state to be OperationEnabled, otherwise it throws InvalidOperationException.

StartHoming()​

public void StartHoming()

Starts homing in HM mode. HomingMethod must be set and the state must be OperationEnabled; Fault / FaultReaction throw InvalidOperationException, and a fault state must never be treated as enabled. On success it writes Controlword 0x1F.

Related status bits: HomingAttained (bit12, homing attained) and HomingError (bit13, homing error). Configure the homing method, speeds, acceleration and offset with HomingMethod / HomingSpeedSearch / HomingSpeedZero / HomingAcceleration / HomeOffset respectively.

drv.OperationMode = ModeCiA402.HM;
drv.HomingMethod = 35; // home at the current position
drv.HomingSpeedSearch = 5000;
drv.HomingSpeedZero = 500;
drv.HomingAcceleration = 10000;

if (drv.StateDrive == StateCiA402.OperationEnabled)
drv.StartHoming();

ConfigureTouchProbe(ushort function)​

public void ConfigureTouchProbe(ushort function)

Configures the touch probe function (0x60B8). In function, bit 0 = enable touch probe 1, bit 1 = positive-edge trigger, bit 2 = first event.

drv.ConfigureTouchProbe(0x0003);          // bit0 enables touch probe 1 + bit1 positive-edge trigger
if ((drv.TouchProbeStatus & 0x0002) != 0) // rising edge captured
Console.WriteLine($"触探位置: {drv.TouchProbePositiveEdge}"); // Touch probe position: {drv.TouchProbePositiveEdge}

A complete PP positioning sequence: set the mode and profile parameters → enable → NewSetpoint → clear the flag after TargetReached:

drv.OperationMode = ModeCiA402.PP;
drv.ProfileVelocity = 10000;
drv.ProfileAcceleration = 50000;

if (drv.StateDrive == StateCiA402.OperationEnabled)
{
drv.NewSetpoint(100000); // absolute positioning
// drv.NewSetpoint(5000, true); // relative move
}

if (drv.TargetReached)
drv.ClearNewSetpoint();

Standard object index constants​

These can be combined with OD property access or slave.CoE.SDORead / SDOWrite:

ConstantValueDescription
OD_CONTROLWORD0x6040Control word
OD_STATUSWORD0x6041Status word
OD_MODES_OF_OPERATION0x6060Modes of operation setting
OD_MODES_OF_OPERATION_DISPLAY0x6061Modes of operation display
OD_TARGET_POSITION0x607ATarget position
OD_POSITION_ACTUAL0x6064Actual position
OD_TARGET_VELOCITY0x60FFTarget velocity
OD_VELOCITY_ACTUAL0x606CActual velocity
OD_TARGET_TORQUE0x6071Target torque
OD_TORQUE_ACTUAL0x6077Actual torque
OD_PROFILE_VELOCITY0x6081Profile velocity
OD_PROFILE_ACCELERATION0x6083Profile acceleration
OD_PROFILE_DECELERATION0x6084Profile deceleration
OD_MAX_TORQUE0x6072Maximum torque
OD_MOTOR_RATED_TORQUE0x6076Motor rated torque
OD_HOME_OFFSET0x607CHoming offset
OD_SOFTWARE_POSITION_LIMIT0x607DSoftware position limit
OD_POLARITY0x607EPolarity
OD_MAX_PROFILE_VELOCITY0x6080Maximum profile velocity
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_DIGITAL_INPUTS0x60FDDigital inputs
OD_DIGITAL_OUTPUTS0x60FEDigital outputs
OD_QUICK_STOP_OPTION_CODE0x605AQuick stop option code
OD_QUICK_STOP_DECELERATION0x6085Quick stop deceleration
OD_SUPPORTED_DRIVE_MODES0x6502Supported drive modes bitmask
OD_ERROR_CODE0x603FCurrent error code (read-only)
OD_DRIVE_DATA0x6510Vendor-specific drive data (RECORD, read-only)
OD_SYNC_ERROR_COUNTER0x10F1Sync error counter (:01 = the counter itself, :02 = upper limit, clear :01 only)
OD_SYNC_ERROR_COUNTER_SUB0x01Subindex of the sync error counter itself (0x10F1:01)
SYNC_ERROR_CODE_75000x7500DS402 communication error code; a reset must also clear the sync error counter itself

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
SW_OP_MODE_SPECIFIC_20x2000 (Bit 13)Mode-specific bit 2

Control word command constants (CW_*) are listed in the constant table under Controlword.

Drive information​

SupportedDriveModes​

public uint SupportedDriveModes { get; }

Supported modes bitmask (0x6502): 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.

SupportedHomingMethods​

public sbyte[] SupportedHomingMethods { get; }

List of homing methods supported by the drive (0x60E3). Entries are sbyte: -128..-1 are vendor-specific methods, 0 is unselected, and 1..35 plus 37 are ETG.6010 standard methods.

Three cases:

  • Read succeeds and the slave returns entries → returns the array
  • Read succeeds but the slave returns 0 entries → returns an empty array (confirmed support for 0 methods)
  • Read fails or the slave does not support 0x60E3 → throws InvalidOperationException, which is distinct from supporting 0 methods
try
{
sbyte[] methods = drv.SupportedHomingMethods;
if (methods.Length == 0)
Console.WriteLine("从站确认支持 0 种回零方法"); // The slave confirms it supports 0 homing methods
else
Console.WriteLine($"支持 {methods.Length} 种回零方法"); // Supports {methods.Length} homing methods
}
catch (InvalidOperationException)
{
Console.WriteLine("回零方法读取失败, 按失败处理"); // Homing methods read failed, treated as a failure
}

Whether an entry number is an ETG.6010 standard method is checked with IsStandardHomingMethod (see below).

TxPdoDataInvalid​

public bool TxPdoDataInvalid { get; }

Whether the TxPDO data is invalid (0x603E). A non-zero value means the drive's TxPDO data cannot be trusted; on a read failure / when the object is unsupported it is treated as invalid and never pretends the data is valid.

if (!drv.TxPdoDataInvalid)
{
int pos = drv.PositionActual; // data is valid, safe to use
}

SupportedDriveModesDll​

public uint SupportedDriveModesDll { get; }

Queries the supported drive modes bitmask (0x6502); equivalent to the SupportedDriveModes property (it selects the read path automatically based on PDO / SDO availability). Another entry point for the same function; new code should use SupportedDriveModes.

GetSupportedHomingMethodsDll(int maxCount = 64)​

public sbyte[] GetSupportedHomingMethodsDll(int maxCount = 64)

Reads the list of supported homing methods (0x60E3; at most 35 ETG.6010 standard methods plus vendor-specific ones). Its exception semantics differ from the SupportedHomingMethods property: both a failure (SDO timeout / communication error / other abort) and lack of support (abort 0x06020000 / 0x06090011) return an empty array, and an empty array must not be read as supporting 0 homing methods — the two are not interchangeable.

Parameters: maxCount — maximum number of entries to read, default 64.

Return value: sbyte[] — list of homing method numbers (-128..-1 vendor-specific methods, 0 unselected, 1..35 and 37 ETG.6010 standard methods). Failure / lack of support / a genuinely empty list all return an empty array; when the three cases must be distinguished, use TryGetSupportedHomingMethods (a bool result) or the SupportedHomingMethods property (an exception).

var drv = slave.CoE.CiA402;

sbyte[] methods = drv.GetSupportedHomingMethodsDll();
if (methods.Length == 0)
{
// empty array = failure / unsupported / genuinely empty list; it does not mean 0 methods are supported
Console.WriteLine("回零方法读取为空, 需区分请用 TryGetSupportedHomingMethods 或 SupportedHomingMethods 属性"); // Homing methods came back empty; to tell the cases apart use TryGetSupportedHomingMethods or the SupportedHomingMethods property
}

foreach (sbyte m in methods)
{
bool standard = CiA402Instance.IsStandardHomingMethod(m);
Console.WriteLine($"回零方法 {m}: {(standard ? "ETG.6010 标准" : "厂商自定义")}"); // Homing method {m}: {(standard ? "ETG.6010 standard" : "vendor-specific")}
}

TryGetSupportedHomingMethods(out sbyte[] methods, int maxCount = 64)​

public bool TryGetSupportedHomingMethods(out sbyte[] methods, int maxCount = 64)

The discriminating variant of GetSupportedHomingMethodsDll: it separates "list read", "list read and genuinely empty", and "not read".

Parameters:

  • methods (out sbyte[]) — list of homing method numbers; an empty array (meaningless) when the method returns false
  • maxCount (int) — maximum number of entries to read, default 64

Return value:

  • bool — true = read succeeded (methods may be an empty array, meaning the slave confirmed support for 0 methods); false = read failure or an invalid maxCount

Description:

  • maxCount <= 0 returns false without touching the device — no device read means nothing to deliver.
  • A count larger than maxCount reported by the read is treated as untrustworthy and likewise returns false; the data is not truncated to fit.
  • A read failure (fail-closed) returns false rather than handing back a partial list.
  • Throws Slave when the Close() has been disposed (after ObjectDisposedException).

Example:

if (drv.TryGetSupportedHomingMethods(out sbyte[] homing, maxCount: 64))
{
Console.WriteLine(homing.Length == 0
? "从站确认支持 0 种回零方法" // The slave confirms it supports 0 homing methods
: $"支持 {homing.Length} 种回零方法"); // Supports {homing.Length} homing methods
}
else
{
Console.WriteLine("回零方法读取失败, 不能断言不支持任何方法"); // Homing methods read failed, cannot assert that no method is supported
}

IsStandardHomingMethod(sbyte method)​

public static bool IsStandardHomingMethod(sbyte method)

Checks whether a homing method number is an ETG.6010 standard method (1..35 or 37). Static method, pure computation, no slave access.

Parameters: method — homing method number. Return value: true = standard method, false = vendor-specific or unselected.

Faults and errors​

CategoryMemberTypeRead/writeDescription
FaultErrorCodeushortread-onlyCurrent error code (0x603F); returns the 0xFFFF sentinel on a read failure
GetErrorHistory(int maxCount = 32)uint[]read-onlyDrive-internal error history (0x1003)
TryGetErrorHistory(int maxCount = 32)boolread-onlyDiscriminating variant of 0x1003; false = read failure or an invalid maxCount
ClearErrorHistory()boolwrite-onlyClears the internal error history
ClearSyncErrorCounter()boolwrite-onlyClears the sync error counter 0x10F1:01; after a 0x7500 communication fault reset, not clearing it latches the error again immediately
Option codesQuickStopOption / ShutdownOption / DisableOperationOptionshortread/write0x605A / 0x605B / 0x605C
HaltOption / FaultReactionOptionshortread/write0x605D / 0x605E

Option code values:

  • QuickStopOption: 0 = immediate switch-off, 1 = ramp down, 2 = Quick Stop deceleration, 3 = torque stop; 5/6/7/8 = decelerate and then stay in QuickStopActive (T16 straight back to OperationEnabled is allowed)
  • ShutdownOption / DisableOperationOption: the deceleration behavior on the corresponding state transition
  • HaltOption: behavior of Controlword bit8 (1 = profile ramp, 2 = Quick Stop deceleration, 3 = torque stop)
  • FaultReactionOption: -1 = vendor-defined, 0 = immediate switch-off, 1/2/3 = decelerate

Error history: GetErrorHistory(maxCount) reads the Error Code array of 0x1003 (each entry is the low 16 bits of an Error Code). It is the drive-internal persistent history and is not the same data as the EMCY buffer on the master side; a read failure is treated as a failure (empty array). ClearErrorHistory() writes 0x1003:00 = 0 to clear it. To tell a genuinely empty history from a read failure, use TryGetErrorHistory (see below).

Read-failure sentinels come in three constant tiers: ReadFailSentinelI16 (short, -32768) for the option code properties, ReadFailSentinelU16 (ushort, 0xFFFF) for ErrorCode, and ReadFailSentinelInt (int, -1) for the low-level return of counter-style read interfaces. Test them with the short / ushort / int overloads of CiA402Instance.IsReadFailSentinel(v) and treat a hit as a failure; never treat a sentinel as a real value. The sentinel convention applies to the five option code properties. GetErrorHistory / GetSupportedHomingMethodsDll return an empty array on a read failure, and an empty array likewise does not prove that the drive has no such records.

note

The sbyte method numbers (entries of the 0x60E3 list, with -128..-1 being vendor-specific methods) are real values, not sentinels; do not use IsReadFailSentinel to test them.

drv.QuickStopOption = 5;          // decelerate and then stay in QuickStopActive
drv.FaultReactionOption = 2; // fault reaction ramps down

ushort ec = drv.ErrorCode;
if (CiA402Instance.IsReadFailSentinel(ec))
Console.WriteLine("Error Code 读取失败, 按失败处理"); // Error Code read failed, treated as a failure
else
Console.WriteLine($"Error Code = 0x{ec:X4}");

uint[] history = drv.GetErrorHistory(maxCount: 16);
drv.ClearErrorHistory();

TryGetErrorHistory(out uint[] history, int maxCount = 32)​

public bool TryGetErrorHistory(out uint[] history, int maxCount = 32)

The discriminating variant of GetErrorHistory: it separates "history read", "history read and genuinely empty", and "not read".

Parameters:

  • history (out uint[]) — array of error codes (low 16 bits); an empty array (meaningless) when the method returns false
  • maxCount (int) — maximum number of entries to read, default 32

Return value:

  • bool — true = read succeeded (history may be an empty array, meaning the history really is empty); false = read failure or an invalid maxCount

Description:

  • maxCount <= 0 returns false without touching the device — no device read means nothing to deliver.
  • A count larger than maxCount reported by the read is treated as untrustworthy and likewise returns false; the data is not truncated to fit.
  • A read failure (fail-closed) returns false rather than handing back a partial history.
  • Throws Slave when the Close() has been disposed (after ObjectDisposedException).

Example:

if (drv.TryGetErrorHistory(out uint[] history, maxCount: 16))
Console.WriteLine(history.Length == 0 ? "驱动器错误历史为空" : $"读到 {history.Length} 条错误"); // drive error history is empty / read {history.Length} errors
else
Console.WriteLine("错误历史读取失败, 空数组不代表没有历史"); // Error history read failed, an empty array does not mean there is no history

Observable read-only reads​

When "true value / not supported by the slave / read failure" must be distinguished, use the TryRead* family; it returns CiA402ReadResult<T>: Status is Success / NotSupported / ReadFailed, and AbortCode is the SDO abort (0 = no abort).

CategoryMethodTypeRead/writeDescription
GeneralTryReadObject<T>(ushort index, byte subindex = 0)CiA402ReadResult<T>read-onlyOne read-only SDO access to an arbitrary object
StateTryReadStatusword()CiA402ReadResult<ushort>read-only0x6041
MotionTryReadPositionActual()CiA402ReadResult<int>read-only0x6064
TryReadVelocityActual()CiA402ReadResult<int>read-only0x606C
TryReadTorqueActual()CiA402ReadResult<short>read-only0x6077
ModeTryReadOperationModeDisplay()CiA402ReadResult<ModeCiA402>read-only0x6061
TryReadSupportedDriveModes()CiA402ReadResult<uint>read-only0x6502
FaultTryReadErrorCode()CiA402ReadResult<ushort>read-only0x603F
Digital IOTryReadDigitalInputs()CiA402ReadResult<uint>read-only0x60FD
VendorTryReadDriveData(byte subindex)CiA402ReadResult<uint>read-only0x6510

TryReadObject<T>(ushort index, byte subindex = 0)​

public CiA402ReadResult<T> TryReadObject<T>(ushort index, byte subindex = 0) where T : struct

Generic observable read — one read-only SDO attempt on an arbitrary CiA 402 object. Purely read-only, with no side effects such as writing the object dictionary, writing PDOs or changing state. T supports byte / sbyte / ushort / short / uint / int / ulong / long.

Parameters:

  • index (ushort) — object index
  • subindex (byte) — subindex, default 0

Return value:

  • CiA402ReadResult<T> — the read result with its status

Related structures:

public enum CiA402ReadStatus
{
NotAttempted = 0, // read not attempted yet
Success = 1, // read succeeded; the returned value is the slave's true value
NotSupported = 2, // the slave does not support this object (SDO abort 0x06020000 / 0x06090011)
ReadFailed = 3 // SDO read failed (timeout / communication error / other abort)
}
public readonly struct CiA402ReadResult<T> where T : struct
  • Value (T) — the value read; meaningful only when Status == Success, otherwise default
  • Status (CiA402ReadStatus) — read status (success / not supported / failed / not attempted)
  • AbortCode (uint) — SDO Abort Code (0 = no abort; on not supported / failure the actual abort code)
  • Ok (bool) — whether the read succeeded and the value can be trusted (Status == Success)
  • NotSupported (bool) — whether the slave does not support the object (Status == NotSupported)

Example:

var drv = slave.CoE.CiA402;
var r = drv.TryReadObject<uint>(0x6502, 0);
if (r.Ok)
Console.WriteLine($"Supported Drive Modes = 0x{r.Value:X8}");
else if (r.NotSupported)
Console.WriteLine("从站不支持 0x6502"); // Slave does not support 0x6502
else
Console.WriteLine($"读失败 abort=0x{r.AbortCode:X8}"); // Read failed abort=0x{r.AbortCode:X8}

The preset methods in the table above are convenience wrappers around TryReadObject<T>. TryReadStatusword / TryReadPositionActual / TryReadVelocityActual / TryReadOperationModeDisplay force a read-only SDO path (they do not take the PDO), which makes it easy to distinguish "the slave really returned a value" from "read failure / not supported"; for high-frequency reads keep using the corresponding PDO-first properties (Statusword / PositionActual / VelocityActual / OperationMode), which cost no network traffic. TryReadOperationModeDisplay reads 0x6061 and confirms the mode the drive actually applies. TryReadErrorCode and ErrorCode use independent read paths.

Preset read example:

var drv = slave.CoE.CiA402;

// Power-on self check: distinguish "the slave really returns a 0 mode bitmask" from "reading 0x6502 failed / is unsupported"
var modes = drv.TryReadSupportedDriveModes();
switch (modes.Status)
{
case CiA402ReadStatus.Success:
Console.WriteLine($"支持模式掩码 = 0x{modes.Value:X8}"); // Supported modes mask = 0x{modes.Value:X8}
break;
case CiA402ReadStatus.NotSupported:
Console.WriteLine("从站不支持 0x6502 (非标准 CiA 402 驱动?)"); // Slave does not support 0x6502 (non-standard CiA 402 drive?)
break;
case CiA402ReadStatus.ReadFailed:
Console.WriteLine($"读 0x6502 失败 abort=0x{modes.AbortCode:X8}"); // Read of 0x6502 failed abort=0x{modes.AbortCode:X8}
break;
}

// Explicit mode read (for when the high-frequency PDO path cannot report a failure)
var md = drv.TryReadOperationModeDisplay();
if (md.Ok)
Console.WriteLine($"当前模式: {md.Value}"); // enum member name, e.g. "CSP"

Last read-only status query​

After reading any public read-only property through the SDO fallback path, query the following members to tell whether a returned value is a true value or the default used on a read failure:

  • LastReadStatus (CiA402ReadStatus, read-only) — status of the most recent read-only SDO attempt (success / not supported / failed / not attempted)
  • LastReadAbortCode (uint, read-only) — Abort Code of the most recent read-only failure / lack of support (0 = no abort / success; 0x06020000 = object does not exist, 0x06090011 = subindex does not exist, 0x05040000 = timeout)
  • LastReadObject ((ushort Index, byte SubIndex), read-only) — index / subindex of the most recent read-only SDO attempt, for diagnostic localization
  • SupportedDriveModesReadable (bool, read-only) — whether the slave really supports the 0x6502 object (judged from the read-only attempts): true = the read succeeded; false = unsupported or the read failed, use LastReadStatus to tell which
var drv = slave.CoE.CiA402;

// After reading an ordinary read-only property, use LastReadStatus to tell whether 0 is a true value or a failure
uint modes = drv.SupportedDriveModes;
if (drv.LastReadStatus != CiA402ReadStatus.Success)
Console.WriteLine($"0x6502 读取异常: {drv.LastReadStatus}, " + // 0x6502 read exception: {drv.LastReadStatus},
$"abort=0x{drv.LastReadAbortCode:X8}, 对象=0x{drv.LastReadObject.Index:X4}"); // abort=0x{drv.LastReadAbortCode:X8}, object=0x{drv.LastReadObject.Index:X4}

Use SDORead(index, subindex, out SdoReadResult detail) when the raw bytes and the WKC are needed. PdoFallbackCount is the cumulative number of times the PDO bounds check failed and the call fell back to SDO; whether the PDO path is being used is shown by the corresponding HasPdo* properties.

Diagnostic properties​

CategoryPropertyTypeRead/writeDescription
PDOPdoInitializedboolread-onlyWhether the PDO offsets have been initialized
HasAnyPdoOffsetboolread-onlyPDO offsets resolved in at least one direction, Rx or Tx
CanSwitchModeViaPdoboolread-onlyWhether the mode can be switched over PDO
HasPdoModesDisplay / HasPdoVelocityActualboolread-onlyWhether the corresponding quantity is in the TxPDO (zero-overhead read)
HasPdoStatusword / HasPdoPositionActual / HasPdoControlword / HasPdoTargetPositionboolread-onlyWhether the corresponding quantity hits the PDO mapping (whether the PDO mapping is known); false = not mapped or the offset is unresolved, so a read can only come from the SDO fallback
PdoFallbackCountlongread-onlyCumulative number of times the PDO bounds check failed and the call fell back to SDO (mapping health)
StateSlaveEcStateEcStateread-onlyCurrent EtherCAT state of the slave
IsMasterDisposedboolread-onlyWhether the master has been disposed

ResetPdoOffsets() resets the offset cache; call it when the slave state degrades — the next transition to SafeOp or above reinitializes the offsets.

public void ResetPdoOffsets()

Typical sequence​

  1. Confirm that slave.CoE.CiA402 is not null and that the slave has entered OP.
  2. InitializePdoOffsets() (or wait for the first access to a PDO property to initialize the offsets automatically).
  3. Read SupportedDriveModes, confirm with IsModeSupported, then set OperationMode.
  4. Configure limits, profile, homing and other parameters.
  5. Enable() up to OperationEnabled.
  6. In the ProcessDataCyclicSync callback, write TargetPosition / TargetVelocity / TargetTorque every cycle.
  7. Stop as needed with DisableOperation() / QuickStop() / Disable().
  8. On a fault call FaultReset() first; inside a PDO callback use FaultResetStep(0) → FaultResetStep(1) instead.

Real-time behavior and threads​

  • Motion / state properties use the PDO first; do not issue extra SDO traffic for high-frequency cyclic reads.
  • Disable / DisableOperation / QuickStop only write the control word; Enable advances the state machine according to the retry count; FaultReset includes an SDO clear and read-back and must not be put in a real-time callback.
  • On the real-time path a fault reset is split into the two cycles FaultResetStep(0) → FaultResetStep(1).
  • Inside a PDO callback only do assignments and FaultResetStep; do not Thread.Sleep, and do not perform bulk SDO or logging IO.
  • Issue several axes from the same callback, one axis after another; do not start a thread per axis.
  • TryRead* / LastRead* are diagnostic paths; use them only when a failure must be distinguished, and keep them out of the real-time cycle.

FAQ​

SymptomCheck order
Enable() returns falseLook at StateDrive first: for Fault / FaultReaction call FaultReset first; then look at ErrorCode (0x603F)
No movement after writing a target valueConfirm that the state is OperationEnabled, that OperationMode matches the target value type, and that neither the software nor the hardware limit is active
TargetReached stays falseCheck whether the profile velocity / acceleration is 0, whether the target exceeds a limit, and whether the drive reports TxPdoDataInvalid
Homing does not completeCheck whether HomingMethod is a method the drive supports and whether HomingError (bit13) is set
The value read back is always 0That property uses the folded PDO / SDO path, where a read failure and a true 0 cannot be distinguished; use the corresponding TryRead* instead
The mode cannot be switchedCall IsModeSupported(mode) first, then check CanSwitchModeViaPdo and the current slave state

Differences from CiA 401​

CiA 401 is a stateless generic I/O profile: no control word / status word / operating mode, only channel reads and writes plus error-safe values. For digital, analog and error-mode usage see CiA 401.

Full example​

CSP mode — cyclic synchronous position control​

var drv = slave.CoE.CiA402;
if (drv == null) return;

drv.InitializePdoOffsets();
drv.OperationMode = ModeCiA402.CSP;

if (!drv.Enable()) { Console.WriteLine($"使能失败: {drv.StateDrive}"); return; } // Enable failed: {drv.StateDrive}

master.Events.ProcessDataCyclicSync += (masterIndex) =>
{
drv.TargetPosition = CalculateNextPosition();
};

PP mode — profile position control​

var drv = slave.CoE.CiA402;
if (drv == null) return;

drv.InitializePdoOffsets();
drv.OperationMode = ModeCiA402.PP;
drv.ProfileVelocity = 10000;
drv.ProfileAcceleration = 50000;
drv.ProfileDeceleration = 50000;

// one-time enable
if (!drv.Enable()) { Console.WriteLine($"使能失败: {drv.StateDrive}"); return; } // Enable failed: {drv.StateDrive}

// send the positioning command
drv.NewSetpoint(100000);

// in the PDO callback, wait for the target and then clear the flag
bool done = false;
master.Events.ProcessDataCyclicSync += (masterIndex) =>
{
if (!done && drv.TargetReached)
{
drv.ClearNewSetpoint();
done = true;
}
};