Skip to main content

CiA 402 — Servo drive support

CiA 402 (IEC 61800-7-204) is the CoE-based device protocol for servo drives. CiA402 wraps drive state machine management, operating mode switching and motion parameter access.

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

Accessed directly through slave.cia402().​

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; for fault detection use (statusWord & 0x4F) == 0x08 (0x4F only looks at faults and cannot be used to 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 on the cyclic path sends 0x86 (bit 7 rising edge, with bit 2 held at 1); sending only 0x80 cannot clear the fault because bit 2 = 0. faultReset() completes 0x0006 → 0x0086 in two cycles; do not Sleep inside the PDO callback.
  • With multiple axes in the same PDO callback (addProcessDataCyclicSyncListener), issue each axis by writing the process image (not by calling an SDO method such as targetPosition(int), since SDO blocks the real-time callback); do not start a thread per axis; the 0x1F of single-axis PP must not be copied to CSP / synchronized axes, which use CSP + DC only.

PDO initialization​

initializePdoOffsets()​

public void initializePdoOffsets()

Parses the 0x1C12/0x1C13 PDO Assignment configuration and builds the "object index → IOmap byte offset" cache.

note

It must be called explicitly once; there is no implicit initialization — without it, pdoOffset() always returns -1 (properties such as stateDrive read the object dictionary over SDO and are unrelated to the PDO offset cache). Call it once after entering OP and before starting cyclic output.

Return value — none (void). Throws — none; failure is reported through pdoInitialized(). Failure semantics — truthful, nothing fabricated: on a scan failure pdoInitialized()=false, and offsets produced before the failure point remain queryable while no offsets are produced after it; the whole table is neither invalidated nor filled with invented offsets.

Example:

CiA402 drv = slave.cia402();
drv.initializePdoOffsets();
drv.operationMode(CiA402.ModeCiA402.CSP);

pdoOffset(short objectIndex, boolean input)​

public int pdoOffset(short objectIndex, boolean input)

Looks up an object's byte offset in the IOmap, so the cyclic path can read and write the process image directly by offset.

Parameters

ParameterTypeDescription
objectIndexshortObject index, e.g. 0x6041 (status word)
inputbooleantrue = TxPDO (master input direction); false = RxPDO (master output direction)

Return value — the byte offset; -1 = the object is not mapped, or initialization has not succeeded yet. Throws — none.

int posOff = drv.pdoOffset((short) 0x607A, false);   // Target position is in the RxPDO
if (posOff < 0) throw new IllegalStateException("0x607A 未映射到 RxPDO"); // (SDK output, = 0x607A is not mapped to RxPDO)
slave.PDO().out().get(posOff).asInt32(nextPosition);

resetPdoOffsets() / pdoInitialized() / pdoMappedObjectCount()​

public void    resetPdoOffsets()        // clear the cache
public boolean pdoInitialized() // whether the cache has been built
public int pdoMappedObjectCount() // number of resolved Rx + Tx mapped objects
  • resetPdoOffsets() — called when the slave state degrades; clears the cache. Call initializePdoOffsets() again the next time the slave reaches SafeOp+.
  • pdoInitialized() — true means the last scan actually read the assignment / mapping table (an empty mapping entry still counts as read; in that case every object offset is -1).
  • pdoMappedObjectCount() — total number of Rx + Tx objects; 0 means the slave maps no PDO at all.

None of the three throws and none issues a bus transaction (except initializePdoOffsets()).

State control​

enable() advances to OperationEnabled in a single call (completing the full state chain + Fault reset + QuickStop recovery + 0x605A option code evaluation); disable() / disableOperation() / quickStop() / faultReset() only write the control word and return immediately — verify the result with stateDrive().

Write observability: for every parameter write entry point (targetPosition(int), operationMode(mode), controlword(short), the various option code / homing / limit writes), a failure sets lastWriteOk()=false, and lastWriteAbortCode() records the abort code carried by this write (a concurrent SDO cannot overwrite it), while lastWriteIndex() / lastWriteSubIndex() identify the object that failed. The read path (readAttribute / tryRead*) likewise takes the abort code carried by this read when deciding success / not supported / failure; codes outside the table are kept verbatim.

MethodReturnRead/writeDescription
lastWriteOk()booleanread-onlyWhether the most recent write succeeded (initially true = nothing written yet)
lastWriteAbortCode()longread-onlyAbort code of the most recent write failure (0 on success)
lastWriteIndex() / lastWriteSubIndex()short / byteread-onlyObject location of the most recent write

This is a set of instance-level "most recent" states; concurrent writes from multiple threads overwrite each other. For per-call results, use the write method's own boolean return value.

enable() / enable(int maxRetries)​

public boolean enable()                   // default maxRetries=10
public boolean enable(int maxRetries)

Enables the drive: in one call it completes the full SwitchOnDisabled → ReadyToSwitchOn → SwitchedOn → OperationEnabled sequence per CiA 402-2, plus Fault reset and QuickStop recovery.

Parameters

ParameterTypeDefaultDescription
maxRetriesint10Maximum number of state machine retries; returns false once exhausted

Return value

  • boolean — true = enabled up to OperationEnabled; false = failure / timeout; use stateDrive() to see which step it stopped at

Throws — none. Timeout — returns as soon as the retries are exhausted and never waits forever; the total time depends on how the drive state machine responds, so do not call it inside a cyclic callback. Write observability — the state machine advance does not go through this class's parameter write entry points, so it does not update lastWriteOk() / lastWriteAbortCode(); on failure check stateDrive() and errorCode().

Example:

CiA402 drv = slave.cia402();
// one-shot enable (full state machine handled internally)
if (drv.enable()) {
drv.targetPosition(nextPosition);
} else {
System.out.println("使能失败, 当前状态: " + drv.stateDrive()); // Enable failed, current state:
}

disable()​

public boolean disable()                 // control word → 0x00

Disables the servo (→ SwitchOnDisabled), removing power completely.

Return value — true = the control word was written; false = the write failed (the disable was not issued; check lastWriteAbortCode() for the reason). Throws — none. Behavior — writes the control word once and returns without waiting for the state machine to settle; verify with stateDrive().

disableOperation()​

public boolean disableOperation()        // control word → 0x07

Disables operation (Transition 5: OperationEnabled → SwitchedOn). The motor stays energized, so enable() can be re-issued quickly.

Return value — true = the control word was written; false = the write failed (the command was not issued; check lastWriteAbortCode()). Throws — none. Behavior — same as disable(): writes the control word once; verify with stateDrive().

quickStop()​

public boolean quickStop()               // control word → 0x02

Quick stop (→ QuickStopActive). Deceleration and post-stop behavior are determined by quickStopOptionCode() (0x605A).

Return value — true = the control word was written; false = the write failed (check lastWriteAbortCode()). Throws — none. Behavior — same as disable(): writes the control word once; verify with stateDrive(). Recovering from QuickStopActive must not issue 0x0006 directly (that state does not accept the Shutdown combination): first call disable() (0x0000) back to SwitchOnDisabled, then enable() to run the full state machine.

faultReset()​

public boolean faultReset()

Clears the latched fault. It writes the control word in two phases: first 0x0006 (releases Quick Stop via bit 2), then after a short delay 0x0086 (adding the bit 7 Fault Reset rising edge), satisfying the 0→1 rising edge requirement of ETG.6010 §5.2.

Return value

  • true — both phases were written successfully
  • false — either phase failed to write, or the call was interrupted (the reset signal is incomplete and the fault is not cleared)

Throws — none; when interrupted it restores the interrupt flag and truthfully returns false instead of swallowing it as "reset succeeded". Check lastWriteAbortCode() for the failure reason.

Forbidden: 0x0000 / 0x0080 — control word bit 2 (Quick Stop) is active low: writing 0x0000 re-activates QuickStop, and writing 0x0080 also cannot clear the fault because bit 2 remains 0. The low phase must be 0x0006 and the high phase 0x0086.

Timeout — there is a fixed short delay between the two writes, so do not call it inside a PDO callback; in a cyclic scenario issue the two phases yourself in two separate cycles.

State reading​

stateDrive()​

public StateCiA402 stateDrive()

Reads the status word once (0x6041, one SDO transaction) and then classifies it per the CiA 402-2 state machine.

Return value — StateCiA402. Values and status word criteria (per statusword() & 0x6F):

EnumgetValue()Status word criterionMeaning
NotReadyToSwitchOn00x0000Initializing, not ready
SwitchOnDisabled10x0040Drive disabled (safe to change the mode / parameters)
ReadyToSwitchOn20x0021Ready, main circuit not energized
SwitchedOn30x0023Switched on, waiting for enable operation
OperationEnabled40x0027Operation enabled, motion commands may be issued
QuickStopActive50x0007Quick stop in progress
FaultReactionActive60x000FFault reaction active (fault bit set and the low 4 bits all 1)
Fault7Bit 3 = 1 and the low 4 bits ≠ 0x0FFault latched; requires faultReset()
Unknown99Any other combinationUnknown state

Throws — none. On an SDO read failure statusword() collapses to 0, so stateDrive() classifies it as NotReadyToSwitchOn, indistinguishable from the real initialization state; to tell them apart use tryReadStatusword().

public enum StateCiA402 {
NotReadyToSwitchOn(0), // initializing
SwitchOnDisabled(1), // drive disabled
ReadyToSwitchOn(2), // ready
SwitchedOn(3), // switched on
OperationEnabled(4), // operation enabled
QuickStopActive(5), // quick stop
FaultReactionActive(6), // fault reaction active
Fault(7), // fault
Unknown(99) // unknown state (fixed 99, not the enum ordinal)
}

Enum helpers:

public int getValue()                        // enum value (0..7 or 99)
public static StateCiA402 fromValue(int v) // reverse lookup; values outside the table return Unknown

Unknown is fixed at 99, not the enum ordinal (ordinal() is 8). Compare with the enum itself or getValue(), never with ordinal(); fromValue() returns Unknown for values outside the table and never invents a specific state.

Example:

CiA402.StateCiA402 state = slave.cia402().stateDrive();
System.out.println("驱动器状态: " + state); // Drive state:

statusword()​

public short statusword()                  // read 0x6041

Reads the raw status word value (one SDO transaction).

Return value — the status word; an SDO read failure collapses to 0, indistinguishable from a real 0. To tell them apart use tryReadStatusword(). Throws — none.

Related properties (each call re-reads the status word):

PropertyTypeRead/writeDescription
targetReached()booleanread-onlyTarget reached (Bit 10)
hasFault()booleanread-onlyFault present (Bit 3)
hasWarning()booleanread-onlyWarning present (Bit 7)
isRemote()booleanread-onlyRemote mode active (Bit 9)
homingAttained()booleanread-onlyHoming attained (Bit 12)
homingError()booleanread-onlyHoming error (Bit 13)

Calling them in a loop issues one transaction each time: on the cyclic path read statusword() once (or read the process image) and evaluate the bits yourself.

controlword()​

public short controlword()                 // read 0x6040
public boolean controlword(short value) // write 0x6040

Reads or writes the raw control word value (one SDO transaction).

Parameters — value: raw control word value; for command constants see control word command constants. Return value

  • Read form: the control word; a read failure collapses to 0
  • Write form: true = written; false = write failed (the command was not issued; check lastWriteAbortCode())

Throws — none, and no value validation is performed.

controlword((short) 0x000F) merely writes a value into the control word; it does not run the 0x06 → 0x07 → 0x0F sequence automatically. To enable the drive, call enable() directly.

Example:

short sw = slave.cia402().statusword();
slave.cia402().controlword((short) 0x000F); // only holds after 0x06→0x07→0x0F has completed; to enable, call enable() directly

Operating modes​

operationMode()​

public ModeCiA402 operationMode()             // read 0x6061 (mode display)
public boolean operationMode(ModeCiA402 mode) // write 0x6060

Reads or writes the operating mode. The read returns the mode display the drive actually applies (0x6061); the write sets the setpoint (0x6060).

Parameters

ParameterTypeDescription
modeModeCiA402Target mode; the value written is mode.value()

Return value

  • Read form: the current mode; on an SDO read failure it returns PP, indistinguishable from "the drive really is in PP" (to tell them apart use tryReadOperationModeDisplay())
  • Write form: true = written; false = write failed (check lastWriteAbortCode())

Throws — none.

A write returning true only means the SDO write succeeded; it does not mean the drive has accepted the mode: issue it in the state the drive manual requires (most require SwitchOnDisabled), and read operationMode() back to confirm. For CSP / CSV / CST, first configure synchronization and the 0x60C2 interpolation period, otherwise drive interpolation and master frame output drift apart.

public enum ModeCiA402 {
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
}

Mode values and the main objects written (the enum value is the byte value of 0x6060 / 0x6061):

Enumvalue()DescriptionMain objects / methods written
PP1Profile position modetargetPosition() (0x607A) + newSetpoint() / clearNewSetpoint() handshake
VL2Velocity modeNo dedicated SDK property; use slave.coe().sdoWrite* for the corresponding object
PV3Profile velocity modetargetVelocity() (0x60FF)
PT4Profile torque modetargetTorque() (0x6071)
HM6Homing modehomingMethod() / homingSpeed*() + startHoming()
IP7Interpolated position modeNo dedicated SDK property
CSP8Cyclic synchronous position mode0x607A issued through the process image every cycle
CSV9Cyclic synchronous velocity mode0x60FF issued through the process image every cycle
CST10Cyclic synchronous torque mode0x6071 issued through the process image every cycle
CSTCA11Cyclic synchronous torque with commutation angle modeNo dedicated SDK property

Enum helpers:

public byte value()                          // enum value (1..11)
public static ModeCiA402 fromValue(byte v) // reverse lookup; values outside the table return PP

fromValue() returns PP (not null) for values outside the table, so a read failure and "really in PP" are indistinguishable.

Example:

slave.cia402().operationMode(CiA402.ModeCiA402.CSP);
CiA402.ModeCiA402 mode = slave.cia402().operationMode();

isModeSupported(ModeCiA402 mode)​

public boolean isModeSupported(ModeCiA402 mode)

Checks whether the drive supports the given operating mode. It is based on SupportedDriveModes (0x6502); check it before switching modes so that a lack of support does not surface only after the write.

Parameters — mode: the mode to test. Return value — true = supported; false = not supported, or the 0x6502 read failed (fail-closed: both cases yield false). To tell them apart use supportedDriveModesReadable() / tryReadSupportedDriveModes() (see the "Tri-state reads" section). Throws — none.

Bit mapping: PP=Bit 0, VL=Bit 1, PV=Bit 2, PT=Bit 3, HM=Bit 5, IP=Bit 6, CSP=Bit 7, CSV=Bit 8, CST=Bit 9, CSTCA=Bit 10.

Motion parameters​

CategoryPropertyTypeRead/writeDescription
PositionpositionActual()intread-onlyActual position (0x6064)
VelocityvelocityActual()intread-onlyActual velocity (0x606C)
TorquetorqueActual()shortread-onlyActual torque, thousandths of rated (0x6077)
PositiontargetPosition() / targetPosition(int)intread/writeTarget position (0x607A)
VelocitytargetVelocity() / targetVelocity(int)intread/writeTarget velocity (0x60FF)
TorquetargetTorque() / targetTorque(short)shortread/writeTarget torque, thousandths of rated (0x6071)

positionActual() / velocityActual() / torqueActual()​

public int   positionActual()   // read 0x6064
public int velocityActual() // read 0x606C
public short torqueActual() // read 0x6077, thousandths of rated torque

Reads the drive actual values (three read-only objects, one SDO transaction each).

Return value — the object value; an SDO read failure collapses to 0, indistinguishable from a real 0. To tell them apart use tryReadTorqueActual() (torque) or tryReadObjectU32() (other objects). Throws — none.

targetPosition() / targetVelocity() / targetTorque()​

public int     targetPosition()                  // read 0x607A
public boolean targetPosition(int value) // write 0x607A
public int targetVelocity() // read 0x60FF
public boolean targetVelocity(int value) // write 0x60FF
public short targetTorque() // read 0x6071
public boolean targetTorque(short value) // write 0x6071

Reads / writes the target values. Torque is in thousandths of rated torque.

Parameters — value: the target value; types as above (torque is short, position / velocity are int).

Return value

  • Read form: the object value, a read failure collapses to 0
  • Write form: true = written; false = write failed (the command was not issued; check lastWriteAbortCode())

Throws — none, and no range validation is performed (the drive enforces the range).

Cyclic path — all six methods are SDO transactions and must not be called inside a cyclic callback; for CSP / CSV / CST write the process image directly every cycle using the offset obtained from pdoOffset() (see PDO initialization).

Example:

CiA402 drv = slave.cia402();

// read actual values
System.out.println("位置: " + drv.positionActual()); // Position:
System.out.println("速度: " + drv.velocityActual()); // Velocity:

// write target values
drv.targetPosition(100000);
drv.targetVelocity(5000);

Profile parameters​

CategoryPropertyTypeRead/writeDescription
ProfileprofileVelocity() / profileVelocity(long)longread/writeProfile velocity (0x6081)
profileAcceleration() / profileAcceleration(long)longread/writeProfile acceleration (0x6083)
profileDeceleration() / profileDeceleration(long)longread/writeProfile deceleration (0x6084)

profileVelocity() / profileAcceleration() / profileDeceleration()​

public long    profileVelocity()                // read 0x6081
public boolean profileVelocity(long value) // write 0x6081
public long profileAcceleration() // read 0x6083
public boolean profileAcceleration(long value) // write 0x6083
public long profileDeceleration() // read 0x6084
public boolean profileDeceleration(long value) // write 0x6084

Velocity / acceleration / deceleration for profile motion; effective in PP / PV / PT modes.

Parameters — value: a uint32 value (the unit is determined by the drive); the SDK performs no range validation.

Return value

  • Read form: the object value, a read failure collapses to 0
  • Write form: true = written; false = write failed (check lastWriteAbortCode())

Throws — none.

Example:

CiA402 drv = slave.cia402();
drv.profileVelocity(10000);
drv.profileAcceleration(50000);
drv.profileDeceleration(50000);

Polarity and profile configuration​

CategoryPropertyTypeRead/writeDescription
Polaritypolarity() / polarity(byte)byteread/writePolarity configuration (0x607E). Bit 6 = velocity polarity inverted, bit 7 = position polarity inverted
ProfilemotionProfileType() / motionProfileType(short)shortread/writeMotion profile type (0x6086). 0 = linear (trapezoidal) ramp, 1 = sine, 2 = S-curve (1 / 2 are slave-defined; consult the ESI)
StopquickStopDeceleration() / quickStopDeceleration(long)longread/writeQuick stop deceleration (0x6085)

polarity() / motionProfileType() / quickStopDeceleration()​

public byte    polarity()              // read 0x607E
public boolean polarity(byte value) // write 0x607E
public short motionProfileType() // read 0x6086
public boolean motionProfileType(short value) // write 0x6086
public long quickStopDeceleration() // read 0x6085
public boolean quickStopDeceleration(long value) // write 0x6085

Parameters — value: polarity is a bitmask (bit 6 = velocity polarity inverted, bit 7 = position polarity inverted); motionProfileType is the profile type (see the table above); quickStopDeceleration is the quick stop deceleration.

Return value

  • Read form: the object value, a read failure collapses to 0
  • Write form: true = written; false = write failed (check lastWriteAbortCode())

Throws — none, and no range validation is performed.

Example:

CiA402 drv = slave.cia402();

// invert the position direction
drv.polarity((byte) 0x80); // bit 7 = position polarity inverted

// set the profile type (1 = sine / 2 = S-curve; slave-defined, consult the ESI)
drv.motionProfileType((short) 1);

// set the quick stop deceleration
drv.quickStopDeceleration(100000);

Touch probe function​

configureTouchProbe(short function)​

public boolean configureTouchProbe(short function)

Configures the touch probe function (0x60B8). Setting the function bits enables / disables the touch probe and its trigger conditions.

Parameters:

  • function — touch probe function word. Bit 0 = enable probe 1, bit 1 = rising / falling edge selection, etc.

Returns:

  • boolean — true = written; false = write failed (check lastWriteAbortCode())

Throws — none, and no range validation is performed.

Related properties:

PropertyTypeRead/writeDescription
touchProbeStatus()shortread-onlyTouch probe status (0x60B9)
touchProbePositiveEdge()intread-onlyRising edge captured position (0x60BA)
touchProbeNegativeEdge()intread-onlyFalling edge captured position (0x60BB)

Each of the three read properties issues one SDO transaction; a read failure collapses to 0 (indistinguishable from a real 0) and none throws; the captured position is latched by the drive at the probe edge, so reading it later still returns the position at the edge.

Example:

CiA402 drv = slave.cia402();

// enable touch probe 1, rising edge trigger
drv.configureTouchProbe((short) 0x0001);

// read the touch probe result
if ((drv.touchProbeStatus() & 0x0002) != 0) { // rising edge captured
int capturedPos = drv.touchProbePositiveEdge();
System.out.println("触探捕获位置: " + capturedPos); // Touch-probe captured position:
}

Homing velocity and acceleration​

CategoryPropertyTypeRead/writeDescription
HominghomingMethod() / homingMethod(byte)byteread/writeHoming method (0x6098), e.g. 35 = home on the current position
homeOffset() / homeOffset(int)intread/writeHoming offset (0x607C), added to the zero position after homing
homingSpeedSearch() / homingSpeedSearch(long)longread/writeHoming search velocity (0x6099:01), fast search for the reference signal
homingSpeedZero() / homingSpeedZero(long)longread/writeHoming zero velocity (0x6099:02), slow precise positioning onto the zero position
homingAcceleration() / homingAcceleration(long)longread/writeHoming acceleration (0x609A)

homingMethod() / homeOffset() / homingSpeedSearch() / homingSpeedZero() / homingAcceleration()​

public byte    homingMethod()              // read 0x6098
public boolean homingMethod(byte value) // write 0x6098
public int homeOffset() // read 0x607C
public boolean homeOffset(int value) // write 0x607C
public long homingSpeedSearch() // read 0x6099:01
public boolean homingSpeedSearch(long value) // write 0x6099:01
public long homingSpeedZero() // read 0x6099:02
public boolean homingSpeedZero(long value) // write 0x6099:02
public long homingAcceleration() // read 0x609A
public boolean homingAcceleration(long value) // write 0x609A

Parameter group for homing (HM) mode. Set homingMethod() and the velocities / acceleration first, then enable to OperationEnabled and call startHoming().

Parameters — value: see the object semantics listed in the table above.

Return value

  • Read form: the object value, a read failure collapses to 0
  • Write form: true = written; false = write failed (check lastWriteAbortCode())

Throws — none, and no range validation is performed.

supportedHomingMethods() (0x60E3) reports which method numbers the drive supports; the three return cases are described in drive information.

Example:

CiA402 drv = slave.cia402();
drv.operationMode(CiA402.ModeCiA402.HM);
drv.homingMethod((byte) 1);

// set the homing velocities and acceleration
drv.homingSpeedSearch(5000); // search velocity
drv.homingSpeedZero(500); // zero velocity
drv.homingAcceleration(10000); // homing acceleration

Digital IO​

CategoryPropertyTypeRead/writeDescription
InputdigitalInputs()intread-onlyDigital inputs (0x60FD), 32-bit bitmap
OutputdigitalOutputs() / digitalOutputs(int)intread/writeDigital outputs (0x60FE:01), 32-bit bitmap

digitalInputs() / digitalOutputs()​

public int     digitalInputs()            // read 0x60FD, read-only
public int digitalOutputs() // read 0x60FE:01
public boolean digitalOutputs(int value) // write 0x60FE:01

Reads the digital input bitmap and reads / writes the digital output bitmap (one SDO transaction each).

Parameters — value: 32-bit bitmap; 1 = that output bit is active. Return value — read form: the bitmap, a read failure collapses to 0 (indistinguishable from all inputs inactive); write form: true = written, false = write failed (check lastWriteAbortCode()). Throws — none. Note — the digital output is a whole-word bitmap and a write replaces it entirely; to change a single bit, read digitalOutputs() first, OR in the bit, then write it back.

Example:

CiA402 drv = slave.cia402();

// read digital inputs
int inputs = drv.digitalInputs();
boolean limitSwitch = (inputs & 0x01) != 0; // bit 0

// set digital outputs
drv.digitalOutputs(0x03); // output bits 0 and 1

Software position limits​

CategoryPropertyTypeRead/writeDescription
LimitsoftwarePositionLimitMin() / softwarePositionLimitMin(int)intread/writeSoftware position limit, lower bound (0x607D:01)
softwarePositionLimitMax() / softwarePositionLimitMax(int)intread/writeSoftware position limit, upper bound (0x607D:02)

softwarePositionLimitMin() / softwarePositionLimitMax()​

public int     softwarePositionLimitMin()            // read 0x607D:01
public boolean softwarePositionLimitMin(int value) // write 0x607D:01
public int softwarePositionLimitMax() // read 0x607D:02
public boolean softwarePositionLimitMax(int value) // write 0x607D:02

Reads / writes the software position limits. The drive enforces the limits; the SDK does not clamp the target values it sends — on the cyclic path the caller must validate the target every cycle (clamp out-of-range values or refuse to send), instead of relying on the drive reporting an error alone.

Parameters — value: position limit, with the same unit as 0x6064 / 0x607A. Return value — read form: the object value, a read failure collapses to 0; write form: true = written, false = write failed (check lastWriteAbortCode()). Throws — none.

Example:

CiA402 drv = slave.cia402();

// set the motion range limits
drv.softwarePositionLimitMin(-1000000);
drv.softwarePositionLimitMax(1000000);

Quick motion control​

newSetpoint(int position, boolean relative)​

public boolean newSetpoint(int position, boolean relative)

Sends a new setpoint command in PP mode. Sets the target position and triggers Controlword Bit 4 (New Setpoint).

Parameters:

  • position — target position (same unit as 0x6064; the SDK does not convert)
  • relative — true = relative positioning (adds Bit 6 to the control word, sending 0x5F), false = absolute positioning (sends 0x1F)

Returns:

  • boolean — true = both the target position and the control word were written; false = either write failed (the command did not take effect; use lastWriteAbortCode() to identify which write failed and lastWriteIndex() to see which object)

Throws — none.

Behavior note — both writes are performed; the control word is not skipped because the target position write failed. When false is returned the New Setpoint bit may already be set, so re-check with stateDrive() / the status word before deciding whether to resend. Preconditions: PP mode + OperationEnabled.

Example:

CiA402 drv = slave.cia402();
drv.operationMode(CiA402.ModeCiA402.PP);
drv.profileVelocity(10000);
drv.profileAcceleration(50000);

// non-cyclic path: send the positioning command after enabling (SDO transaction; do not put it in a PDO callback)
if (drv.stateDrive() == CiA402.StateCiA402.OperationEnabled) {
drv.newSetpoint(100000, false); // absolute positioning to 100000
}

clearNewSetpoint()​

public boolean clearNewSetpoint()

Clears the NewSetpoint flag in PP mode (writes 0x0F to the control word, Bit 4 = 0). Call it after targetReached() to complete the SetPointAck handshake.

Returns:

  • boolean — true = written; false = write failed (check lastWriteAbortCode())

Throws — none. Writes the control word once and returns; verify with stateDrive() / the status word.

Example:

if (drv.targetReached()) {
drv.clearNewSetpoint();
}

startHoming()​

public boolean startHoming()

Starts homing in HM mode. Requires homingMethod() to be set and the drive enabled to OperationEnabled first. Writes 0x1F to the control word (sets Start Homing).

Returns:

  • boolean — true = written; false = write failed (check lastWriteAbortCode())

Throws — none. Writes the control word once and returns; the homing process does not block the calling thread; follow up with homingAttained() / homingError().

Related properties:

PropertyTypeRead/writeDescription
homingMethod() / homingMethod(byte)byteread/writeHoming method (0x6098)
homeOffset() / homeOffset(int)intread/writeHoming offset (0x607C)
homingAttained()booleanread-onlyHoming attained (status word Bit 12)
homingError()booleanread-onlyHoming error (status word Bit 13)

homingAttained() / homingError() re-read the status word on every call (SDO transaction); when polling in a cycle, read statusword() once and evaluate the bits yourself.

Example:

CiA402 drv = slave.cia402();
drv.operationMode(CiA402.ModeCiA402.HM);
drv.homingMethod((byte) 35); // home on the current position

// non-cyclic path: start homing after enabling (SDO transaction)
if (drv.stateDrive() == CiA402.StateCiA402.OperationEnabled) {
drv.startHoming();
// check drv.homingAttained() / drv.homingError() in later cycles
}

Extended motion parameters​

CategoryPropertyTypeRead/writeDescription
TorquemaxTorque() / maxTorque(int)intread/writeMaximum torque (0x6072), thousandths of rated torque
TorquemotorRatedTorque() / motorRatedTorque(long)longread/writeMotor rated torque (0x6076), unit mNm
OffsetpositionOffset() / positionOffset(int)intread/writePosition offset (0x60B0), added to the target position in CSP mode
velocityOffset() / velocityOffset(int)intread/writeVelocity offset (0x60B1), added to the target velocity in CSV mode
torqueOffset() / torqueOffset(short)shortread/writeTorque offset (0x60B2), added to the target torque in CST mode
InterpolationinterpolationTimePeriodValue() / interpolationTimePeriodValue(byte)byteread/writeInterpolation time period value (0x60C2:01)
InterpolationinterpolationTimePeriodIndex() / interpolationTimePeriodIndex(byte)byteread/writeInterpolation time period index (0x60C2:02); actual period = Value x 10^Index seconds
Option codequickStopOptionCode() / quickStopOptionCode(short)shortread/writeQuick stop option code (0x605A). 0 = disable the drive, 1/2 = decelerate and stop, 5/6 = decelerate and stay in QuickStopActive. A read failure returns -32768 (not a valid value)

maxTorque() / motorRatedTorque() / torqueOffset()​

public int     maxTorque()                // read 0x6072, thousandths of rated torque
public boolean maxTorque(int value) // write 0x6072
public long motorRatedTorque() // read 0x6076, unit mNm
public boolean motorRatedTorque(long value) // write 0x6076
public short torqueOffset() // read 0x60B2
public boolean torqueOffset(short value) // write 0x60B2

Parameters — value: see the object semantics in the table above.

Return value — read form: the object value, a read failure collapses to 0; write form: true = written, false = write failed (check lastWriteAbortCode()).

Throws — the argument of maxTorque(int) must be in 0..65535 (uint16); out of range throws IllegalArgumentException and is not silently truncated (otherwise 65536 would be written as 0). motorRatedTorque(long) / torqueOffset(short) perform no range validation.

positionOffset() / velocityOffset() / interpolationTimePeriodValue() / interpolationTimePeriodIndex()​

public int     positionOffset()                    // read 0x60B0
public boolean positionOffset(int value) // write 0x60B0
public int velocityOffset() // read 0x60B1
public boolean velocityOffset(int value) // write 0x60B1
public byte interpolationTimePeriodValue() // read 0x60C2:01
public boolean interpolationTimePeriodValue(byte value) // write 0x60C2:01
public byte interpolationTimePeriodIndex() // read 0x60C2:02
public boolean interpolationTimePeriodIndex(byte value) // write 0x60C2:02

Parameters — value: see the object semantics in the table above; interpolation period = Value x 10^Index seconds.

Return value — read form: the object value, a read failure collapses to 0; write form: true = written, false = write failed (check lastWriteAbortCode()). Throws — none, and no range validation is performed.

Interpolation period must match the bus cycle

0x60C2 is the drive-side interpolation period, not the bus cycle: under CSP / CSV / CST it should match the master PDO cycle (or be an integer divider of it), otherwise drive interpolation and master frame output drift apart. After changing the bus cycle you must change it here too.

Example:

CiA402 drv = slave.cia402();

// torque configuration
drv.maxTorque(1000); // maximum torque = 100% of rated
long rated = drv.motorRatedTorque();

// offset superposition in CSP mode
drv.positionOffset(100); // additional position offset
drv.velocityOffset(50); // additional velocity offset

// interpolation time period (1 ms = 1 x 10^(-3) s)
drv.interpolationTimePeriodValue((byte) 1);
drv.interpolationTimePeriodIndex((byte) -3);

// quick stop option (5 = decelerate and hold, allows direct recovery)
drv.quickStopOptionCode((short) 5);

Option codes and error codes​

The five drive option codes determine the deceleration / stop behavior of each state transition; the error code reflects the current drive fault. The SDK reads and writes these objects verbatim: writes perform no value validation, and the meaning of specific values follows the drive manual (the ETG.6010 option code definitions).

CategoryMethodTypeRead/writeDescription
Option codequickStopOptionCode() / quickStopOptionCode(short)shortread/write0x605A. Normal = the real value (valid option codes are small values including 0); a read failure returns -32768 (not a valid value; do not treat it as a real value, handle it as a failure)
Option codeshutdownOptionCode() / shutdownOptionCode(short)shortread/write0x605B. Same as above
Option codedisableOperationOptionCode() / disableOperationOptionCode(short)shortread/write0x605C. Same as above
Option codehaltOptionCode() / haltOptionCode(short)shortread/write0x605D. Same as above
Option codefaultReactionOptionCode() / faultReactionOptionCode(short)shortread/write0x605E. Same as above
ErrorerrorCode()intread-only0x603F. Normal = the real value (0x0000 means no error); a read failure returns 0xFFFF (not a valid value; do not treat it as a real value, handle it as a failure)
ErrortryReadErrorCode()CiA402ReadResult<Integer>read-only0x603F. Tri-state result (success / not supported / read failure), see the "Tri-state reads" section

Read failure sentinels (same convention as the low-level direct reads): a signed 16-bit option code read failure = -32768 (INT16_MIN); an unsigned 16-bit error code read failure = 0xFFFF. Neither is a valid value (valid option codes are small values including 0; error code 0x0000 means no error), so do not use them as real values — handle them as read failures. Counter-style read interfaces returning int return -1 as a whole on a read failure; the caller handles it as a failure.

Predicate constants and helper methods (inside the CiA402 class):

NameTypeDescription
READ_FAIL_SENTINEL_I16shortSigned 16-bit read-failure sentinel (-32768)
READ_FAIL_SENTINEL_U16intUnsigned 16-bit read-failure sentinel (0xFFFF)
READ_FAIL_SENTINEL_INTintRead-failure sentinel for read interfaces returning int (-1, fail-closed)
isReadFailSentinelI16(short v)booleanDomain-specific predicate: matches only the signed 16-bit option code domain sentinel (-32768), not the other two tiers
isReadFailSentinelU16(int v)booleanDomain-specific predicate: matches only the unsigned 16-bit error code domain sentinel (0xFFFF), not the other two tiers. Java has no unsigned 16-bit type, so u16 is carried in an int
isReadFailSentinelInt(int v)booleanDomain-specific predicate: matches only the counter-style read domain sentinel for reads returning int (-1, fail-closed), not the other two tiers
isReadFailSentinel(short v)booleanshort form of the legacy merged entry point, kept for old call sites. This overload tests the i16 domain only and behaves like isReadFailSentinelI16(short); new code should use the domain-specific predicates
isReadFailSentinel(int v)booleanLegacy cross-domain predicate with a documented false positive. Java has no unsigned 16-bit type, so u16 and int counters are both carried in an int; this overload therefore covers both tiers (-1 and 0xFFFF) and cannot attribute the sentinel to a tier, and the legal counter value 65535 in the int counter domain is misjudged as a read failure. New code should use isReadFailSentinelU16(int) / isReadFailSentinelInt(int)

For domain-specific checks pick the predicate that matches the returned form under test: option codes use isReadFailSentinelI16, errorCode() uses isReadFailSentinelU16, and counter-style reads returning int use isReadFailSentinelInt.

The byte method numbers (entries of the 0x60E3 list, with -128..-1 being vendor-defined methods) are real values, not sentinels; do not test them with the predicates above.

Example:

// option code: read failure = -32768 sentinel (not a valid value); if matched, handle as a failure
short qs = drv.quickStopOptionCode();
if (CiA402.isReadFailSentinelI16(qs)) {
/* read failure, handle as a failure */
} else {
/* qs is a real value (valid option codes are small values including 0) */
}

// error code: errorCode() read failure = 0xFFFF sentinel; for a tri-state distinction use tryReadErrorCode()
int ec = drv.errorCode();
if (CiA402.isReadFailSentinelU16(ec)) {
/* read failure, handle as a failure */
} else {
/* ec is a real value (0x0000 means no error) */
}

errorCode() / tryReadErrorCode()​

public int                       errorCode()          // read 0x603F
public CiA402ReadResult<Integer> tryReadErrorCode() // read 0x603F, with status

Reads the drive's current error code (0x603F, read-only).

Return value

  • errorCode() — unsigned 16-bit error code, 0x0000 means no error; a read failure returns the 0xFFFF sentinel (not a valid value; handle it as a failure)
  • tryReadErrorCode() — CiA402ReadResult<Integer>: status distinguishes success / not supported / read failure; on failure value is null and abortCode carries the low-level abort code

Throws — neither throws. Note — the SDK only passes the raw error code through and does not translate vendor error codes into names; to distinguish "real value / not supported / read failure" use tryReadErrorCode(), see the "Tri-state reads (success / not supported / read failure)" section.

quickStopOptionCode() / shutdownOptionCode() / disableOperationOptionCode() / haltOptionCode() / faultReactionOptionCode()​

public short   quickStopOptionCode()                  // read 0x605A
public boolean quickStopOptionCode(short value) // write 0x605A
public short shutdownOptionCode() // read 0x605B
public boolean shutdownOptionCode(short value) // write 0x605B
public short disableOperationOptionCode() // read 0x605C
public boolean disableOperationOptionCode(short value) // write 0x605C
public short haltOptionCode() // read 0x605D
public boolean haltOptionCode(short value) // write 0x605D
public short faultReactionOptionCode() // read 0x605E
public boolean faultReactionOptionCode(short value) // write 0x605E

Five option codes, controlling the deceleration and stop behavior for quick stop / shutdown / disable operation / halt / fault reaction respectively.

Parameters — value: option code (valid values are small values including 0).

Return value

  • Read form: the real option code, a read failure returns the -32768 sentinel (not a valid value; test it with isReadFailSentinelI16() and handle a hit as a failure)
  • Write form: true = written; false = write failed (check lastWriteAbortCode())

Throws — none.

Torque limits​

CategoryPropertyTypeRead/writeDescription
TorquepositiveTorqueLimit() / positiveTorqueLimit(int)intread/writePositive torque limit (0x60E0), thousandths of rated torque
negativeTorqueLimit() / negativeTorqueLimit(int)intread/writeNegative torque limit (0x60E1), thousandths of rated torque

positiveTorqueLimit() / negativeTorqueLimit()​

public int     positiveTorqueLimit()                  // read 0x60E0
public boolean positiveTorqueLimit(int value) // write 0x60E0
public int negativeTorqueLimit() // read 0x60E1
public boolean negativeTorqueLimit(int value) // write 0x60E1

Parameters — value: thousandths of rated torque; must be in 0..65535 (uint16). Return value — read form: the object value (0..65535), a read failure collapses to 0; write form: true = written, false = write failed (check lastWriteAbortCode()). Throws — out of range throws IllegalArgumentException and is not silently truncated (otherwise 65536 would be written as 0).

Example:

CiA402 drv = slave.cia402();

// limit the positive and negative torque to 50% of rated
drv.positiveTorqueLimit(500);
drv.negativeTorqueLimit(500);

Synchronization​

CategoryPropertyTypeRead/writeDescription
SynchronizationsynchronizationSettings() / synchronizationSettings(int)intread/writeSynchronization settings (0x60D9:01), synchronization enable bitmask
driveSyncStatus()intread-onlyDrive synchronization status (0x60DA), indicating whether the drive is synchronized to the master clock

synchronizationSettings() / driveSyncStatus()​

public int     synchronizationSettings()               // read 0x60D9:01
public boolean synchronizationSettings(int value) // write 0x60D9:01
public int driveSyncStatus() // read 0x60DA, read-only

Parameters — value: synchronization enable bitmask; must be in 0..65535 (uint16). Return value — read form: the object value (0..65535), a read failure collapses to 0; write form: true = written, false = write failed (check lastWriteAbortCode()). Throws — synchronizationSettings(int) throws IllegalArgumentException when out of range and does not silently truncate; the others do not throw.

Example:

CiA402 drv = slave.cia402();

// read the drive synchronization status
int syncStatus = drv.driveSyncStatus();
System.out.printf("同步状态: 0x%04X%n", syncStatus); // Sync status: 0x%04X%n

// configure synchronization settings
drv.synchronizationSettings(0x0001);

TxPDO data validity​

txPdoDataInvalid()​

public boolean txPdoDataInvalid()

Whether the TxPDO data is invalid (0x603E). A non-zero value means the drive TxPDO data is not trustworthy, for example the position value is meaningless while the encoder is not ready.

Return value — true = the data is not trustworthy; false = trustworthy, or the SDO read failed (a read failure collapses to false, indistinguishable from a real false). Therefore check pdoOffset() >= 0 before trusting it; do not rely on this method alone. Throws — none.

Example:

CiA402 drv = slave.cia402();
if (!drv.txPdoDataInvalid()) {
int pos = drv.positionActual(); // data valid, safe to use
}

Drive information​

supportedDriveModes()​

public long supportedDriveModes()

Supported drive modes bitmask (0x6502, read-only).

BitModeBitMode
Bit 0PPBit 6IP
Bit 1VLBit 7CSP
Bit 2PVBit 8CSV
Bit 3PTBit 9CST
Bit 5HMBit 10CSTCA

Return value — the bitmask; a read failure returns 0, indistinguishable from "no mode supported", and isModeSupported() then returns false as well (fail-closed). To tell them apart use supportedDriveModesReadable() / tryReadSupportedDriveModes() (with status / abortCode). Throws — none.

supportedHomingMethods()​

public byte[] supportedHomingMethods()

Reads the list of homing methods supported by the drive (0x60E3) and returns an array of method numbers.

Parameters — none. Return value — byte[] array of method numbers (elements are byte; -128..-1 are vendor-defined method numbers and are real values, not sentinels). Throws — none; any failure collapses to null.

What each of the three cases returns:

  • Failure (SDO timeout / communication exception / any other abort) — returns null, handle it as a failure
  • Empty set (SI0=0 and the read succeeded; the slave really returned 0 entries) — returns an empty array
  • Not supported (the slave has no 0x60E3 or 0x60E3:00; SDO abort 0x06020000 object does not exist / 0x06090011 subindex does not exist) — returns null, the same tier as failure

If any sub-item read fails, the whole read fails.

Predicate: null = read failure or not supported; an empty array = the read succeeded and the drive really supports no homing method. The two are not interchangeable.

note

Failure and not-supported are both handled as failures; never take them to mean 0 homing methods are supported. The low-level read is fail-closed (a read failure fails the whole call), and following Java convention this method maps that to null rather than -1.

Example:

byte[] methods = drv.supportedHomingMethods();
if (methods == null) {
/* read failure, handle as a failure */
} else {
System.out.println("支持 " + methods.length + " 种回零方法"); // Supports {methods.length} homing methods
}

predefinedErrorHistoryOrNull(int maxCount) / predefinedErrorHistoryOrNull()​

public long[] predefinedErrorHistoryOrNull(int maxCount)
public long[] predefinedErrorHistoryOrNull() // default maxCount = 32

Reads the drive's internal error history from the Pre-defined Error Field (0x1003): 0x1003:00 = entry count (uint8), 1..N = error codes (uint32 little-endian, unsigned, carried in a Java long). The EMCY buffer is maintained on the master side; this entry point reads the drive's persistent error history.

Three states (not collapsible):

  • null — read failure or not supported: a failed count item, any failed entry, maxCount <= 0, or an abort classified as not-supported all return null; 0 entries are never fabricated to pad the length
  • Empty array — the read succeeded and the count is 0: the drive really has no history
  • Non-empty array — error codes in the drive's history order

At most maxCount entries are read (the rest are not read). Attribution uses the same three-state read contract as the rest of this class: abort 0x06020000 / 0x06090011 / 0x06090012 is treated as not-supported, any other abort / timeout as a read failure. This method is read-only and does not clear the history.

Parameters:

  • maxCount — maximum number of entries to read; <= 0 returns null (invalid request, the device is not read)

Return value: long[] array of error codes (0x00000000..0xFFFFFFFF); read failure / not supported returns null.

Throws: none (read exceptions collapse to null).

Example:

long[] history = drv.predefinedErrorHistoryOrNull();
if (history == null) {
/* read failure or not supported: do not treat it as "no history" */
} else if (history.length == 0) {
/* really no history */
} else {
for (long code : history) {
System.out.printf("0x%08X%n", code);
}
}

PDO offset management​

Item-by-item descriptions of initializePdoOffsets() / pdoOffset() / resetPdoOffsets() / pdoInitialized() / pdoMappedObjectCount() are in PDO initialization; for TxPDO data trustworthiness see txPdoDataInvalid().

drv.initializePdoOffsets();           // initialize the PDO offset cache
drv.resetPdoOffsets(); // reset the PDO offset cache
boolean ready = drv.pdoInitialized(); // whether the PDO offsets have been built
int n = drv.pdoMappedObjectCount(); // number of resolved Rx + Tx mapped objects

State parsing​

parseState(short statusword)​

public static StateCiA402 parseState(short statusword)

Parses the drive state from a status word. Use it when you already have the status word, to avoid another bus read.

Parameters — statusword: raw status word value (including the bit masks). Return value — StateCiA402; the criteria are in the state table of the stateDrive() section; combinations outside the table return Unknown. Throws — none. Pure function, no bus transaction.

Tri-state reads (success / not supported / read failure)​

Bare-value getters (errorCode(), positionActual() and so on) only give the value itself: a read failure is collapsed to 0 or a sentinel, indistinguishable from a real value. To distinguish "the slave simply does not support this object" from "the link read failed", use the tryRead* family — they are observable read-only interfaces that only read the object dictionary and have no side effects such as writing the object dictionary / writing PDOs / changing the state machine / enabling the drive.

There are only two real failure channels:

  1. PDO data source (cyclic path): check whether pdoInitialized() / pdoOffset() hit, and whether txPdoDataInvalid() declares the data untrustworthy.
  2. SDO abort (parameter path): check the status and abortCode returned by tryRead*; for bare-value interfaces you can use slave.coe().getLastSdoError() to obtain the reason.

The CiA402ReadResult result object​

public final class CiA402ReadResult<T> {
public final T value; // only meaningful when status == Success
public final CiA402ReadStatus status;
public final long abortCode; // 0 = no abort
public boolean isOk(); // status == Success
public boolean isNotSupported(); // status == NotSupported
}
MemberTypeDescription
valueTThe value read; null on failure / not supported (no fabricated value)
statusCiA402ReadStatusRead status, see the table below
abortCodelongSDO Abort Code; 0 = no abort, on failure / not supported the low-level abort code; codes outside the table are kept verbatim
isOk()booleanstatus == Success
isNotSupported()booleanstatus == NotSupported

toString(): on success it prints the value itself, on failure it prints <状态 abort=0xXXXXXXXX(十进制)>, so it can go straight into logs.

The CiA402ReadStatus status enum​

EnumMeaningCriterion
NotAttemptedNot attempted yetInitial state of the instance; the caller did not trigger it, or a precondition was not met
SuccessRead succeeded, returns the slave's real valueEnough bytes were obtained and converted successfully
NotSupportedThe slave does not support this objectSDO abort 0x06020000 (object does not exist) / 0x06090011 (subindex does not exist) / 0x06090012 (object does not contain this subindex)
ReadFailedSDO read failedTimeout / communication exception / any other abort / fewer bytes than the type width

Any non-zero abort other than those classified as NotSupported is classified as ReadFailed; data received with fewer bytes than required also counts as ReadFailed and is never folded into a fake real value.

tryReadStatusword()​

public CiA402ReadResult<Integer> tryReadStatusword()

Tri-state read of the status word (0x6041, unsigned 16-bit). The observable version of statusword(); a failure is no longer collapsed to 0.

tryReadOperationModeDisplay()​

public CiA402ReadResult<ModeCiA402> tryReadOperationModeDisplay()

Tri-state read of the mode display (0x6061, 8-bit). When the read succeeds but the raw value is not in the ModeCiA402 enum, it is classified as PP per ModeCiA402.fromValue(). To distinguish "read failure" from "really PP" you must look at status.

tryReadErrorCode()​

public CiA402ReadResult<Integer> tryReadErrorCode()

Tri-state read of the error code (0x603F, unsigned 16-bit). Same semantics as errorCode() (0x0000 means no error), but a failure does not produce the 0xFFFF sentinel: value is null and the reason is in status / abortCode.

tryReadTorqueActual()​

public CiA402ReadResult<Short> tryReadTorqueActual()

Tri-state read of the actual torque (0x6077, signed 16-bit, thousandths of rated torque).

tryReadDigitalInputs()​

public CiA402ReadResult<Long> tryReadDigitalInputs()

Tri-state read of the digital inputs (0x60FD, unsigned 32-bit bitmap).

tryReadSupportedDriveModes() / supportedDriveModesReadable()​

public CiA402ReadResult<Long> tryReadSupportedDriveModes()   // 0x6502, unsigned 32-bit bitmask
public boolean supportedDriveModesReadable() // = tryReadSupportedDriveModes().isOk()

Tri-state read of the supported drive mode bitmask. supportedDriveModesReadable() is a convenience predicate: true = 0x6502 was actually read, false = not supported or the read failed (use lastReadStatus() to tell which). When supportedDriveModes() returns 0 after a read failure, this tells you whether it is "really unsupported" or "not read".

tryReadDriveData(byte subindex)​

public CiA402ReadResult<Long> tryReadDriveData(byte subindex)   // 0x6510, read-only

Tri-state read of vendor-specific drive data (0x6510, RECORD, read-only). The subindexes are defined by the slave ESI; this reads an unsigned 32-bit value by subindex. Read only, never written.

Parameters — subindex: subindex (byte).

tryReadObjectU32(short index, byte subindex)​

public CiA402ReadResult<Long> tryReadObjectU32(short index, byte subindex)

General escape hatch: performs one unsigned 32-bit tri-state read of any object. Objects in CiA 402 that have no dedicated getter all go through it.

Parameters

ParameterTypeDescription
indexshortObject index
subindexbyteSubindex

Return value — CiA402ReadResult<Long>; at least 4 bytes are required for a real value, otherwise it is ReadFailed. Throws — none.

CiA402.CiA402ReadResult<Long> r = drv.tryReadObjectU32((short) 0x607C, (byte) 0);
if (r.isOk()) {
System.out.println("0x607C = " + r.value);
} else if (r.isNotSupported()) {
System.out.println("该从站不提供 0x607C"); // This slave does not provide 0x607C
} else {
System.out.printf("读取失败: abort=0x%08X%n", r.abortCode); // Read failed: abort=0x%08X%n
}

readAttribute(short index, byte subindex, String dtype)​

public Number readAttribute(short index, byte subindex, String dtype)
public Number readAttribute(short index, String dtype) // subindex fixed at 0

Reads any object directly by data type and returns a bare value (null on failure); use lastReadStatus() to judge the result of this call.

Parameters

ParameterTypeDescription
indexshortObject index
subindexbyteSubindex (fixed at 0 in the form that omits it)
dtypeStringi8 / u8 / i16 / u16 / i32 / u32

Return value — the numeric value read (u8 / u16 are widened as unsigned); an unknown dtype or a read failure returns null. Throws — none.

lastReadStatus() / lastReadAbortCode() / lastReadIndex() / lastReadSubIndex()​

public CiA402ReadStatus lastReadStatus()   // status of the most recent SDO read-only attempt
public long lastReadAbortCode() // abort code on failure / not supported (0 on success)
public short lastReadIndex() // object index of the most recent read
public byte lastReadSubIndex() // subindex of the most recent read

Every tryRead* / readAttribute call updates this state, for GUI / diagnostics queries. The initial state is NotAttempted. Like the write-side lastWrite*, this is an instance-level "most recent" state; concurrent reads from multiple threads overwrite each other.

Standard object index constants​

Can be used with slave.coe().sdoRead() / sdoWrite():

ConstantValueDescription
OD_CONTROLWORD0x6040Control word
OD_STATUSWORD0x6041Status word
OD_MODES_OF_OPERATION0x6060Operating mode setpoint
OD_MODES_OF_OPERATION_DISPLAY0x6061Operating mode 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_SHUTDOWN_OPTION_CODE0x605BShutdown option code
OD_DISABLE_OPERATION_OPTION_CODE0x605CDisable Operation option code
OD_HALT_OPTION_CODE0x605DHalt option code
OD_FAULT_REACTION_OPTION_CODE0x605EFault Reaction option code
OD_ERROR_CODE0x603FCurrent error code (read-only)
OD_SUPPORTED_HOMING_METHODS0x60E3Supported homing method list
OD_QUICK_STOP_DECELERATION0x6085Quick stop deceleration
OD_SUPPORTED_DRIVE_MODES0x6502Supported drive modes bitmask
OD_POSITIVE_TORQUE_LIMIT0x60E0Positive torque limit
OD_NEGATIVE_TORQUE_LIMIT0x60E1Negative torque limit
OD_TXPDO_DATA_INVALID0x603ETxPDO data validity
OD_SYNCHRONIZATION_SETTINGS0x60D9Synchronization settings
OD_DRIVE_SYNC_STATUS0x60DADrive synchronization status
OD_DRIVE_DATA0x6510Vendor-specific drive data (read-only)
OD_RXPDO_ASSIGN0x1C12PDO assignment (master output direction)
OD_TXPDO_ASSIGN0x1C13PDO assignment (master input direction)

Control word command constants​

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

Control word bit layout: Bit 0 Switch On, Bit 1 Enable Voltage, Bit 2 Quick Stop (active low: 0 = quick stop active, 1 = released), Bit 3 Enable Operation, Bit 4 New Setpoint / Start Homing (mode-dependent), Bit 7 Fault Reset (triggered on a 0→1 rising edge), Bit 8 Halt.

CW_FAULT_RESET = 0x86 = Bit 1 + Bit 2 (releases Quick Stop) + Bit 7 (Fault Reset rising edge). Because Bit 2 is active low, 0x0000 / 0x0080 keep QuickStop active, so they fail to reset the fault and additionally drag the drive into a quick stop.

Status word bitmask constants​

ConstantValueDescription
SW_FAULT0x0008 (Bit 3)Fault
SW_QUICK_STOP0x0020 (Bit 5)Quick stop
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

Bits 0 / 1 / 2 / 4 / 6 (ReadyToSwitchOn / SwitchedOn / OperationEnabled / VoltageEnabled / SwitchOnDisabled) have no corresponding SDK constants and are not read as individual bits — read the overall state with parseState(statusword()) into a StateCiA402.

Complete examples​

CSP mode — cyclic synchronous position control​

CiA402 drv = slave.cia402();

// initialization (call once after entering OP)
drv.initializePdoOffsets();
drv.operationMode(CiA402.ModeCiA402.CSP);

// one-shot enable (full state machine handled internally)
if (!drv.enable()) { System.out.println("使能失败: " + drv.stateDrive()); return; } // Enable failed:

int swOff = drv.pdoOffset((short) 0x6041, true); // Statusword (TxPDO)
int posOff = drv.pdoOffset((short) 0x607A, false); // Target position (RxPDO)
if (swOff < 0 || posOff < 0) {
System.out.println("PDO 未映射 0x6041 / 0x607A,无法走周期路径"); // PDO does not map 0x6041 / 0x607A, the cyclic path cannot be used
return;
}

// in the PDO callback, write the process image every cycle to issue the target (no SDO, no logging, no sleep inside the callback)
master.events().addProcessDataCyclicSyncListener((masterIndex) -> {
int sw = slave.PDO().in().get(swOff).asUInt16();
if ((sw & 0x6F) == 0x27) { // OperationEnabled
slave.PDO().out().get(posOff).asInt32(calculateNextPosition());
}
});

PP mode — profile position control​

CiA402 drv = slave.cia402();

drv.initializePdoOffsets();
drv.operationMode(CiA402.ModeCiA402.PP);
drv.profileVelocity(10000);
drv.profileAcceleration(50000);
drv.profileDeceleration(50000);

// one-shot enable
if (!drv.enable()) { System.out.println("使能失败: " + drv.stateDrive()); return; } // Enable failed:

// send the positioning command
drv.newSetpoint(100000, false);

// in the PDO callback, clear the flag once the target is reached
boolean[] homing = {false};
master.events().addProcessDataCyclicSyncListener((masterIndex) -> {
if (!homing[0] && drv.targetReached()) {
drv.clearNewSetpoint();
homing[0] = true;
}
});

HM mode — homing control​

CiA402 drv = slave.cia402();

drv.initializePdoOffsets();
drv.operationMode(CiA402.ModeCiA402.HM);
drv.homingMethod((byte) 35); // home on the current position
drv.homingSpeedSearch(5000);
drv.homingSpeedZero(500);
drv.homingAcceleration(10000);

// one-shot enable
if (!drv.enable()) { System.out.println("使能失败: " + drv.stateDrive()); return; } // Enable failed:

// start homing
drv.startHoming();

master.events().addProcessDataCyclicSyncListener((masterIndex) -> {
if (drv.homingAttained()) {
System.out.println("回零完成"); // Homing complete
} else if (drv.homingError()) {
System.out.println("回零错误"); // Homing error
}
});

The PP and HM examples call targetReached() / clearNewSetpoint() / homingAttained() / homingError() directly inside the callback to make the handshake order clear. On the real cyclic path, read the process image at the pdoOffset() offsets and evaluate the bits yourself, and issue handshake writes (clearNewSetpoint() / the control word) through the process image at the control word offset as well, so that no blocking SDO transaction appears inside the callback.