Skip to main content

EoE (Ethernet over EtherCAT)

The EoE protocol carries Ethernet communication over the EtherCAT bus. It supports IP/MAC/DNS address configuration and Ethernet frame transmission and reception, and conforms to the ETG.1000.6 and ETG.1020 standards.

Get an EoEInstance through slave.eoe() — the method returns the EoEInstance directly (not an Option); use eoe.eoe_support() to determine whether EoE is really supported.

Protocol capability detection​

pub fn eoe_support(&self) -> Option<bool>
pub fn is_support_known(&self) -> bool
pub fn is_supported(&self) -> bool

Authority chain: bit0 of the low-level EoE details query (positive) → when the low-level SII general information is really read, eoe_details bit0 is the authoritative verdict (a false verdict is safe there) → mbx_proto bit1 (0x02) is positive evidence only (the ESI fast path hard-codes the protocol bits to CoE).

  • Some(true) — supported
  • Some(false) — SII was really read and confirms it is not declared
  • None — unknown (there is no authoritative reading and the protocol bits give no positive evidence either)

is_supported() is the bool view: true only for Some(true); unknown is folded into false, so use is_support_known() or eoe_support() when you need to tell them apart.

Mailbox protocol common interface (MailboxProtocol)​

MailboxProtocol is the common interface shared by the mailbox protocol instances (protocol identification, capability verdict, per-protocol mailbox statistics).

use darra_ethercat::abstractions::MailboxProtocol;
MethodReturnsDescription
protocol_type()u8Mailbox protocol type code, EoE = 0x02
protocol_name()&'static strProtocol name, always "EoE"
let proto = eoe.protocol_type();   // 0x02
let name = eoe.protocol_name(); // "EoE"

Both return constants: they start no mailbox transaction and cannot fail; protocol_type() is also the protocol key used when querying mailbox statistics / state per protocol. The same trait also provides is_supported() (see "Protocol capability detection" above) and the per-protocol mailbox statistics methods.

Honest boundaries​

EoE in this SDK is an Ethernet frame tunnel over the EtherCAT mailbox; it is not an operating-system network adapter.

  • No TAP / tun: it creates no Windows TAP or Linux tun/tap device
  • No DHCP server / NAT: it assigns no addresses and performs no routing or NAT
  • No automatic fragmentation at MTU 1500: the lower layer splits frames into 32-byte blocks according to the slave mailbox (mbx.length - 10); the whole-frame limit is the ETG.1000.6 §5.7 Frame Offset (6 bit × 32 B) = 2016 bytes. Anything over 2016 bytes makes the wrapper return InvalidParameter
  • Receive buffer: receive_frame copies according to the frame_size returned by the lower layer, whose maximum is likewise bounded by 2016 — it is not an arbitrary size

IP / MAC / DNS configuration​

Every getter / setter is a mailbox transaction, so all of them take a timeout_ms parameter and return Result. IP parameters use u32 (network byte order); MAC uses [u8; 6].

MethodTypeCategoryRead/writeDescription
ip(timeout_ms)Result<u32>Network configurationread-onlyIP address (u32, network byte order)
subnet(timeout_ms)Result<u32>Network configurationread-onlySubnet mask
gateway(timeout_ms)Result<u32>Network configurationread-onlyDefault gateway
set_ip(ip, subnet, gateway, timeout_ms)Result<()>Network configurationwrite-onlyWrites IP/subnet/gateway in one call
mac(timeout_ms)Result<[u8; 6]>Network configurationread-onlyMAC address (6 bytes)
mac_string(timeout_ms)Result<String>Network configurationread-onlyMAC address ("AA:BB:CC:DD:EE:FF" format)
set_mac(&mac, timeout_ms)Result<()>Network configurationwrite-onlyWrites the MAC address
dns(timeout_ms)Result<u32>Network configurationread-onlyDNS server address
set_dns(dns_ip, dns_name, timeout_ms)Result<()>Network configurationwrite-onlyWrites the DNS server IP + name

Example:

let eoe = slave.eoe();
if eoe.eoe_support() != Some(true) {
println!("从站未确认支持 EoE(未知或 SII 确认未声明)"); // Slave support for EoE is not confirmed (unknown, or not declared in the SII confirmation)
return Ok(());
}

// Read (returns Result; a timeout is required)
println!("IP: 0x{:08X}", eoe.ip(5000)?);
println!("MAC: {}", eoe.mac_string(5000)?);

// Write: set_ip writes IP/subnet/gateway in one call (u32, network byte order)
let ip = u32::from_be_bytes([192, 168, 1, 100]);
let subnet = u32::from_be_bytes([255, 255, 255, 0]);
let gateway = u32::from_be_bytes([192, 168, 1, 1]);
eoe.set_ip(ip, subnet, gateway, 5000)?;

eoe.set_mac(&[0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF], 5000)?;
eoe.set_dns(u32::from_be_bytes([8, 8, 8, 8]), "dns.google", 5000)?;

Address filters (ETG.1020)​

get_address_filters()​

pub fn get_address_filters(&self, timeout_ms: i32) -> Result<Vec<[u8; 6]>>

Gets the list of MAC address filters currently configured on the slave (at most 16 entries), each represented as [u8; 6].

set_address_filters_batch()​

pub fn set_address_filters_batch(&self, filters: &[[u8; 6]], timeout_ms: i32) -> Result<()>

Replaces all MAC address filters on the slave in one call.

Example:

// Replace with filters that allow only two hosts
eoe.set_address_filters_batch(&[
[0x00, 0x1B, 0x21, 0xAA, 0xBB, 0xCC],
[0x00, 0x1B, 0x21, 0xDD, 0xEE, 0xFF],
], 5000)?;

let filters = eoe.get_address_filters(5000)?;
for f in &filters {
println!("过滤器: {:02X?}", f); // Filter: {:02X?}
}

Ethernet frame transmission and reception​

send_frame()​

pub fn send_frame(&self, frame: &[u8], timeout_ms: i32) -> Result<()>

Sends an Ethernet frame (the port number is specified when the EoEInstance is created). Fragmentation is done by the lower layer (ETG.1000.6 §5.7). A whole frame may be larger than the slave mailbox; it is rejected only when it exceeds the Frame Offset limit (2016 bytes). There is no TAP/DHCP/NAT and no automatic fragmentation at MTU 1500.

Parameters:

  • frame (&[u8]) — Ethernet frame data
  • timeout_ms (i32) — timeout in milliseconds

Returns:

  • Result<()> — success or error

receive_frame()​

pub fn receive_frame(&self, timeout_ms: i32) -> Result<Vec<u8>>

Receives an Ethernet frame.

Parameters:

  • timeout_ms (i32) — timeout in milliseconds

Returns:

  • Result<Vec<u8>> — the received frame data

Example:

// Send a frame
let frame = vec![0xFF; 64]; // sample frame data
eoe.send_frame(&frame, 5000)?;

// Receive a frame
let data = eoe.receive_frame(5000)?;
println!("收到帧: {} 字节", data.len()); // Frame received: {} bytes

Ping test​

pub fn ping(&self, target_ip: u32, timeout_ms: i32) -> EoEPingResult

Sends an ICMP Ping through EoE and waits for the response. The method does not return a Result; failure information is carried in EoEPingResult.

Parameters:

  • target_ip (u32) — target IP address (network byte order, for example 192.168.1.1 = 0xC0A80101)
  • timeout_ms (i32) — timeout in milliseconds
pub struct EoEPingResult {
pub success: bool, // whether it succeeded
pub round_trip_time_ms: f64, // round-trip time (milliseconds)
pub target_address: String, // target address
pub ttl: u8, // time to live
pub error_message: String, // error message
}

Example:

let target = u32::from_be_bytes([192, 168, 1, 1]);
let result = eoe.ping(target, 5000);
if result.success {
println!("Ping 成功: {:.1}ms", result.round_trip_time_ms); // Ping succeeded: {:.1}ms
} else {
println!("Ping 失败: {}", result.error_message); // Ping failed: {}
}

Local ARP cache​

EoEInstance keeps a built-in local ARP cache (it learns IP↔MAC from the received frames) and never writes it to the slave. The lower layer offers no interface for setting ARP entries on the slave, so the SDK provides no method for it.

clear_arp_cache()​

pub fn clear_arp_cache(&mut self)

Clears the local ARP cache (recreates an empty cache). Note that it requires a &mut receiver.

Complete example​

Network configuration and Ping​

let eoe = slave.eoe();
if eoe.eoe_support() != Some(true) {
return Ok(());
}

println!("当前 IP: 0x{:08X}", eoe.ip(5000)?); // Current IP: 0x{:08X}
println!("当前 MAC: {}", eoe.mac_string(5000)?); // Current MAC: {}

let ip = u32::from_be_bytes([10, 0, 0, 100]);
let subnet = u32::from_be_bytes([255, 255, 255, 0]);
let gateway = u32::from_be_bytes([10, 0, 0, 1]);
eoe.set_ip(ip, subnet, gateway, 5000)?;
eoe.set_dns(gateway, "", 5000)?;

let ping = eoe.ping(gateway, 5000);
if ping.success {
println!("Ping 成功: {:.1}ms", ping.round_trip_time_ms); // Ping succeeded: {:.1}ms
}

Ethernet frame transmission and reception​

let eoe = slave.eoe();
if eoe.eoe_support() != Some(true) {
return Ok(());
}

// send_frame / receive_frame return Result
let frame = vec![0xFF; 64];
eoe.send_frame(&frame, 5000)?;

let data = eoe.receive_frame(5000)?;
println!("收到帧: {} 字节", data.len()); // Frame received: {} bytes

Asynchronous receive hook (frame_received)​

The SDK forwards frames pushed by the lower layer to a user closure asynchronously. Multiple frames may arrive concurrently; per master only the most recently registered callback is kept.

set_receive_hook​

pub fn set_receive_hook<F>(&self, callback: F) -> Result<()>
where
F: Fn(u16, u16, &[u8]) + Send + Sync + 'static

Registers a receive callback; the closure parameters are (master_index, slave_index, &frame_bytes). Calling it several times on the same master_index overwrites the previous closure (only the most recently registered closure is kept per master). When the lower layer offers no receive hook registration interface, it returns DarraError::Other instead of panicking.

clear_receive_hook​

pub fn clear_receive_hook(&self) -> Result<()>

Unregisters the receive callback of this master and tells the runtime to unbind the receive hook.

Example:

use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;

let frame_count = Arc::new(AtomicU64::new(0));
let counter = Arc::clone(&frame_count);

eoe.set_receive_hook(move |master, slave, frame| {
counter.fetch_add(1, Ordering::Relaxed);
println!("[Master {} Slave {}] 收到 {} 字节", master, slave, frame.len()); // [Master {} Slave {}] received {} bytes
})?;

// ... application logic ...

eoe.clear_receive_hook()?;
println!("总共收到 {} 帧", frame_count.load(Ordering::Relaxed)); // {} frames received in total
The closure must be Send + Sync + 'static

The callback runs on a lower-layer thread; data referenced inside the closure must be shared through synchronization primitives such as Arc<Mutex<_>> / AtomicXxx; do not capture stack references.

Address filters​

CategoryMethodRead/writeDescription
Address filterget_address_filters(timeout_ms)read-onlyReads the MAC filter list currently configured on the slave (at most 16 entries)
set_address_filters_batch(&filters, timeout_ms)write-onlyReplaces all filters in one call
clear_arp_cache()write-onlyClears the local ARP cache (recreates an empty cache)
// Replace with filters that allow only two hosts
eoe.set_address_filters_batch(&[
[0x00, 0x1B, 0x21, 0xAA, 0xBB, 0xCC],
[0x00, 0x1B, 0x21, 0xDD, 0xEE, 0xFF],
], 1000)?;

let filters = eoe.get_address_filters(1000)?;
println!("当前过滤器数: {}", filters.len()); // Current filter count: {}

Sending frames with a timestamp​

send_frame_with_timestamp​

pub fn send_frame_with_timestamp(&self, frame: &[u8], timestamp: u64, timeout_ms: i32) -> Result<()>

ETG.1000.6 §5.7 TimeAppended: appends a 4-byte (Unsigned32) timestamp at the end of the frame, taking the low 32 bits of timestamp (DC time in nanoseconds).

let dc_ns = master.master_dc_time();
eoe.send_frame_with_timestamp(&frame, dc_ns, 1000)?;
Setting ARP table entries is not supported

The lower layer offers no interface for setting ARP entries on the slave, and the Rust SDK provides no method for it. Local ARP learning and resolution are done by the local ARP cache built into EoEInstance and are never written to the slave.