EoE (Ethernet over EtherCAT)
The EoE protocol carries Ethernet communication over the EtherCAT bus. It supports configuring IP/MAC/DNS addresses and sending and receiving Ethernet frames, and follows ETG.1000.6 and ETG.1020.
Accessed through slave.EoE. It is null when the slave does not support EoE.
Properties
Read/write properties act immediately: the getter reads the current value from the device, and the setter validates the format and writes to the device straight away. When re-reading the paired fields or writing fails, EoEException is thrown.
| Category | Property | Type | Read/write | Description |
|---|---|---|---|---|
| Capability | IsSupported | bool | read-only | bool view of EoESupport == true: true only for "known to be supported", false when the conclusion is unknown |
| EoESupport | bool? | read-only | EoE capability tri-state: true = supported, false = mbx_proto was actually read and confirms it is not declared, null = unknown (read failed) | |
| IsSupportedKnown | bool | read-only | Whether the capability conclusion is known; false = unknown (not the same as unsupported) | |
| CanSendFrame | bool | read-only | Whether sending Ethernet frames is supported | |
| CanReceiveFrame | bool | read-only | Whether receiving Ethernet frames is supported | |
| CanSetIP | bool | read-only | Whether setting IP parameters is supported | |
| CanGetIP | bool | read-only | Whether reading IP parameters is supported | |
| Address | IP | IPAddress? | read/write | IP address (IPv4 only) |
| Subnet | IPAddress? | read/write | Subnet mask | |
| Gateway | IPAddress? | read/write | Default gateway | |
| MAC | string? | read/write | MAC address (format "AA:BB:CC:DD:EE:FF") | |
| DNS | DNS | IPAddress? | read/write | DNS server address |
| DNSName | string? | read/write | DNS name | |
| Frame options | TimeAppended | bool | read/write | Whether a timestamp is appended to sent frames (ETG.1000.6 §5.7), default false |
| TimeRequested | bool | read/write | Whether the slave is asked to append a timestamp to received frames (ETG.1000.6 §5.7), default false | |
| Filtering | InhibitBroadcast | bool | read/write | InhibitBroadcast flag sent with SetAddressFilters (ETG.1020), default false |
| Timeout | DefaultTimeoutMs | int (constant) | read-only | Default timeout constant for the frame send/receive and filter methods, 500 ms |
| Statistics | StatisticsReadFailed | bool | read-only | Whether the most recent mailbox statistics read failed; when it is true, Statistics / LastStatus / LastErrorCode hold degraded values and the numbers are not trustworthy |
EoESupport returns bool?: true = supported, false = SII mbx_proto was actually read and the bit is not set, null = it could not be read this time (the call failed). A read failure or exception is no longer folded into false; to tell "confirmed unsupported" from "unknown", check EoESupport / IsSupportedKnown.
Example:
using System.Net;
if (slave.EoE != null)
{
// Read
Console.WriteLine($"IP: {slave.EoE.IP}");
Console.WriteLine($"MAC: {slave.EoE.MAC}");
// Write
slave.EoE.IP = IPAddress.Parse("192.168.1.100");
slave.EoE.Subnet = IPAddress.Parse("255.255.255.0");
slave.EoE.Gateway = IPAddress.Parse("192.168.1.1");
slave.EoE.MAC = "AA:BB:CC:DD:EE:FF";
slave.EoE.DNS = IPAddress.Parse("8.8.8.8");
slave.EoE.DNSName = "dns.google";
}
StatisticsReadFailed
public bool StatisticsReadFailed { get; }
Whether the most recent mailbox statistics read failed. Statistics, LastStatus and LastErrorCode have a fixed return shape and still return degraded values when the read fails (empty snapshot / Pending / 0), so you must check this property to tell "really empty" from "not read this time".
This property only reflects whether the statistics read succeeded; it does not trigger a retry and does not mean later calls will keep failing. When it is true, both the statistics values and LastStatus / LastErrorCode are not trustworthy — treat the read as failed.
Example:
var stats = slave.EoE.Statistics;
if (slave.EoE.StatisticsReadFailed)
Console.WriteLine("统计读取失败,本次数值不可信"); // Statistics read failed, this reading is not trustworthy
else
Console.WriteLine($"累计发送: {stats.TotalSent}"); // Total sent: {stats.TotalSent}
Address filters (ETG.1020)
GetAddressFilters(byte[]? macFilterMask = null, int timeoutMs = DefaultTimeoutMs)
using System.Net.NetworkInformation;
public List<PhysicalAddress> GetAddressFilters(byte[]? macFilterMask = null, int timeoutMs = DefaultTimeoutMs)
Gets the MAC address filter list. macFilterMask is an optional MAC filter mask parameter (the current version does not send it to the slave; it is a placeholder). A failed read returns an empty list and writes a log entry; an empty list does not mean no filter is configured.
SetAddressFilters(IList<PhysicalAddress> filters, byte[]? macFilterMasks = null, int timeoutMs = DefaultTimeoutMs)
using System.Net.NetworkInformation;
public bool SetAddressFilters(IList<PhysicalAddress> filters, byte[]? macFilterMasks = null, int timeoutMs = DefaultTimeoutMs)
Sets the address filter list (at most 16 entries). macFilterMasks is an optional set of MAC filter masks (at most 3 masks of 6 bytes each; when omitted, exact matching is configured). The InhibitBroadcast flag comes from the InhibitBroadcast property.
AddAddressFilter / RemoveAddressFilter / ClearAddressFilters
using System.Net.NetworkInformation;
public bool AddAddressFilter(PhysicalAddress mac, int timeoutMs = DefaultTimeoutMs)
public bool RemoveAddressFilter(PhysicalAddress mac, int timeoutMs = DefaultTimeoutMs)
public bool ClearAddressFilters(int timeoutMs = DefaultTimeoutMs)
Example:
using System.Net.NetworkInformation;
var mac = PhysicalAddress.Parse("AA-BB-CC-DD-EE-FF");
slave.EoE.AddAddressFilter(mac);
var filters = slave.EoE.GetAddressFilters();
foreach (var f in filters)
Console.WriteLine($"过滤器: {f}"); // Filter: {f}
slave.EoE.ClearAddressFilters();
Sending and receiving Ethernet frames
EoEInstance.BuildEthernetFrame(byte[] destMac, byte[] sourceMac, ushort etherType, byte[] payload)
public static byte[] BuildEthernetFrame(byte[] destMac, byte[] sourceMac, ushort etherType, byte[] payload)
Builds an Ethernet II frame: destination MAC (6 bytes) + source MAC (6 bytes) + EtherType (big-endian, 2 bytes) + payload. Use it to build a complete frame before SendFrame, so the caller does not have to assemble the frame header.
Parameters:
destMac(byte[]) — destination MAC; must be 6 bytes, otherwiseArgumentExceptionis thrownsourceMac(byte[]) — source MAC; must be 6 bytes, otherwiseArgumentExceptionis thrownetherType(ushort) — EtherType, for example0x0800for IPv4payload(byte[]) — frame payload;nullis treated as 0 bytes
Return value:
byte[]— complete frame data (14-byte header + payload)
Example:
byte[] frame = DarraEtherCAT.Slave.EoEInstance.BuildEthernetFrame(
destMac: new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
sourceMac: new byte[] { 0x02, 0x00, 0x00, 0x00, 0x00, 0x01 },
etherType: 0x0800,
payload: BitConverter.GetBytes(0x12345678));
slave.EoE.SendFrame(frame);
SendFrame(byte[] frame, int timeoutMs = DefaultTimeoutMs)
public bool SendFrame(byte[] frame, int timeoutMs = DefaultTimeoutMs)
public bool SendFrame(byte[] frame, byte port, int timeoutMs = DefaultTimeoutMs)
Sends an Ethernet frame.
ReceiveFrame(int timeoutMs = DefaultTimeoutMs)
public byte[]? ReceiveFrame(int timeoutMs = DefaultTimeoutMs)
public byte[]? ReceiveFrame(byte port, int timeoutMs = DefaultTimeoutMs)
Receives an Ethernet frame.
Return value:
byte[]?— received frame data;nullon failure
SendFrameWithTimestamp(byte[] frame, ulong timestamp, int timeoutMs = DefaultTimeoutMs)
public bool SendFrameWithTimestamp(byte[] frame, ulong timestamp, int timeoutMs = DefaultTimeoutMs)
Sends an Ethernet frame with a DC timestamp appended per ETG.1000.6. Fragmentation is handled by the SDK, so a whole frame may be larger than the slave mailbox.
Parameters:
frame(byte[]) — Ethernet frame datatimestamp(ulong) — timestamp to append (DC time, nanoseconds)timeoutMs(int) — timeout in milliseconds
Return value:
bool—trueon success
Ping test
Ping(IPAddress targetIp, int timeoutMs = 5000, byte ttl = 64)
using System.Net;
public EoEPingResult Ping(IPAddress targetIp, int timeoutMs = 5000, byte ttl = 64)
Sends an ICMP Ping over EoE and waits for the reply.
Parameters:
targetIp(IPAddress) — target IP addresstimeoutMs(int) — timeout in millisecondsttl(byte) — time to live
Related structures:
public class EoEPingResult
{
public bool Success { get; set; } // success
public double RoundTripTimeMs { get; set; } // round-trip time in milliseconds
public string TargetAddress { get; set; } // target address
public byte TTL { get; set; } // time to live
public string ErrorMessage { get; set; } // error message
}
Example:
using System.Net;
var result = slave.EoE.Ping(IPAddress.Parse("192.168.1.1"));
Console.WriteLine(result.ToString());
Frame receive events
FrameReceived
public event EventHandler<EoEFrameEventArgs>? FrameReceived;
Raised when an Ethernet frame pushed by the slave arrives. Once subscribed, the SDK receives frames automatically; the callback does not run on the UI thread, so subscribers should copy the data into a queue quickly to avoid blocking.
Related structures:
public class EoEFrameEventArgs : EventArgs
{
public ushort MasterIndex { get; } // master index
public ushort SlaveIndex { get; } // source slave index
public byte[] Frame { get; } // complete Ethernet frame data
public DateTime ReceivedAt { get; } // receive timestamp (UTC)
}
Companion methods: UnregisterFrameReceiveHook() stops the subscription of this instance (other slaves are unaffected); ClearMasterFrameReceiveHook() clears the receive hook of the whole master and is usually called before the master is disposed.
Full example
Network configuration and ping
using System.Net;
if (slave.EoE != null)
{
Console.WriteLine($"当前 IP: {slave.EoE.IP}"); // Current IP: {slave.EoE.IP}
Console.WriteLine($"当前 MAC: {slave.EoE.MAC}"); // Current MAC: {slave.EoE.MAC}
slave.EoE.IP = IPAddress.Parse("10.0.0.100");
slave.EoE.Subnet = IPAddress.Parse("255.255.255.0");
slave.EoE.Gateway = IPAddress.Parse("10.0.0.1");
slave.EoE.DNS = IPAddress.Parse("10.0.0.1");
var ping = slave.EoE.Ping(IPAddress.Parse("10.0.0.1"));
if (ping.Success)
Console.WriteLine($"Ping 成功: {ping.RoundTripTimeMs:F1}ms"); // Ping succeeded: {ping.RoundTripTimeMs:F1}ms
}
ARP cache management
SetArpEntry(IPAddress ip, byte[] mac)
using System.Net;
public void SetArpEntry(IPAddress ip, byte[] mac)
Binds an IP address to a MAC address in the SDK's local ARP cache (the next-hop MAC is specified manually and is used to address Ping frames).
Parameters:
ip(IPAddress) — IP addressmac(byte[]) — MAC address (6 bytes)
ClearArpCache()
public void ClearArpCache()
Clears the SDK's local ARP cache (the cache on the slave side is not cleared).
ArpCacheTtl / ExpireArpCache()
public static TimeSpan ArpCacheTtl { get; set; } // local ARP cache lifetime, default 5 minutes
public void ExpireArpCache() // removes entries older than ArpCacheTtl
The first Ping is sent as a broadcast; after the Echo Reply arrives the source MAC is recorded, and later traffic to the same IP is unicast. Entries expire automatically once they are older than ArpCacheTtl.
Example:
using System.Net;
if (slave.EoE != null)
{
// Add a static ARP entry
var ip = IPAddress.Parse("192.168.1.1");
byte[] mac = new byte[] { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
slave.EoE.SetArpEntry(ip, mac);
// Clear the ARP cache
slave.EoE.ClearArpCache();
}
Asynchronous methods
Every synchronous method has an Async counterpart with the Async suffix that takes an extra CancellationToken cancellationToken = default: SendFrameAsync / ReceiveFrameAsync / SendFrameWithTimestampAsync / PingAsync / GetAddressFiltersAsync / SetAddressFiltersAsync, and so on.
AddAddressFilterAsync(PhysicalAddress mac, int timeoutMs = DefaultTimeoutMs, CancellationToken cancellationToken = default)
public Task<bool> AddAddressFilterAsync(PhysicalAddress mac, int timeoutMs = DefaultTimeoutMs, CancellationToken cancellationToken = default)
Adds a single MAC address filter asynchronously. Internally it first reads the current filter list: when the 16-entry limit is already reached it returns false directly (nothing is written to the slave); otherwise it writes "the existing list plus this MAC" back to the slave as a whole.
Parameters:
mac(PhysicalAddress) — the MAC address to addtimeoutMs(int) — timeout for each read and write in milliseconds; defaults toDefaultTimeoutMscancellationToken(CancellationToken) — cancellation token
Return value:
Task<bool>—truewhen the write-back succeeds;falsewhen the limit is reached, a state transition fails, or the write fails
If reading the existing list fails, it is treated as an empty list, so after the write-back only the MAC added by this call remains on the slave.
Example:
using System.Net.NetworkInformation;
var mac = PhysicalAddress.Parse("AA-BB-CC-DD-EE-FF");
if (!await slave.EoE.AddAddressFilterAsync(mac, cancellationToken: ct))
Console.WriteLine("添加过滤器失败"); // Failed to add filter
RemoveAddressFilterAsync(PhysicalAddress mac, int timeoutMs = DefaultTimeoutMs, CancellationToken cancellationToken = default)
public Task<bool> RemoveAddressFilterAsync(PhysicalAddress mac, int timeoutMs = DefaultTimeoutMs, CancellationToken cancellationToken = default)
Removes a single MAC address filter asynchronously: read the current list → remove that MAC → write the whole list back to the slave. When the target MAC is not in the list, no error is raised; the existing list is still written back and the write-back result is returned.
Parameters:
mac(PhysicalAddress) — the MAC address to removetimeoutMs(int) — timeout for each read and write in milliseconds; defaults toDefaultTimeoutMscancellationToken(CancellationToken) — cancellation token
Return value:
Task<bool>—truewhen the write-back succeeds;falsewhen a state transition fails or the write fails
If reading the existing list fails, it is treated as an empty list, so the write-back clears all filters currently on the slave.
Example:
using System.Net.NetworkInformation;
var mac = PhysicalAddress.Parse("AA-BB-CC-DD-EE-FF");
await slave.EoE.RemoveAddressFilterAsync(mac, cancellationToken: ct);
ClearAddressFiltersAsync(int timeoutMs = DefaultTimeoutMs, CancellationToken cancellationToken = default)
public Task<bool> ClearAddressFiltersAsync(int timeoutMs = DefaultTimeoutMs, CancellationToken cancellationToken = default)
Clears all MAC address filters asynchronously by sending 0 filters to the slave.
Parameters:
timeoutMs(int) — write timeout in milliseconds; defaults toDefaultTimeoutMscancellationToken(CancellationToken) — cancellation token
Return value:
Task<bool>—trueon success;falsewhen a state transition fails or the write fails
Example:
await slave.EoE.ClearAddressFiltersAsync(cancellationToken: ct);
Related structures
EoEException
Thrown when a property setter fails to write or when the paired fields cannot be read back.
public class EoEException : Exception
{
public EoEException(string message);
public EoEException(string message, Exception innerException);
}
EoEAddressFilterConfig
Aggregate structure for address filter configuration:
using System.Net.NetworkInformation;
public class EoEAddressFilterConfig
{
public List<PhysicalAddress> Filters { get; set; } // list of MAC filters
public byte[]? MacFilterMask { get; set; } // MAC filter mask
public bool InhibitBroadcast { get; set; } // whether broadcast is inhibited
}