Skip to main content

CiA 401 — Generic I/O modules

CiA 401 (IEC 61131-9) is a CoE-based device profile for generic digital and analog I/O devices.

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

Accessed through slave.CoE.CiA401. null when the slave does not support CiA 401.​

Differences from CiA 402​

CiA 401 is a stateless generic I/O profile: no control word / status word / operation mode / enable sequence, only channel read and write, polarity and filter configuration, and safe values for loss of communication. For the servo state machine, operation modes and motion parameters, see CiA 402.

I/O properties​

Channels are read and written directly through indexers; channel numbers start at 0.

CategoryPropertyTypeRead/writeDescription
DigitalDI[n]boolread-onlyDigital input channel n (0x6000, 8 channels per group)
DO[n]boolread/writeDigital output channel n (0x6200; the read-modify-write leaves the other channels in the group untouched)
AnalogAI[n]intread-onlyAnalog input channel n (0x6400, adapts automatically to 16-bit or 32-bit signed values)
AO[n]shortread/writeAnalog output channel n (0x6411, 16-bit signed)
var io = slave.CoE.CiA401;
if (io == null) return;

bool sensor = io.DI[0];
io.DO[0] = true;
io.DO[1] = sensor;

int adc = io.AI[0];
io.AO[0] = 16384;
Real-time control

Use PDO mapping for high-frequency I/O control; SDO is suitable for parameter configuration and diagnostics.

Channels, groups and bit order​

  • Every single-channel number starts at 0, 1 less than channel 1 in the slave manual.
  • Digital channels are mapped in groups of 8 to 0x6000 / 0x6200: channel / 8 is the group number and the subindex is the group number + 1; channel % 8 is the bit number, and bit0 corresponds to the 1st channel of the group.
  • For the 16-bit and 32-bit bulk methods, group is the subindex and starts at 1: group 1 = channels 0-15 (16-bit) or 0-31 (32-bit).
  • Analog inputs adapt automatically to 16 or 32 bits; values are interpreted as signed by default. Use ReadAIUnsigned / ReadAI32Unsigned when you need 065535 or 04294967295.
  • Except for WriteVirtualDI, write methods throw InvalidOperationException when the SDO write fails; the slave configuration stays unchanged.

Accessor types​

All four indexer properties are thin wrappers with the same behavior as the matching ReadXxx / WriteXxx methods.

DI​

public DIAccessor DI { get; }

Digital input indexer. DI[channel] reads the high/low level of a single channel by channel number (starting at 0) and converts it to SDO 0x6000 in groups of 8 channels.

Related structures:

public class DIAccessor
{
public bool this[int channel] { get; } // read-only, true = high level
}

Example:

bool ch0 = io.DI[0];
bool ch5 = io.DI[5];

DO​

public DOAccessor DO { get; }

Digital output indexer. DO[channel] both reads back the last written state and sets the target state (writes SDO 0x6200); the read-modify-write leaves the other channels in the group untouched.

Related structures:

public class DOAccessor
{
public bool this[int channel] { get; set; }
}

Example:

io.DO[0] = true;
io.DO[1] = io.DI[0];
bool current = io.DO[0];

AI​

public AIAccessor AI { get; }

Analog input indexer. AI[channel] reads SDO 0x6400 (subindex = channel + 1), adapts automatically to 16 or 32 bits based on the returned length, and returns a signed raw value. For unsigned 16-bit or unsigned 32-bit values, use ReadAIUnsigned / ReadAI32Unsigned.

Related structures:

public class AIAccessor
{
public int this[int channel] { get; } // read-only
}

Example:

int adc0 = io.AI[0];
double voltage = adc0 * 10.0 / 32768;

AO​

public AOAccessor AO { get; }

Analog output indexer. AO[channel] reads and writes 16-bit signed values (SDO 0x6411). Use WriteAO32 / ReadAO32 for 32-bit high-precision devices.

Related structures:

public class AOAccessor
{
public short this[int channel] { get; set; }
}

Example:

io.AO[0] = 16384;            // write 50% of full scale
short echo = io.AO[0]; // read back the current setpoint

Use the method API below when you need to tell read failures apart, read or write 16-bit or 32-bit bulk values, or configure interrupts.

Digital methods​

All channel numbers start at 0; the group number of the 16-bit and 32-bit bulk methods starts at 1 (group 1 = channels 0-15 or 0-31). A normal read method returns 0 / false on failure; use the matching TryRead* method to detect failure.

CategoryMethodTypeRead/writeDescription
InputReadDI(int channel)boolread-only0x6000, high/low level of a single channel
TryReadDI(int channel, out bool value)boolread-onlyfalse = read failed
ReadDI16(int group)ushortread-only0x6001, 16-channel bitmap
TryReadDI16(int group, out ushort value)boolread-only—
ReadDI32(int group)uintread-only0x6020, 32-channel bitmap
TryReadDI32(int group, out uint value)boolread-only—
OutputWriteDO(int channel, bool state)voidwrite-only0x6200, read-modify-write of the group byte
ReadDO(int channel)boolread-only0x6200 read-back
TryReadDO(int channel, out bool value)boolread-only—
ReadDO16(int group) / WriteDO16(int group, ushort value)ushort / voidread/write0x6201
TryReadDO16(int group, out ushort value)boolread-only—
ReadDO32(int group) / WriteDO32(int group, uint value)uint / voidread/write0x6220
TryReadDO32(int group, out uint value)boolread-only—
VirtualWriteVirtualDI(int diIndex, bool state)voidwrite-only0x2120:01-04; falls back to PDO when the SDO write is aborted, and throws InvalidOperationException when both fail

Except for WriteVirtualDI, write methods throw InvalidOperationException when the SDO write fails (the slave configuration stays unchanged); WriteDO also throws when it fails to read the old value of the group, rather than overwriting the other channels in the group from a 0 baseline.

ushort di16 = io.ReadDI16(1);            // channels 0-15
bool ch5 = (di16 & (1 << 5)) != 0;

io.WriteDO16(1, 0x00FF); // channels 0-7 driven high
uint do32 = io.ReadDO32(1); // 32-bit read-back

ReadDI​

public bool ReadDI(int channel)

Reads a digital input. The group number and bit offset are derived automatically for groups of 8 channels. A failed read returns false, which is indistinguishable from a real value; use TryReadDI to detect failure.

Parameters:

  • channel — channel number (starts at 0)

Return value:

  • bool — channel state (true = high level)

WriteDO(int channel, bool state)​

Parameters: channel — channel number (starts at 0); state — target level.

The group byte is read first and only the target bit is changed, so the other channels in the group are unaffected. A failed read of the old group value throws InvalidOperationException instead of rewriting from a 0 baseline; a failed SDO write throws the same exception and leaves the slave configuration as it was.

io.WriteDO(0, true);
io.WriteDO(1, io.DI[0]); // follow the input

ReadDO​

public bool ReadDO(int channel)

Reads a digital output state (SDO 0x6200, in groups of 8 channels). A failed read returns false, which is indistinguishable from a real value; use TryReadDO to detect failure.

Parameters:

  • channel — channel number (starts at 0)

Return value:

  • bool — channel state (true = high level)

ReadDI16(int group)​

public ushort ReadDI16(int group)

Reads the 16-bit digital input (16 channels).

Parameters:

  • group — group number (subindex, starts at 1, one group per 16 channels: group 1 = channels 0-15)

Return value:

  • ushort — 16-bit input value, one bit per channel

ReadDI32(int group)​

public uint ReadDI32(int group)

Reads the 32-bit digital input (32 channels).

Parameters:

  • group — group number (subindex, starts at 1, one group per 32 channels: group 1 = channels 0-31)

Return value:

  • uint — 32-bit input value, one bit per channel

Example:

var io = slave.CoE.CiA401;

ushort di16 = io.ReadDI16(1); // read channels 0-15
uint di32 = io.ReadDI32(1); // read channels 0-31
bool ch5 = (di16 & (1 << 5)) != 0; // check channel 5

ReadDO16 / WriteDO16​

public ushort ReadDO16(int group)
public void WriteDO16(int group, ushort value)

Reads or writes the 16-bit digital output (16 channels).

Parameters:

  • group — group number (subindex, starts at 1, one group per 16 channels: group 1 = channels 0-15)
  • value — 16-bit output value, bit0 corresponds to the 1st channel of the group

Return value:

  • ushort — 16-bit output value, one bit per channel (ReadDO16 only)

ReadDO32 / WriteDO32​

public uint ReadDO32(int group)
public void WriteDO32(int group, uint value)

Reads or writes the 32-bit digital output (32 channels).

Parameters:

  • group — group number (subindex, starts at 1, one group per 32 channels: group 1 = channels 0-31)
  • value — 32-bit output value, bit0 corresponds to the 1st channel of the group

Return value:

  • uint — 32-bit output value, one bit per channel (ReadDO32 only)

Example:

var io = slave.CoE.CiA401;

// 16-bit bulk operation
io.WriteDO16(1, 0x00FF); // channels 0-7 high, 8-15 low
ushort do16 = io.ReadDO16(1); // read back the current value

// 32-bit bulk operation
io.WriteDO32(1, 0x0000FFFF); // channels 0-15 high
uint do32 = io.ReadDO32(1); // read back the current value

WriteVirtualDI(int diIndex, bool state)​

Parameters: diIndex — virtual DI subindex, 1-4, corresponding to vendor object 0x2120:01-04; state — target state.

This object is normally accessible only through PDO: after an SDO abort 0x06020000 the write automatically switches to PDO; an SDO failure for any other reason also falls back to a PDO write attempt for that call. When both SDO and PDO fail, it throws InvalidOperationException.

io.WriteVirtualDI(1, true);   // 0x2120:01

Analog methods​

CategoryMethodTypeRead/writeDescription
InputReadAI(int channel)intread-only0x6400, signed, adapts automatically to 16 or 32 bits
TryReadAI(int channel, out int value)boolread-only—
ReadAIUnsigned(int channel)ushortread-only0x6400, unsigned 16-bit (0~65535)
TryReadAIUnsigned(int channel, out ushort value)boolread-only—
ReadAI32Unsigned(int channel)uintread-only0x6400, unsigned 32-bit
TryReadAI32Unsigned(int channel, out uint value)boolread-only—
OutputWriteAO(int channel, short value)voidwrite-only0x6411, 16-bit signed
ReadAO(int channel)shortread-only0x6411 read-back
TryReadAO(int channel, out short value)boolread-only—
ReadAO32(int channel) / WriteAO32(int channel, int value)int / voidread/write0x6412, 32-bit high precision
TryReadAO32(int channel, out int value)boolread-only—
int aiSigned = io.ReadAI(0);             // high values may turn negative
ushort aiU16 = io.ReadAIUnsigned(0); // 0~65535
uint aiU32 = io.ReadAI32Unsigned(0); // high-precision devices

io.WriteAO32(0, 65536);

Analog read conventions​

ReadAI adapts to 16 or 32 bits based on the length returned by the slave and always interprets the value as signed. Which read method to use for a channel depends on the device range:

Range / deviceUsageReturned range
Bipolar 16-bitReadAI / TryReadAI-32768 ~ 32767
Unipolar 16-bitReadAIUnsigned / TryReadAIUnsigned0 ~ 65535
High-precision 32-bit unsignedReadAI32Unsigned / TryReadAI32Unsigned0 ~ 4294967295
32-bit signed outputReadAO32 / WriteAO32int

Range scaling (for example 010 V mapped to 032768) is done in the application layer; the SDK returns raw values only.

Analog output writes​

WriteAO writes a 16-bit signed value (0x6411) and WriteAO32 writes a 32-bit value (0x6412). A failed write throws InvalidOperationException; use ReadAO / ReadAO32 to read back and TryReadAO / TryReadAO32 to detect failure.

io.WriteAO(0, 16384);      // 50% of full scale
io.WriteAO32(1, 65536); // high-precision channel

ReadAI​

public int ReadAI(int channel)

Reads an analog input value. It adapts to 16-bit and 32-bit devices based on the length returned by the slave and always interprets the value as signed. A failed read returns 0, which is indistinguishable from a real value; use TryReadAI to detect failure.

Parameters:

  • channel — channel number (starts at 0)

Return value:

  • int — signed analog value

WriteAO​

public void WriteAO(int channel, short value)

Writes a 16-bit signed analog output value (SDO 0x6411). A failed write throws InvalidOperationException (the slave output is unchanged).

Parameters:

  • channel — channel number (starts at 0)
  • value — 16-bit signed output value

ReadAO​

public short ReadAO(int channel)

Reads the 16-bit analog output value (SDO 0x6411). A failed read returns 0, which is indistinguishable from a real value; use TryReadAO to detect failure.

Parameters:

  • channel — channel number (starts at 0)

Return value:

  • short — 16-bit signed analog output value

ReadAIUnsigned​

public ushort ReadAIUnsigned(int channel)

Reads an analog input value (unsigned 16-bit). Suited to devices whose AI data range is 0~65535. A failed read returns 0, which is indistinguishable from a real value; use TryReadAIUnsigned to detect failure.

Parameters:

  • channel — channel number (starts at 0)

Return value:

  • ushort — unsigned 16-bit analog value

ReadAI32Unsigned​

public uint ReadAI32Unsigned(int channel)

Reads an analog input value (unsigned 32-bit). Suited to high-precision AI devices with a data range of 0~4294967295. A failed read returns 0, which is indistinguishable from a real value; use TryReadAI32Unsigned to detect failure.

Parameters:

  • channel — channel number (starts at 0)

Return value:

  • uint — unsigned 32-bit analog value

Example:

var io = slave.CoE.CiA401;

// signed read (default, high values may turn negative)
int aiSigned = io.ReadAI(0);

// unsigned 16-bit read (0~65535)
ushort aiU16 = io.ReadAIUnsigned(0);

// unsigned 32-bit read (high-precision devices)
uint aiU32 = io.ReadAI32Unsigned(0);

ReadAO32 / WriteAO32​

public int ReadAO32(int channel)
public void WriteAO32(int channel, int value)

Reads or writes the 32-bit analog output value (0x6412). Suited to high-precision analog output devices. A failed write throws InvalidOperationException (the slave output is unchanged); a failed read returns 0, which is indistinguishable from a real value, so use TryReadAO32 to detect failure.

Parameters:

  • channel — channel number (starts at 0)
  • value — 32-bit output value

Example:

var io = slave.CoE.CiA401;
io.WriteAO32(0, 65536); // write a 32-bit high-precision value
int ao = io.ReadAO32(0); // read back the current value

Interrupts and limits​

Analog input limit interrupt configuration:

CategoryMethodTypeRead/writeDescription
InterruptReadGlobalInterruptEnable() / WriteGlobalInterruptEnable(bool enable)bool / voidread/write0x6423 global enable
TryReadGlobalInterruptEnable(out bool enable)boolread-only0x6423 read-back; false = read failure, out is meaningless
Upper limitReadAIUpperLimit(int channel) / WriteAIUpperLimit(int channel, short value)int / voidread/write0x6424
TryReadAIUpperLimit(int channel, out int value)boolread-only—
Lower limitReadAILowerLimit(int channel) / WriteAILowerLimit(int channel, short value)int / voidread/write0x6425
TryReadAILowerLimit(int channel, out int value)boolread-only—
io.WriteGlobalInterruptEnable(true);
io.WriteAIUpperLimit(0, 30000);
io.WriteAILowerLimit(0, 1000);
  • WriteGlobalInterruptEnable(bool) is the global switch; when it is off, the per-channel upper and lower limits are retained but do not trigger.
  • The value of WriteAIUpperLimit / WriteAILowerLimit is a 16-bit signed raw value in the same scale as ReadAI; confirm the device range before setting it, so the limit does not end up triggering always or never.
  • Read the limits with ReadAIUpperLimit / ReadAILowerLimit; detect read failures with TryReadAIUpperLimit / TryReadAILowerLimit.
  • Read the global interrupt enable with ReadGlobalInterruptEnable; detect read failures with TryReadGlobalInterruptEnable.
  • Whether an interrupt is actually reported, and in which PDO bit, is decided by the slave; the SDK only configures the object entries.

ReadGlobalInterruptEnable / WriteGlobalInterruptEnable​

public bool ReadGlobalInterruptEnable()
public bool TryReadGlobalInterruptEnable(out bool enable)
public void WriteGlobalInterruptEnable(bool enable)

Reads or sets the global analog input interrupt enable (0x6423). A failed read returns false, which is indistinguishable from a real value; a failed write throws InvalidOperationException (the slave configuration is unchanged).

TryReadGlobalInterruptEnable separates "the global interrupt is genuinely off" from "the read failed": it returns false on a read failure, in which case enable is meaningless (the implementation sets it to false); only when it returns true does enable hold the real value.

Parameters:

  • enable — true = enabled, false = disabled (WriteGlobalInterruptEnable); an output parameter for TryReadGlobalInterruptEnable

Return value:

  • bool — whether the global interrupt is enabled (ReadGlobalInterruptEnable only); TryReadGlobalInterruptEnable returns whether the read succeeded
if (io.TryReadGlobalInterruptEnable(out bool enabled))
Console.WriteLine(enabled ? "全局中断已使能" : "全局中断已关闭"); // global interrupts enabled / global interrupts disabled
else
Console.WriteLine("全局中断使能读取失败, 不能断言已关闭"); // Reading the global interrupt enable failed, cannot assert it is off

ReadAIUpperLimit / WriteAIUpperLimit​

public int ReadAIUpperLimit(int channel)
public void WriteAIUpperLimit(int channel, short value)

Reads or writes the analog input interrupt upper limit (0x6424). The interrupt triggers when the AI value exceeds the upper limit. A failed write throws InvalidOperationException (the slave configuration is unchanged); a failed read returns 0, which is indistinguishable from a real value, so use TryReadAIUpperLimit to detect failure.

Parameters:

  • channel — channel number (starts at 0)
  • value — upper limit (16-bit signed raw value)

ReadAILowerLimit / WriteAILowerLimit​

public int ReadAILowerLimit(int channel)
public void WriteAILowerLimit(int channel, short value)

Reads or writes the analog input interrupt lower limit (0x6425). The interrupt triggers when the AI value falls below the lower limit. A failed write throws InvalidOperationException (the slave configuration is unchanged); a failed read returns 0, which is indistinguishable from a real value, so use TryReadAILowerLimit to detect failure.

Parameters:

  • channel — channel number (starts at 0)
  • value — lower limit (16-bit signed raw value)

Example:

var io = slave.CoE.CiA401;

// enable the global interrupt
io.WriteGlobalInterruptEnable(true);

// set the upper and lower limits of channel 0
io.WriteAIUpperLimit(0, 30000);
io.WriteAILowerLimit(0, 1000);

// read the current limit configuration
int upper = io.ReadAIUpperLimit(0);
int lower = io.ReadAILowerLimit(0);
bool enabled = io.ReadGlobalInterruptEnable();

Digital input configuration and error safe values​

CategoryMethodTypeRead/writeDescription
Digital inputSetDIPolarity(int group, byte polarity) / GetDIPolarity(int group)void / byteread/write0x6002, 1 = invert the corresponding channel
TryGetDIPolarity(int group, out byte polarity)boolread-only0x6002 read-back; false = read failure, out is meaningless
SetDIFilter(int group, byte filterEnable) / GetDIFilter(int group)void / byteread/write0x6003, filter enable mask
TryGetDIFilter(int group, out byte filterEnable)boolread-only0x6003 read-back; false = read failure, out is meaningless
Error modeDOErrorMode(int group, CiA401ErrorMode mode)voidwrite-only0x6206, output behavior when communication is lost
DOErrorValue(int group, byte value)voidwrite-only0x6207, safe output value (8-bit)
GetDOErrorMode(int group) / TryGetDOErrorMode(int group, out CiA401ErrorMode mode)CiA401ErrorMode / boolread-only0x6206 read-back
GetDOErrorValue(int group) / TryGetDOErrorValue(int group, out byte value)byte / boolread-only0x6207 read-back
Analog outputAOErrorMode(int channel, CiA401ErrorMode mode)voidwrite-only0x6443
AOErrorValue(int channel, short value)voidwrite-only0x6444, 16-bit safe value
public enum CiA401ErrorMode : byte
{
Hold = 0, // hold the current output value
SafeValue = 1, // switch to the preset safe value
}
io.SetDIPolarity(1, 0x0F);           // invert channels 0-3
io.SetDIFilter(1, 10);

SetDIPolarity / SetDIFilter​

Parameters:

  • group — group number (subindex, starts at 1, one group per 8 channels)
  • polarity — polarity mask, 1 = invert the corresponding channel, bit0 corresponds to the 1st channel of the group
  • filterEnable — filter enable mask; the bit definitions are defined by the slave implementation

Read-back and failure detection:

  • GetDIPolarity / GetDIFilter return 0 on a read failure, which is indistinguishable from "polarity / filter is genuinely all zero"; they must not be used as a configuration read-back conclusion. Use TryGetDIPolarity / TryGetDIFilter to tell the cases apart.
  • TryGetDIPolarity / TryGetDIFilter return false on a read failure, in which case the out parameter is meaningless (the implementation sets it to 0); only when they return true does out hold the slave's real value.
io.SetDIPolarity(1, 0x0F);    // invert channels 0-3 of group 1
io.SetDIFilter(1, 10);

if (io.TryGetDIPolarity(1, out byte pol))
Console.WriteLine($"极性 = 0x{pol:X2}"); // Polarity = 0x{pol:X2}
else
Console.WriteLine("极性读取失败, 不能断言为 0"); // Polarity read failed, cannot assert it is 0

if (!io.TryGetDIFilter(1, out byte flt))
Console.WriteLine("滤波使能读取失败"); // Filter enable read failed

Error safe values​

DOErrorMode(int group, CiA401ErrorMode mode) decides how the digital outputs respond when EtherCAT communication is lost; DOErrorValue(int group, byte value) is the 8-bit safe value in SafeValue mode (bit0 corresponds to the 1st channel of the group). AOErrorMode / AOErrorValue work the same way for analog outputs, with a 16-bit safe value.

  • Hold — keep the last output value
  • SafeValue — switch to the preset safe value; when SafeValue is configured without DOErrorValue / AOErrorValue, 0 is used
  • The group of the error mode starts at 0 (group 0 = channels 0-7), unlike the group number of polarity and filter (starts at 1)
  • These settings take effect only when communication is lost; normal cyclic output is still controlled by DO / AO
  • Read the configuration back with GetDOErrorMode / GetDOErrorValue; detect failures with TryGetDOErrorMode / TryGetDOErrorValue
io.DOErrorMode(0, CiA401ErrorMode.SafeValue);
io.DOErrorValue(0, 0x00); // drive the whole group low when communication is lost
io.AOErrorMode(0, CiA401ErrorMode.SafeValue);
io.AOErrorValue(0, 0);

// read the configuration back
var mode = io.GetDOErrorMode(0);
byte safeVal = io.GetDOErrorValue(0);
Console.WriteLine($"错误模式: {mode}, 安全值: 0x{safeVal:X2}"); // Error mode: {mode}, safe value: 0x{safeVal:X2}

Telling read failures apart​

Normal read methods (ReadDI / ReadAI / ReadDO16 and so on) return the placeholder 0 / false / Hold on failure, which is indistinguishable from a real value, so they must not take part in interlocks as process state. A Try-prefixed method returns false to signal a failed read (the out parameter is meaningless then); only when it returns true does out hold the real value.

Configuration read-back follows the same rule: TryGetDIPolarity / TryGetDIFilter / TryReadGlobalInterruptEnable, together with TryGetDOErrorMode / TryGetDOErrorValue / TryReadAIUpperLimit / TryReadAILowerLimit.

Method familyPlaceholder returned on a failed read
ReadDI / ReadDO / ReadGlobalInterruptEnablefalse
ReadDI16 / ReadDO16 / ReadDI32 / ReadDO320
ReadAI / ReadAIUnsigned / ReadAI32Unsigned0
ReadAO / ReadAO32 / ReadAIUpperLimit / ReadAILowerLimit0
GetDIPolarity / GetDIFilter / GetDOErrorValue0
GetDOErrorModeHold
if (io.TryReadAI(0, out int ai))
Console.WriteLine($"AI0 = {ai}");
else
Console.WriteLine("AI0 读取失败, 不可当测量值使用"); // AI0 read failed, must not be used as a measurement value

This "real value / not supported / read failed" convention matches observable read-only reads in CiA 402.

Return values and exceptions​

CategoryBehavior
Normal readA failed read returns the placeholder 0 / false / Hold, which is indistinguishable from a real value
TryRead*false = read failed, and out is meaningless then; when it returns true, out holds the real value
WriteA failed SDO write throws InvalidOperationException; the slave configuration is unchanged
Virtual DIFalls back to PDO when the SDO is aborted; throws InvalidOperationException when both fail
AccessorDI[n] / DO[n] / AI[n] / AO[n] have the same semantics as the methods: read accessors do not throw and return the placeholder on a failed read; assigning to DO[n] / AO[n] also throws InvalidOperationException on failure

Typical sequence​

  1. Confirm that slave.CoE.CiA401 is not null.
  2. Configure input polarity and filtering (SetDIPolarity / SetDIFilter).
  3. Configure the error mode and safe values for loss of communication (DOErrorMode / DOErrorValue / AOErrorMode / AOErrorValue).
  4. If analog limit interrupts are needed, configure WriteGlobalInterruptEnable and the upper and lower limits.
  5. Use PDO or the indexers for cyclic read and write; use the SDO methods for parameter configuration and diagnostics.

Real-time behavior and threads​

  • Use PDO for high-frequency cyclic control; do not issue per-channel SDO requests from a real-time thread.
  • Indexers and methods access the same object dictionary; when several threads read or write the same channel at once, the application layer must ensure ordering.
  • WriteDO is a read-modify-write, not an atomic operation; concurrent writes to several channels of the same group must be serialized by the application layer.
  • The error safe values are a "communication lost" policy, not an application-level emergency stop; emergency stops still go through PDO and the drive safety chain.

Consistency and snapshots​

A per-channel read is an independent SDO each time, so the values may come from different cycles and must not be used in interlocks as a snapshot of a single instant. When same-cycle consistency is required:

  • Read the whole group in one call with ReadDI16 / ReadDI32 / ReadDO16 / ReadDO32 (a single transaction)
  • Or use the PDO process image directly, where all channels update together within one cycle

Channel range​

The SDK does not restrict channel numbers; the usable range is determined by the slave objects. A subindex beyond those the slave implements either fails to read or returns an abort, and TryRead* distinguishes a read failure from a real value of 0. The same applies to group numbers: check the subindex range given in the slave documentation before a bulk read.

Writing and reading back​

  • When several channels of a group must change together, write the whole group at once with WriteDO16 / WriteDO32 to avoid intermediate states.
  • A successful SDO write only means the object dictionary was written; it does not guarantee that the output terminal has already acted. For critical outputs, read back with ReadDO / ReadAO after writing, or confirm from the PDO input side.
  • During a communication loss, writes may be overridden by the drive error safe values; after recovery the target values must be sent again.

FAQ​

SymptomCheck order
DI[n] is always falseWhether the channel number starts at 0, whether polarity is inverted, whether the input voltage reaches the threshold; use TryReadDI to tell a failed read apart
Other channels in the group change after writing DO[n]Check whether 0x6200 bytes are written directly, bypassing WriteDO; WriteDO itself changes only the target bit
No output after writing AOConfirm the range and that 32-bit devices use WriteAO32, that the error mode is not SafeValue, and that communication is healthy
Analog reading has the wrong signSwitch to ReadAIUnsigned / ReadAI32Unsigned when the device range is unipolar
Interrupt does not triggerWhether the global interrupt is enabled, whether the limits fall within the actual reading range, and whether the slave supports the object
Write throws InvalidOperationExceptionCheck the object index in the log; most often an SDO write failure or a failed read of the old group value, and the slave configuration has not been rewritten

Standard object index constants​

These can be used directly with slave.CoE.SDORead / SDOWrite:

ConstantValueDescription
OD_VIRTUAL_DI0x2120Virtual DI command (vendor object, must go through PDO)
OD_DI0x6000Digital input
OD_DI_16BIT0x600116-bit digital input
OD_DI_POLARITY0x6002Digital input polarity
OD_DI_FILTER0x6003Digital input filter enable
OD_DI_INTERRUPT0x6005Digital input interrupt trigger
OD_DI_INTERRUPT_EDGE0x6006Digital input interrupt edge
OD_DI_32BIT0x602032-bit digital input
OD_DO0x6200Digital output
OD_DO_16BIT0x620116-bit digital output
OD_DO_POLARITY0x6202Digital output polarity
OD_DO_ERROR_MODE0x6206Digital output error mode
OD_DO_ERROR_VALUE0x6207Digital output error value
OD_DO_32BIT0x622032-bit digital output
OD_AI0x6400Analog input
OD_AI_SI_UNIT0x6420Analog input range
OD_AI_GLOBAL_INTERRUPT0x6423Analog input global interrupt enable
OD_AI_UPPER_LIMIT0x6424Analog input interrupt upper limit
OD_AI_LOWER_LIMIT0x6425Analog input interrupt lower limit
OD_AO0x6411Analog output
OD_AO_32BIT0x641232-bit analog output
OD_AO_SI_UNIT0x6430Analog output range
OD_AO_ERROR_MODE0x6443Analog output error mode
OD_AO_ERROR_VALUE0x6444Analog output error value

Full example — initialization and cyclic read/write​

var io = slave.CoE.CiA401;
if (io == null) return;

// one-time configuration
io.SetDIFilter(1, 0x0F);
io.DOErrorMode(0, CiA401ErrorMode.SafeValue);
io.DOErrorValue(0, 0x00);

// read and write in the cyclic task (switch to PDO for high frequencies)
while (running)
{
if (io.TryReadAI(0, out int adc) && io.TryReadDI(0, out bool start))
{
io.WriteDO(0, start);
io.WriteAO(0, (short)Math.Clamp(adc, -32768, 32767));
}
Thread.Sleep(10);
}