Skip to main content

FSoE functional safety

FSoE layers a functional safety protocol on top of the standard PDO channel: the master maintains the safety connection state machine, the slave executes the safety logic, and the safety data carries a CRC and a sequence number check.

This is not a certified safety product, nor a PLC capability; the safety level that can be reached is determined by the safety devices and the overall safety concept.

A null slave.FSoE means the slave does not support FSoE; do not attempt to bind.

Accessed through slave.FSoE. null when the slave does not support FSoE.​

FSoE device detection

slave.FSoE is detected automatically when the slave is initialized. The detection sequence:

  1. CoE prerequisite — the slave must support the CoE mailbox protocol
  2. 0xF980:01 check — attempt an SDO read of the device-level FSoE safety address; success confirms support
  3. 0x9001:02 check — if the previous step fails, attempt to read the MDP connection parameters (applies to multi-module safety devices)

Checking CoE support alone is not enough, because many non-safety devices (such as ordinary servo drives) also support CoE. An FSoE device must implement the specific safety object indices to be recognized correctly.

Quick start​

FSoE workflow​

FSoE establishes an independent safety connection over the EtherCAT PDO channel. The master handles protocol management; the slave handles the safety logic.

State machine flow:

  • Reset — initial state, waiting for the master to start a session
  • Session — session established, connection ID exchanged
  • Connection — connection established, safety address verified
  • Parameter — parameter download phase (SRA CRC check)
  • Data — normal safety data exchange
  • Failsafe — failsafe, the slave outputs safe values
Recommended approach

Use the code export feature of Darra EtherCAT Master Tools to generate the safety data structures and binding code in one step.

Minimal example (digital safety IO)​

// safety data structure (exported in one step by the Darra configuration tool)
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDigitalInput // EL19xx: 2 bytes
{
public byte InputBits; // safety input status bits (one bit per channel)
public byte DiagBits; // input diagnostic status
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDigitalOutput // EL29xx: 1 byte
{
public byte OutputBits; // safety output control bits
}
var slave = master.Slaves[0];  // EL1904 safety input + EL2904 safety output

// 1. one-line bind + exchange callback: infers the data size and starts the data exchange
// exchange is called on the PDO cycle path and receives the safety inputs/outputs by ref (automatic safety data exchange on every cycle is not standard)
slave.FSoE.BindSafeIO<SafeDigitalInput, SafeDigitalOutput>(
safetyAddress: 0x0100,
exchange: (ref SafeDigitalInput input, ref SafeDigitalOutput output) =>
{
bool ch0 = (input.InputBits & 0x01) != 0;
output.OutputBits = ch0 ? (byte)0x01 : (byte)0x00;
});

// 2. subscribe to events (raised automatically, no manual call needed)
slave.FSoE.ErrorOccurred += (s, e) =>
Console.WriteLine($"FSoE 错误: {e.Description}"); // FSoE error: {e.Description}

Method overview​

CategoryMethodTypeRead/writeDescription
BindingBindSafeIOboolWrite-onlyBinds safety inputs and safety outputs together; one line performs initialization and starts the data exchange
BindingBindSafeInputboolWrite-onlyBinds safety inputs only (output size 0); for pure safety input devices
BindingBindSafeOutputboolWrite-onlyBinds safety outputs only (input size 0); for pure safety output devices
BindingBindMdpSafeIOboolWrite-onlyMDP multi-connection binding; each call adds an independent safety connection
BindingBindMdpSafeInputboolWrite-onlyMDP multi-connection binding for safety inputs only
BindingBindMdpSafeOutputboolWrite-onlyMDP multi-connection binding for safety outputs only
BindingBindMdpDriveAxisboolWrite-onlyMDP drive-axis safety connection binding; one independent connection per axis
State controlRequestStateboolWrite-onlyRequests a transition to the target FSoE state; the SDK checks whether the transition is legal
State controlEnterFailsafeboolWrite-onlyEnters failsafe explicitly; the slave outputs the preset safe values
State controlResetboolWrite-onlyResets the safety connection and starts the handshake again from Reset
State controlCloseboolWrite-onlyCloses the FSoE connection and releases resources
Parameters and configurationDownloadParametersboolWrite-onlyDownloads safety parameters; callable only in the Parameter state
Parameters and configurationSetFailsafeOutputboolWrite-onlyPresets the output value used in failsafe
DiagnosticsClearErrorvoidWrite-onlyClears the FSoE error
DiagnosticsCheckWatchdogboolRead-onlyChecks whether the watchdog is healthy; false means it has expired or is not initialized
DiagnosticsGetTotalConnectionCountushortRead-onlyTotal master-level FSoE connections (sum over all slaves)
DiagnosticsGetSlaveConnectionCountushortRead-onlyNumber of FSoE connections registered for this slave
DiagnosticsDetectConnectionsushortRead-onlyProbes the actual number of FSoE connections on this slave
Multi-connectionGetConnectionFSoEConnection?Read-onlyGets an MDP connection by index
Multi-connectionFindConnectionByAddressFSoEConnection?Read-onlyFinds an MDP connection by safety address
Connection validationIsConnectionIdAvailableboolRead-onlyChecks whether a connection ID is available (static method on FSoEHelper)

FSoE versus regular PDO​

FSoE safety data cannot be used as user safety IO through CopyInputPdo / WriteOutputPdo the way regular PDOs can. IOmap holds FSoE protocol frames; the user's safety data is wrapped inside the frame and must pass the checks. Reading or writing IOmap directly, bypassing the SDK, breaks the integrity of the safety protocol, so FSoE safety data must be accessed through the separate channel created by BindSafeIO.

The SDK's FSoE protocol engine handles: CRC checking (verifies input frame integrity, computes the output frame CRC), state machine management (advances Session → Connection → Parameter → Data automatically), watchdog (monitors communication timeouts and enters Failsafe automatically on timeout), and sequence numbers (detects lost and duplicate frames).

Comparison in use

Despite the different mechanism, using BindSafeIO + the exchange callback is already very close to regular PDO:

  • Regular PDO — process data is read and written directly through the mapping (slave.PDO.InputsMapping / OutputsMapping); when a snapshot is needed, copy the whole frame with CopyInputPdo / WriteOutputPdo. The data in IOmap is the user data
  • FSoE PDO — after checking, safety data is read and written by ref inside the exchange callback; at the end of the cycle the SDK sends the safety outputs in one pass

Simplified binding​

BindSafeIO<TIn, TOut>()​

public bool BindSafeIO<TIn, TOut>(ushort safetyAddress,
SafeDataExchangeHandler<TIn, TOut>? exchange = null,
uint watchdogMs = 100, ushort connectionId = 0)
where TIn : struct where TOut : struct

One line performs FSoE initialization + starts the data exchange. SafeInputSize / SafeOutputSize are inferred from the structs; the PDO offset is fixed at station offset 0 (the start of this slave's PDOs, not the global IOmap offset); a connectionId of 0 is allocated automatically (a safety application should take a fixed connection ID from the ESI / configuration tool).

The exchange callback is invoked on the PDO cycle path and receives the safety inputs/outputs directly by ref; no copying is needed (automatic safety data exchange on every cycle is not standard).

Parameters:

  • safetyAddress (ushort) — slave safety address (hardware DIP switch)
  • exchange (SafeDataExchangeHandler<TIn, TOut>?) — data exchange callback (optional)
  • watchdogMs (uint) — watchdog timeout in milliseconds, default 100
  • connectionId (ushort) — connection ID; 0 allocates one automatically

Return value:

  • bool — true on success (initialized and exchanging data); returns false when initialization succeeds but starting the data exchange fails, and rolls back this binding (you can bind again)

Example:

slave.FSoE.BindSafeIO<SafeDigitalInput, SafeDigitalOutput>(
safetyAddress: 0x0100,
exchange: (ref SafeDigitalInput input, ref SafeDigitalOutput output) =>
{
output.OutputBits = input.InputBits;
});
Automatic state progression

BindSafeIO performs initialization + starts the data exchange in one line; the intermediate states (Session → Connection → Parameter) are advanced by the SDK automatically.

BindSafeInput<TIn>()​

public bool BindSafeInput<TIn>(ushort safetyAddress,
SafeInputExchangeHandler<TIn>? exchange = null,
uint watchdogMs = 100, ushort connectionId = 0)
where TIn : struct

Binds safety inputs only (SafeOutputSize = 0); for pure safety input devices such as EL1904. Parameters and return value are the same as BindSafeIO (without the output side).

Example:

slave.FSoE.BindSafeInput<SafeDigitalInput>(
safetyAddress: 0x0100,
exchange: (ref SafeDigitalInput input) =>
{
lastInput = input; // capture the latest input
});

BindSafeOutput<TOut>()​

public bool BindSafeOutput<TOut>(ushort safetyAddress,
SafeOutputExchangeHandler<TOut>? exchange = null,
uint watchdogMs = 100, ushort connectionId = 0)
where TOut : struct

Binds safety outputs only (SafeInputSize = 0); for pure safety output devices such as EL2904. Parameters and return value are the same as BindSafeIO (without the input side).

Example:

slave.FSoE.BindSafeOutput<SafeDigitalOutput>(
safetyAddress: 0x0200,
exchange: (ref SafeDigitalOutput output) =>
{
output.OutputBits = lastInput.InputBits; // pass input straight to output
});

BindMdpSafeIO<TIn, TOut>()​

// automatic offset (computed from the DENI PDO configuration)
public bool BindMdpSafeIO<TIn, TOut>(ushort safetyAddress,
SafeDataExchangeHandler<TIn, TOut>? exchange = null, uint watchdogMs = 100)
where TIn : struct where TOut : struct

// explicit offset (user-supplied module station PDO offset, not the global IOmap offset)
public bool BindMdpSafeIO<TIn, TOut>(ushort safetyAddress,
uint pdoInputOffset, uint pdoOutputOffset,
SafeDataExchangeHandler<TIn, TOut>? exchange = null, uint watchdogMs = 100)
where TIn : struct where TOut : struct

MDP multi-connection binding. Each call adds an independent FSoE connection and infers the safety data size from the struct. All connections start automatically on the first PDO cycle; no manual call is needed.

The automatic-offset overload computes each module's station PDO offset from the DENI PDO Assignment/Mapping configuration through slave.MDP.GetModulePdoLayout() (an offset relative to slave.Ioffset / slave.Ooffset, not the global IOmap offset) and assigns them in call order (matching the slot order). The slave must have a completed DENI configuration (after ConfigMap) and the MDP must have detected its modules.

Example:

// automatic offset + exchange callback (recommended)
slave.FSoE.BindMdpSafeIO<SafeDigitalInput, SafeDigitalOutput>(
safetyAddress: 0x0100,
exchange: (ref SafeDigitalInput input, ref SafeDigitalOutput output) =>
{
output.OutputBits = input.InputBits;
});
slave.FSoE.BindMdpSafeIO<SafeDigitalInput, SafeDigitalOutput>(safetyAddress: 0x0200);

// explicit offset — user-supplied module station PDO offset (relative to this slave's PDO start, not the global IOmap offset)
slave.FSoE.BindMdpSafeIO<SafeDigitalInput, SafeDigitalOutput>(
safetyAddress: 0x0100, pdoInputOffset: 0, pdoOutputOffset: 0);
slave.FSoE.BindMdpSafeIO<SafeDigitalInput, SafeDigitalOutput>(
safetyAddress: 0x0200, pdoInputOffset: 7, pdoOutputOffset: 6);
Automatic PDO offset calculation

The automatic offset relies on slave.MDP.GetModulePdoLayout() (see the MDP page) and accumulates the byte offset from each module's PDO configuration (relative to slave.Ioffset / slave.Ooffset).

The slave must have a completed DENI configuration (after ConfigMap); an ESI file is not strictly required: when the ESI is available the offsets are allocated exactly per module PDO count, otherwise they are estimated by even distribution (which may be inaccurate). If the MDP modules are not detected or CoE is unavailable, the automatic offset falls back to station offset 0 (the start of this slave's PDOs); in that case use the explicit-offset overload.

BindMdpSafeInput<TIn>() / BindMdpSafeOutput<TOut>()​

public bool BindMdpSafeInput<TIn>(ushort safetyAddress,
SafeInputExchangeHandler<TIn>? exchange = null, uint watchdogMs = 100)
where TIn : struct
public bool BindMdpSafeOutput<TOut>(ushort safetyAddress,
SafeOutputExchangeHandler<TOut>? exchange = null, uint watchdogMs = 100)
where TOut : struct

MDP multi-connection binding (safety inputs only / safety outputs only) with automatic offset.

BindMdpDriveAxis<TIn, TOut>()​

// automatic offset
public bool BindMdpDriveAxis<TIn, TOut>(int axisNumber, ushort safetyAddress,
SafeDataExchangeHandler<TIn, TOut>? exchange = null, uint watchdogMs = 100)
where TIn : struct where TOut : struct

// explicit offset (station PDO offset, not the global IOmap offset)
public bool BindMdpDriveAxis<TIn, TOut>(int axisNumber, ushort safetyAddress,
uint pdoInputOffset, uint pdoOutputOffset,
SafeDataExchangeHandler<TIn, TOut>? exchange = null, uint watchdogMs = 100)
where TIn : struct where TOut : struct

MDP drive-axis safety connection binding. One independent FSoE connection per axis. Started automatically on the first PDO cycle.

Example:

slave.FSoE.BindMdpDriveAxis<SafeDriveInput, SafeDriveOutput>(
axisNumber: 0, safetyAddress: 0x0100,
exchange: (ref SafeDriveInput input, ref SafeDriveOutput output) =>
{
if ((input.SafetyStatusWord & 0x0100) != 0)
output.SafetyControlWord |= 0x0080; // acknowledge the fault
});
slave.FSoE.BindMdpDriveAxis<SafeDriveInput, SafeDriveOutput>(
axisNumber: 1, safetyAddress: 0x0200);

DataExchanged event​

public event EventHandler<FSoEDataExchangeEventArgs>? DataExchanged;

Slave-level safety data exchange event (multiple subscribers, registered with +=). It is raised automatically in every PDO cycle after the safety inputs are refreshed and before the safety outputs are committed; the event arguments carry the current FSoE state, the safety inputs/outputs, the failsafe flag, the cycle count and a timestamp.

Related structures:

public class FSoEDataExchangeEventArgs : EventArgs
{
public ushort SlaveIndex { get; } // slave index
public FSoEState CurrentState { get; } // current FSoE state for this cycle
public byte[] SafeInputs { get; } // safety input snapshot for this cycle (a copy)
public byte[] SafeOutputs { get; } // safety output snapshot for this cycle (a copy, the value before commit)
public bool InFailsafe { get; } // whether the connection is in failsafe mode
public uint CycleCount { get; } // accumulated PDO cycle count
public DateTime Timestamp { get; } // timestamp when the event was raised
}
slave.FSoE.DataExchanged += (sender, e) =>
{
// e.CurrentState / e.SafeInputs / e.SafeOutputs / e.InFailsafe / e.CycleCount / e.Timestamp
};
DataExchange is deprecated

The old public event Action? DataExchange (a callback without context) is marked [Obsolete]; new code should use DataExchanged above (which carries the full FSoEDataExchangeEventArgs context). Both are multi-subscriber events and must be registered with +=; do not assign them with =, which replaces the existing subscribers.

Prefer the exchange callback

The exchange parameter of BindSafeIO / BindMdpSafeIO is registered automatically as the data exchange callback and passes the safety data as a typed ref. Subscribing to DataExchanged directly suits scenarios where you manage the data of several slaves manually.

PDO cycle timing

After binding, safety data can be read and written on the PDO cycle path (automatic safety data exchange on every cycle is not standard):

  1. Cycle start — refresh the safety input buffers of all FSoE slaves, check for state changes and raise events
  2. exchange callback — slave-level callback; reads the ref inputs (already the latest data) and modifies the ref outputs
  3. ProcessDataCyclicSync callback — master-level callback (regular PDO read/write)
  4. Cycle end — the SDK sends the safety outputs of all FSoE slaves in one pass

Properties​

CategoryPropertyTypeRead/writeDescription
StateIsInitializedboolRead-onlyWhether the instance is initialized
StateFSoEStateRead-onlyCurrent FSoE state
InFailsafeboolRead-onlyWhether the connection is in failsafe mode
WatchdogExpiredboolRead-onlyWhether the watchdog has expired
LastErrorFSoEErrorRead-onlyLast error code
ConnectionConfigFSoEConnectionConfig?Read-onlyCurrent connection configuration
StatusFSoEConnectionStatusRead-onlyConnection status details (communication statistics)
StatusValidboolRead-onlyWhether the most recent status read was valid; false means there is no connection or the read failed, and values such as Status / InFailsafe / WatchdogExpired cannot be trusted
Multi-connectionIsMdpModeboolRead-onlyWhether MDP multi-connection mode is active
ConnectionCountintRead-onlyNumber of connections (1 in single-connection mode, the number of modules in multi-connection mode, 0 when not initialized)
ManagerSafetyManager?Read-onlyMDP multi-connection manager (null when not in MDP mode)
FSoEState enum
public enum FSoEState : int
{
Reset = 0x100, // initial/reset state
Session = 0x101, // session established
Connection = 0x102, // connection established
Parameter = 0x103, // parameter download
Data = 0x104, // data exchange (normal operation)
Failsafe = 0x105 // failsafe
}
FSoEError enum
public enum FSoEError : int
{
None = 0x0000, // no error
WrongCommand = 0x0001, // wrong command
UnknownCommand = 0x0002, // unknown command
WrongConnectionId = 0x0003, // connection ID mismatch
CrcError = 0x0004, // CRC check failed
Watchdog = 0x0005, // watchdog timeout
WrongAddress = 0x0006, // wrong FSoE address
WrongData = 0x0007, // invalid data
CommParamLength = 0x0008, // communication parameter length error
CommParam = 0x0009, // communication parameter error
AppParamLength = 0x000A, // application parameter length error
AppParam = 0x000B, // application parameter error
UnexpectedSession = 0x000C, // unexpected session command
FailsafeData = 0x000D, // failsafe data received
OutputBindingUnsupported = 0x000E, // missing versioned PDO transaction bound on the slave (fail-closed)
NotInitialized = 0x0100, // FSoE not initialized (SDK-level error)
MaxConnections = 0x0101, // maximum number of connections reached (SDK-level error)
InvalidStateTransition = 0x0102 // invalid state transition (SDK-level error)
}
FSoEConnectionStatus
CategoryPropertyTypeRead/writeDescription
StateStateFSoEStateRead-onlyCurrent FSoE state
LastErrorFSoEErrorRead-onlyLast error code
StatisticsErrorCountuintRead-onlyTotal error count
FramesSentuintRead-onlyFrames sent
FramesReceiveduintRead-onlyValid frames received
CrcErrorsuintRead-onlyCRC error count
WatchdogErrorsuintRead-onlyWatchdog timeout count
StateWatchdogExpiredboolRead-onlyWhether the watchdog has expired
InFailsafeboolRead-onlyWhether the connection is in failsafe mode
ToggleBitbyteRead-onlyCurrent toggle bit value
IsInitializedboolRead-onlyWhether the connection is initialized
FSoEConnectionConfig
CategoryPropertyTypeRead/writeDescription
Connection configurationConnectionIdushortRead/writeUnique connection identifier
SafetyAddressushortRead/writeFSoE slave safety address (set by DIP switch)
WatchdogTimeMsuintRead/writeWatchdog timeout in milliseconds, default 100; valid values are 0 or ≥ 2 (0 keeps the default), any other value throws ArgumentOutOfRangeException
SafeInputSizeushortRead/writeSafety input data size in bytes, determined by the device
SafeOutputSizeushortRead/writeSafety output data size in bytes, determined by the device
PdoInputOffsetuintRead/writeStation offset of the FSoE frame inside this slave's TxPDO (an offset relative to slave.Ioffset, not the global IOmap offset)
PdoOutputOffsetuintRead/writeStation offset of the FSoE frame inside this slave's RxPDO (an offset relative to slave.Ooffset, not the global IOmap offset)

Safety data structures​

Recommended approach

Use the code export feature of Darra EtherCAT Master Tools to generate the safety data structures and binding code in one step. The generated output contains the correct struct sizes, field layout and FSoE binding calls, so manual definitions do not go wrong.

Safety data structure examples:

// EL19xx digital safety input (2 bytes of safety data)
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDigitalInput
{
public byte InputBits; // safety input status bits (one bit per channel)
public byte DiagBits; // input diagnostic status
}

// EL29xx digital safety output (1 byte of safety data)
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDigitalOutput
{
public byte OutputBits; // safety output control bits
}

// ETG.6100 safety drive input (10 bytes of safety data)
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDriveInput
{
public ushort SafetyStatusWord; // safety status word
public int SafeActualPosition; // safe actual position
public int SafeActualVelocity; // safe actual velocity
}

// ETG.6100 safety drive output (2 bytes of safety data)
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDriveOutput
{
public ushort SafetyControlWord; // safety control word
}

// safety encoder input (6 bytes of safety data)
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeEncoderInput
{
public uint SafePosition; // safe position value
public ushort StatusWord; // status word
}
Struct sizes must match

SafeInputSize / SafeOutputSize must match Marshal.SizeOf<T>() for the struct, otherwise reads and writes fail.

State control​

Safety connection state machine: Reset → Session → Connection → Parameter → Data; Data and Failsafe switch to each other, and any state can be reset back to Reset. For the meaning of each state and the transition diagram see FSoE workflow.

RequestState(FSoEState targetState)​

public bool RequestState(FSoEState targetState)

Requests an FSoE state transition. The validity of the transition is checked automatically; entering Data requires the master to be in OP, the other states require at least SafeOp. If that is not the case the SDK tries to change the master state automatically and returns false if the change fails.

Parameters:

Return value:

  • bool — true on success

EnterFailsafe()​

public bool EnterFailsafe()

Enters failsafe mode explicitly. The slave outputs the safe values (preset by SetFailsafeOutput).

Return value:

  • bool — true on success

Reset (FSoE protocol state)​

public bool Reset()

Resets the FSoE safety connection of this slave so the state machine starts the handshake again from Reset. It affects only the FSoE protocol layer; it does not change the slave's EtherCAT state and does not affect the master diagnostic counters (it is unrelated to the diagnostic counter reset master.Diagnostics.Reset).

Return value:

  • bool — true on success

Close()​

public bool Close()

Closes the FSoE connection and releases resources.

Return value:

  • bool — true on success, false on failure

Parameters and configuration​

DownloadParameters(byte[] parameterData, out uint sraCrc)​

public bool DownloadParameters(byte[] parameterData, out uint sraCrc)

Downloads safety parameters. Callable only in the Parameter state (returns false when the current state is not Parameter); parameterData null or empty throws ArgumentException. The parameter contents are generated by the safety configuration tool.

Parameters:

  • parameterData (byte[]) — parameter data
  • sraCrc (out uint) — outputs the SRA CRC32 check value

Return value:

  • bool — true on success

SetFailsafeOutput(byte[] data) / SetFailsafeOutput<T>(T data)​

public bool SetFailsafeOutput(byte[] data)
public bool SetFailsafeOutput<T>(T data) where T : struct

Presets the output value used in failsafe. When FSoE enters the Failsafe state, the slave switches to this value automatically. data null or empty throws ArgumentException; the generic overload converts the struct according to its layout into a byte sequence and then calls the same-named method.

Return value:

  • bool — true on success

Example:

// all outputs off in failsafe
slave.FSoE.SetFailsafeOutput(new byte[] { 0x00 });

// or use a struct
var failsafe = new SafeDriveOutput();
failsafe.SafetyControlWord |= 0x0001; // request STO (safe torque off)
slave.FSoE.SetFailsafeOutput(failsafe);

Events​

Events are detected and raised automatically in every PDO cycle.

FSoE.StateChanged​

public event EventHandler<FSoEStateChangedEventArgs>? StateChanged;

FSoE safety connection state machine change event. Raised on every transition of the safety connection (Reset / Session / Connection / Parameter / Data / Failsafe); it is independent of the slave EtherCAT state (slave.Events.StateChanged) and the master EtherCAT state (master.Events.StateChanged).

Related structures:

public class FSoEStateChangedEventArgs
{
public ushort SlaveIndex { get; } // slave index
public int ConnectionIndex { get; } // connection index (distinguishes connections in MDP mode)
public FSoEState OldState { get; } // state before the change
public FSoEState NewState { get; } // state after the change
public DateTime Timestamp { get; } // timestamp
}

Example:

slave.FSoE.StateChanged += (sender, e) =>
{
Console.WriteLine($"FSoE 从站{e.SlaveIndex} 连接{e.ConnectionIndex}: " + // FSoE slave{e.SlaveIndex} connection{e.ConnectionIndex}:
$"{e.OldState} → {e.NewState}");
};

ErrorOccurred​

public event EventHandler<FSoEErrorEventArgs>? ErrorOccurred;

FSoE error event. Raised when a new error is detected; carries the error code and an automatically generated description in Chinese.

Related structures:

public class FSoEErrorEventArgs
{
public ushort SlaveIndex { get; } // slave index
public int ConnectionIndex { get; } // connection index
public FSoEError Error { get; } // error code
public string Description { get; } // error description (Chinese, generated automatically)
public FSoEState CurrentState { get; } // state at the time of the error
public DateTime Timestamp { get; } // timestamp
}

Example:

slave.FSoE.ErrorOccurred += (sender, e) =>
{
Console.WriteLine($"FSoE 错误: 从站{e.SlaveIndex}, " + // FSoE error: slave{e.SlaveIndex},
$"代码=0x{(int)e.Error:X4}, {e.Description}, " + // code=0x{(int)e.Error:X4}, {e.Description},
$"当前状态={e.CurrentState}"); // current state={e.CurrentState}

if (e.Error == FSoEError.CrcError)
slave.FSoE.ClearError();
};

FailsafeTriggered​

public event EventHandler<FSoEFailsafeEventArgs>? FailsafeTriggered;

Failsafe event. Raised when failsafe mode is entered or left.

Related structures:

public class FSoEFailsafeEventArgs
{
public ushort SlaveIndex { get; } // slave index
public int ConnectionIndex { get; } // connection index
public FSoEFailsafeReason Reason { get; } // trigger reason
public bool EnteringFailsafe { get; } // true = entering failsafe, false = returning to data exchange
public DateTime Timestamp { get; } // timestamp
}
public enum FSoEFailsafeReason
{
WatchdogTimeout, // watchdog timeout
CrcError, // CRC error
CommunicationError, // communication error
ApplicationRequest, // application request
SlaveRequest, // slave request
MasterRequest, // master request
RecoveryToData // recovery to data mode (leaving failsafe)
}

Example:

slave.FSoE.FailsafeTriggered += (sender, e) =>
{
if (e.EnteringFailsafe)
{
Console.WriteLine($"进入失效安全! 原因: {e.Reason}"); // Entering failsafe! Reason: {e.Reason}
// application-level safety handling: stop motion, cut off air supply, etc.
}
else
{
Console.WriteLine($"恢复数据交换"); // Resuming data exchange
}
};
SafeDataUpdated does not exist in the C# SDK

Older documentation listed a SafeDataUpdated safety data update event (argument type FSoEDataUpdatedEventArgs); the current C# SDK does not have these two members — subscribing does not compile, and there is no version that is "declared but never raised". To observe safety data updates use the DataExchanged event or the exchange callback passed at binding time.

Diagnostics​

ClearError()​

public void ClearError()

Clears the FSoE error. After clearing you can try to re-establish the connection.

CheckWatchdog()​

public bool CheckWatchdog()

Checks the FSoE watchdog state (single-connection mode).

Return value:

  • bool — true = watchdog healthy; false = expired or not initialized (an exception during the check also returns false)
Cycle handling

FSoE frames are handled automatically with the master PDO cycle; no manual call is required. To watch the result, use CheckWatchdog() and the state events.

GetTotalConnectionCount()​

public ushort GetTotalConnectionCount()

Gets the master-level total number of FSoE connections (the sum over all slaves). It reads the connection counter and sends no bus command; returns 0 when the read fails.

Return value:

  • ushort — number of connections

GetSlaveConnectionCount()​

public ushort GetSlaveConnectionCount()

Gets the number of FSoE connections registered for this slave (in MDP mode a slave may have several connections). It reads the registration counter and sends no bus command; for a measured probe use DetectConnections(); returns 0 when the read fails.

Return value:

  • ushort — number of slave connections

DetectConnections()​

public ushort DetectConnections()

Probes the actual number of FSoE connections on the slave. It probes module by module with SDO reads (real mailbox commands), scans the safety modules the slave supports and returns the number of connections detected; returns 0 when the read fails.

Return value:

  • ushort — number of connections detected

Example:

// check the watchdog
if (!slave.FSoE.CheckWatchdog())
Console.WriteLine("FSoE 看门狗超时!"); // FSoE watchdog timeout!

// get the connection counts
ushort totalConns = slave.FSoE.GetTotalConnectionCount();
ushort slaveConns = slave.FSoE.GetSlaveConnectionCount();
Console.WriteLine($"总连接: {totalConns}, 从站连接: {slaveConns}"); // Total connections: {totalConns}, slave connections: {slaveConns}

// detect connections automatically
ushort detected = slave.FSoE.DetectConnections();
Console.WriteLine($"检测到 {detected} 个 FSoE 连接"); // Detected {detected} FSoE connections

MDP multi-connection mode​

MDP devices (safety IO couplers, multi-axis drives and so on) contain several safety modules. Multi-connection mode creates an independent FSoE connection for each module; each connection has its own state machine, watchdog and safety data buffer.

Selection guide
  • Single connection (BindSafeIO) — simple devices, single-axis drives
  • Multiple connections (BindMdpSafeIO) — when modules need independent monitoring/recovery (for example a multi-axis drive with an independent safety connection per axis)

GetConnection(int index)​

public FSoEConnection? GetConnection(int index)

Gets the MDP connection at the given index. It can also be accessed through the indexer slave.FSoE[index].

Parameters:

  • index (int) — connection index (0-based)

Return value:

  • FSoEConnection? — connection instance; null when the index is invalid

FindConnectionByAddress(ushort safetyAddress)​

public FSoEConnection? FindConnectionByAddress(ushort safetyAddress)

Finds an MDP connection by safety address.

Parameters:

  • safetyAddress (ushort) — FSoE safety address

Return value:

  • FSoEConnection? — connection instance; null when not found

SafetyManager class​

The connection manager in MDP mode, accessed through slave.FSoE.Manager.

CategoryPropertyTypeRead/writeDescription
Connection managementConnectionCountintRead-onlyNumber of connections
ConnectionModeFSoEConnectionModeRead-onlyConnection mode
ConnectionsIReadOnlyList<FSoEConnection>Read-onlyList of all connections
PrimaryConnectionFSoEConnection?Read-onlyPrimary connection (index 0)

SafetyManager also exposes the three events StateChanged / ErrorOccurred / FailsafeTriggered (EventHandler<T>; the payload types are described in the Events section above). The same-named events on slave.FSoE forward these three, so subscribe in one place only — do not subscribe on both, or a single transition is delivered twice.

FSoEConnectionMode enum
public enum FSoEConnectionMode
{
Single, // single-connection mode - all modules share one FSoE connection and safety address
Multiple // multi-connection mode - each module has its own FSoE connection and safety address
}
SafeModuleProfile enum
public enum SafeModuleProfile : ushort
{
DigitalInput = 190, // FSoE digital input
DigitalInOut = 195, // FSoE digital input/output
DigitalOutput = 290, // FSoE digital output
DriveConnection = 790, // FSoE drive connection (CiA402)
Master = 6900 // FSoE master module
}

AllInDataState()​

public bool AllInDataState()

Checks whether all connections are in the data exchange state.

Return value:

  • bool — true when every connection is in the Data state

AnyInFailsafe()​

public bool AnyInFailsafe()

Checks whether any connection is in failsafe mode.

Return value:

  • bool — true when any connection is in the Failsafe state

EnterAllFailsafe()​

public bool EnterAllFailsafe()

Puts all connections into failsafe mode.

Return value:

  • bool — true on success

ResetAll()​

public bool ResetAll()

Resets all connections.

Return value:

  • bool — true on success

GetStatusSummary()​

public string GetStatusSummary()

Gets a status summary of all connections (for diagnostics).

Return value:

  • string — status summary text

FSoEConnection class​

A single FSoE connection instance in MDP mode. Each FSoEConnection has its own state machine, watchdog and safety data buffer.

Accessed through slave.FSoE[index], slave.FSoE.GetConnection(index) or slave.FSoE.Manager.Connections[index].

CategoryPropertyTypeRead/writeDescription
IdentityIndexintRead-onlyConnection index (0-based)
StateIsInitializedboolRead-onlyWhether the connection is initialized
IsConnected / StatusValidboolRead-onlyWhether a valid FSoE connection exists (the two are synonyms; IsConnected is the intuitive name for UI use); reading triggers one status refresh
StateFSoEStateRead-onlyCurrent FSoE state
InFailsafeboolRead-onlyWhether the connection is in failsafe mode
WatchdogExpiredboolRead-onlyWhether the watchdog has expired
LastErrorFSoEErrorRead-onlyLast error code
ConfigurationConfigFSoEConnectionConfig?Read-onlyConnection configuration
ModuleProfileSafeModuleProfileRead-onlyModule profile type
AxisNumberintRead-onlyAxis number (drive connections only)

RequestState / EnterFailsafe / Reset / ClearError / Close​

public bool RequestState(FSoEState targetState)
public bool EnterFailsafe()
public bool Reset()
public void ClearError()
public bool Close()

Connection-level state control and error handling. Each connection can be controlled independently.

DownloadParameters(byte[] parameterData, out uint sraCrc)​

public bool DownloadParameters(byte[] parameterData, out uint sraCrc)

Downloads the safety parameters of this connection (connection-level overload; same name as the slave-level DownloadParameters but a different scope).

SetFailsafeOutput(byte[] data)​

public bool SetFailsafeOutput(byte[] data)

Sets the failsafe output value of this connection.

Connection ID uniqueness check​

The FSoE protocol uses a Connection ID (ConnID) to identify each independent safety communication connection. ETG.5120 §5.2.3 requires that every ConnID be globally unique across the whole Master, and reserves 0 as an invalid value. Configuring a duplicate ConnID makes connection initialization fail, the slave handshake does not pass, and the connection ends up in Failsafe.

Typical use cases:

  • Configuration tool — validate before assigning a new ConnID, to avoid a clash with existing connections
  • Multi-slave / multi-connection setups — on an MDP device every module / every safety axis has its own ConnID, and each must be checked
  • Dynamic attach — when a new FSoE slave is hot-plugged at runtime, make sure the number does not collide before assigning

IsConnectionIdAvailable(ushort connectionId)​

// static method on the FSoEHelper static class
public static bool IsConnectionIdAvailable(ushort connectionId)

Checks whether a candidate ConnID is not yet used by another FSoE connection. The method is a member of the static class FSoEHelper (top level of the DarraEtherCAT_Master namespace, a peer of DarraEtherCAT; it is not a member of slave.FSoE).

Parameters:

  • connectionId (ushort) — candidate Connection ID (1..65535; 0 is invalid and returns false immediately)

Return value:

  • bool — true means available (not in use and not 0); false means already in use or 0

Example:

ushort myConnId = 0x1234;
if (!FSoEHelper.IsConnectionIdAvailable(myConnId))
{
Console.WriteLine($"ConnID 0x{myConnId:X4} 已被占用, 请选其他值"); // ConnID 0x{myConnId:X4} is already taken, pick another value
return;
}

// validation passed, now bind the safety IO
slave.FSoE.BindSafeIO<SafeDigitalInput, SafeDigitalOutput>(
safetyAddress: 0x0100,
connectionId: myConnId,
exchange: (ref SafeDigitalInput input, ref SafeDigitalOutput output) =>
{
output.OutputBits = input.InputBits;
});

Batch allocation example​

// scan from 1 and find the first available ConnID
ushort AllocateNextFreeConnId()
{
for (ushort candidate = 1; candidate != 0; candidate++)
{
if (FSoEHelper.IsConnectionIdAvailable(candidate))
return candidate;
}
throw new InvalidOperationException("ConnID 池已耗尽"); // (SDK output, = ConnID pool exhausted)
}

// allocate an independent ConnID for each of 3 safety modules
var id1 = AllocateNextFreeConnId();
var id2 = AllocateNextFreeConnId();
var id3 = AllocateNextFreeConnId();

Notes​

  • The method is static; it needs no slave instance and its scope is the whole Master
  • BindSafeIO(..., connectionId: 0) lets the SDK allocate the connection ID automatically; most setups need no explicit management
  • Manual ConnID allocation is needed only for custom safety network planning or in a configuration tool

Full example​

Digital safety IO​

using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDigitalInput
{
public byte InputBits; // safety input status bits (one bit per channel)
public byte DiagBits; // input diagnostic status
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDigitalOutput
{
public byte OutputBits; // safety output control bits
}

var slave = master.Slaves[0]; // safety IO slave
if (slave.FSoE == null)
{
Console.WriteLine("该从站不支持 FSoE"); // This slave does not support FSoE
return;
}

// one-line bind: infers the safety data size from the structs and starts the data exchange
bool bound = slave.FSoE.BindSafeIO<SafeDigitalInput, SafeDigitalOutput>(
safetyAddress: 0x0100,
watchdogMs: 100,
exchange: (ref SafeDigitalInput input, ref SafeDigitalOutput output) =>
{
output.OutputBits = (input.InputBits & 0x01) != 0 ? (byte)0x01 : (byte)0x00;
});
Console.WriteLine(bound ? "FSoE 绑定成功" : "FSoE 绑定失败,检查安全地址与结构体大小"); // FSoE binding succeeded / FSoE binding failed, check the safety address and struct size

// check the watchdog in the application cycle; after a timeout the protocol layer switches the outputs to safe values
if (!slave.FSoE.CheckWatchdog())
Console.WriteLine("FSoE 看门狗超时,输出已由协议层接管"); // FSoE watchdog timeout, the outputs have been taken over by the protocol layer

Safety drive​

var drive = master.Slaves[0];  // servo drive with FSoE

// one-line bind + exchange callback
drive.FSoE.BindSafeIO<SafeDriveInput, SafeDriveOutput>(
safetyAddress: 0x0100,
exchange: (ref SafeDriveInput driveIn, ref SafeDriveOutput driveOut) =>
{
if ((driveIn.SafetyStatusWord & 0x0100) != 0) // Bit8: safety fault
{
bool sto = (driveIn.SafetyStatusWord & 0x0001) != 0;
Console.WriteLine($"安全故障: STO={sto}, 位置={driveIn.SafeActualPosition}"); // Safety fault: STO={sto}, position={driveIn.SafeActualPosition}
driveOut.SafetyControlWord |= 0x0080; // acknowledge the fault
}
else
{
driveOut.SafetyControlWord &= unchecked((ushort)~0x0001); // clear the STO request
driveOut.SafetyControlWord &= unchecked((ushort)~0x0080); // clear the fault acknowledgement
}
});

drive.FSoE.FailsafeTriggered += (s, e) =>
{
if (e.EnteringFailsafe)
Console.WriteLine($"驱动器安全停止! 原因: {e.Reason}"); // Drive safe stop! Reason: {e.Reason}
};

Multi-connection IO (MDP mode)​

Each module has its own FSoE connection and can be monitored for status and errors independently. The PDO offsets are computed automatically from the DENI PDO configuration:

// safety data structure (exported in one step by the Darra configuration tool)
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDigitalInput // 2 bytes
{
public byte InputBits; // safety input status bits
public byte DiagBits; // input diagnostic status
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDigitalOutput // 1 byte
{
public byte OutputBits; // safety output control bits
}
var coupler = master.Slaves[0];  // safety IO coupler with 2 safety modules

// bind 2 independent connections + exchange callbacks (PDO offsets computed automatically)
coupler.FSoE.BindMdpSafeIO<SafeDigitalInput, SafeDigitalOutput>(
safetyAddress: 0x0100,
exchange: (ref SafeDigitalInput input, ref SafeDigitalOutput output) =>
{
output.OutputBits = input.InputBits;
});
coupler.FSoE.BindMdpSafeIO<SafeDigitalInput, SafeDigitalOutput>(
safetyAddress: 0x0200,
exchange: (ref SafeDigitalInput input, ref SafeDigitalOutput output) =>
{
output.OutputBits = input.InputBits;
});
// all connections start automatically on the first PDO cycle

// monitor each module's state independently
coupler.FSoE.StateChanged += (s, e) =>
Console.WriteLine($"模块{e.ConnectionIndex}: {e.OldState} → {e.NewState}"); // Module{e.ConnectionIndex}: {e.OldState} → {e.NewState}

Multi-axis safety drive (MDP mode)​

// safety data structure (exported in one step by the Darra configuration tool)
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDriveInput // 10 bytes (ETG.6100)
{
public ushort SafetyStatusWord; // safety status word
public int SafeActualPosition; // safe actual position
public int SafeActualVelocity; // safe actual velocity
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SafeDriveOutput // 2 bytes (ETG.6100)
{
public ushort SafetyControlWord; // safety control word
}
var drive = master.Slaves[0];  // two-axis servo drive, independent FSoE connection per axis

// bind 2 axes + exchange callbacks (PDO offsets computed automatically)
SafeDataExchangeHandler<SafeDriveInput, SafeDriveOutput> driveExchange =
(ref SafeDriveInput input, ref SafeDriveOutput output) =>
{
if ((input.SafetyStatusWord & 0x0100) != 0) // safety fault
output.SafetyControlWord |= 0x0080; // acknowledge the fault
else
output.SafetyControlWord &= unchecked((ushort)~0x0001); // clear STO
};

drive.FSoE.BindMdpDriveAxis<SafeDriveInput, SafeDriveOutput>(
axisNumber: 0, safetyAddress: 0x0100, exchange: driveExchange);
drive.FSoE.BindMdpDriveAxis<SafeDriveInput, SafeDriveOutput>(
axisNumber: 1, safetyAddress: 0x0200, exchange: driveExchange);
// started automatically on the first PDO cycle

// monitor each axis independently
drive.FSoE.FailsafeTriggered += (s, e) =>
Console.WriteLine($"轴{e.ConnectionIndex} 失效安全: {e.Reason}"); // Axis{e.ConnectionIndex} failsafe: {e.Reason}

Failures and handling​

SymptomCauseHandling
Binding returns false, or the data exchange state is not reached for a long timeThe safety address does not match the device DIP switch, or the struct size does not match the device definitionCheck safetyAddress against the DIP switch; verify the struct byte count with Marshal.SizeOf
The connection cannot be established (it stays in the session or connection stage)The connection ID is already used by another safety connectionUse an unused connectionId, or leave it 0 so the SDK allocates one
CheckWatchdog returns false and the outputs are switched to safe valuesThe watchdog timed out and the safety data exchange was interruptedFirst confirm that the PDO cycle is running and the slave has not dropped out of OP, then call Reset to start a new handshake
No automatic recovery after entering failsafeFailsafe was triggered and the fault source is still presentRemove the fault source and call Reset to re-establish the connection; if the device does not allow recovery, follow the safety procedure