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.
Use the return value of GetSlaveEoEDetails(master_index, slave) to determine whether a slave supports EoE (a value other than 0 means supported).
To distinguish supported / not supported / unknown, use the tri-state query ec_slave_get_proto_support_state(master, slave, MBXPROT_EOE). For EoE, SII General eoe_details bit0 can give an authoritative negative answer (NO); when it cannot be read, report UNKNOWN.
The public EoE interfaces are eoe_send_frame_with_timestamp, eoe_set_receive_hook / eoe_clear_receive_hook, eoe_ping, and the ARP cache functions (no handle, no function-pointer table).
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: frames are split into 32-byte blocks according to the slave mailbox capacity; the whole-frame limit is the ETG.1000.6 §5.7 Frame Offset (6 bit × 32 B) = 2016 bytes. The caller must ensure the whole frame does not exceed 2016 bytes; the wrapper in
eoe_send_frame_with_timestamphas a separate 1500-byte limit
Network parameter configuration
EoE parameters such as IP / MAC / DNS and address filters are configured according to ETG.1000.6 and the device manual. The public SDK interfaces focus on frame transmission and reception, Ping / ARP, and the receive hook; the exact entry points for parameter configuration are defined by the public headers shipped with the package.
Sending with a timestamp (slave/eoe.h)
eoe_send_frame_with_timestamp()
BOOL eoe_send_frame_with_timestamp(uint16_t master_index, uint16_t slave, uint8_t port,
const uint8_t* data, int size,
uint32_t timestamp, int timeout);
Sends an Ethernet frame together with an application-layer timestamp (normally referenced to the DC clock).
The function attaches the timestamp inside the EoE frame, which suits scenarios that need precise synchronization of the "send instant", such as PTP gateways, industrial camera triggering, and time-stamped logs across multiple slaves.
Parameters:
master_index(uint16_t) — master indexslave(uint16_t) — slave indexport(uint8_t) — port number (normally 0)data(const uint8_t*) — frame datasize(int) — frame size (this wrapper is limited to 1500 bytes; anything larger returnsFALSEimmediately)timestamp(uint32_t) — timestamp (32-bit, taken from the low 32 bits of the DC clock)timeout(int) — timeout (microseconds)
Return value:
BOOL—TRUEon success
Example:
#include "slave/eoe.h"
uint32_t now = (uint32_t)get_master_dc_time(master);
eoe_send_frame_with_timestamp(master, 1, 0, frame, sizeof(frame),
now, 5000000);
The timestamp is consumed only when the slave's EoE stack implements ETG.1000.6 EoE extension-header parsing; an ordinary slave handles the frame as a standard frame and silently discards the timestamp.
Ping test (ethercat_advanced.h)
eoe_ping()
ping_result_t eoe_ping(uint16_t master, uint16_t slave,
uint8_t port, uint32_t target_ip, int timeout_ms);
Sends an ICMP Ping over EoE and waits for the response.
Parameters:
target_ip(uint32_t) — target IP addresstimeout_ms(int) — timeout in milliseconds
Return value:
ping_result_t— Ping result
Related structures:
typedef struct {
BOOL success; /* whether it succeeded */
uint32_t rtt_us; /* round-trip time (microseconds) */
uint8_t ttl; /* TTL */
} ping_result_t;
ARP cache management (ethercat_advanced.h)
eoe_arp_set()
void eoe_arp_set(uint32_t ip, const uint8_t mac[6]);
Sets an ARP cache entry.
eoe_arp_clear()
void eoe_arp_clear(void);
Clears all ARP cache entries.
eoe_arp_lookup()
BOOL eoe_arp_lookup(uint32_t ip, uint8_t mac[6]);
Looks up an ARP cache entry.
Return value:
BOOL—TRUEwhen found
EoE asynchronous receive hook
After eoe_set_receive_hook registers a receive hook, the PDO main-loop thread calls the user function directly when an EoE Fragment Data frame arrives, with no polling.
typedef void (*eoe_frame_cb_t)(uint16_t master_index,
uint16_t slave,
const uint8_t* frame_data,
int frame_size);
BOOL eoe_set_receive_hook (uint16_t master_index, eoe_frame_cb_t cb);
BOOL eoe_clear_receive_hook(uint16_t master_index);
eoe_set_receive_hook — registers a callback shared across the whole master; it fires once for every EoE Fragment Data frame (from any slave), and the caller dispatches on master_index / slave. The callback signature is fixed at 4 parameters (no port / user_data argument); to pass context, use a global or static variable.
- The callback runs synchronously inside the PDO main-loop thread; copy
frame_dataimmediately and return. Do not block (Sleep / file IO / waiting for a lock), otherwise the whole bus is held up frame_datapoints to a buffer owned by the SDK that is released as soon as the callback returns; do not access it outside the callback- Only one hook can be registered per master at a time; setting it again replaces the previous one
- Returns
FALSEwhen not ready; the application should check the return value and retry
Example:
typedef struct { volatile int got_frame; uint8_t buf[2016]; int len; } ctx_t;
/* the callback has no user_data argument; pass context through a global or static variable */
static ctx_t g_ctx = {0};
static void on_eoe_recv(uint16_t master_index, uint16_t slave,
const uint8_t* data, int size) {
if (size >= 0 && (size_t)size <= sizeof(g_ctx.buf)) {
memcpy(g_ctx.buf, data, (size_t)size);
g_ctx.len = size;
g_ctx.got_frame = 1; /* wake the application thread */
}
}
eoe_set_receive_hook(master, on_eoe_recv);
/* application thread */
while (running) {
if (g_ctx.got_frame) {
process_frame(g_ctx.buf, g_ctx.len);
g_ctx.got_frame = 0;
} else {
Sleep(1);
}
}
eoe_clear_receive_hook(master);
Full example
#include "ethercat.h"
#include "ethercat_advanced.h"
#include <stdio.h>
int main(void)
{
uint16_t master = Initialize();
SetNetwork(master, "\\Device\\NPF_{...}", "");
SetStateSequence(master, EC_STATE_PRE_OP, 5000);
uint16_t slave = 1;
/* Ping test */
ping_result_t ping = eoe_ping(master, slave, 0, 0xC0A80101, 5000);
if (ping.success) {
printf("Ping 成功: RTT=%u us, TTL=%d\n", ping.rtt_us, ping.ttl); /* Ping succeeded: RTT=%u us, TTL=%d */
}
/* send with a timestamp */
uint8_t frame[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* destination MAC */
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* source MAC */
0x08, 0x00}; /* EtherType: IP */
uint32_t now = (uint32_t)get_master_dc_time(master);
eoe_send_frame_with_timestamp(master, slave, 0, frame, sizeof(frame), now, 5000000);
Dispose(master);
return 0;
}
EoE dx_* interface
The 12 dx_eoe_* functions in slave/eoe.h are the entry points for whole-frame EoE transmission and network parameter configuration: IP / mask / gateway, MAC, DNS, full parameters, and MAC address filtering. All are inline wrappers in the header, addressed uniformly by master_index + slave + port (the slave's EoE port number).
| Category | Function | Return type | Read/write | Description |
|---|---|---|---|---|
| Frame transmission | dx_eoe_send_frame | BOOL | write-only | Sends one complete Ethernet frame; size is the full frame length, capped at 2016 bytes (ETG.1000.6 §5.7); the wrapper above rejects larger frames |
| dx_eoe_receive_frame | BOOL | read-only | Receives one complete Ethernet frame; *data is allocated by the runtime and its length is in *size; it must be released with FreeMemory() — it is not a caller-supplied buffer of arbitrary size | |
| IP | dx_eoe_set_ip | BOOL | write-only | Sets ip / mask / gateway, all uint32_t |
| dx_eoe_get_ip | BOOL | read-only | Reads back the three output parameters ip / mask / gateway | |
| MAC | dx_eoe_set_mac | BOOL | write-only | Sets the MAC; mac points to a 6-byte address |
| dx_eoe_get_mac | BOOL | read-only | Reads the MAC into a 6-byte buffer | |
| DNS | dx_eoe_set_dns | BOOL | write-only | Sets the DNS server address dns_ip and name dns_name |
| dx_eoe_get_dns | BOOL | read-only | Reads back dns_ip and dns_name; the name buffer is provided by the caller (this entry point has no length parameter) | |
| Full parameters | dx_eoe_get_full_param | BOOL | read-only | Reads back IP + mask + gateway + MAC + DNS (address and name) in one call |
| dx_eoe_set_full_param | BOOL | write-only | Writes IP + mask + gateway + MAC + DNS in one call | |
| Address filtering | dx_eoe_set_address_filter | BOOL | write-only | Sets filter_count MAC filters; mac_filters points to a contiguous array of those MAC addresses |
| dx_eoe_get_address_filter | BOOL | read-only | Reads back filter_count and writes the filters into mac_filters, at most max_filters entries |
Frame length and ownership notes
- Whole-frame limit of 2016 bytes: from the Frame Offset in ETG.1000.6 §5.7 (6 bits × 32 B). This layer does not fragment to an MTU of 1500; fragmentation is done by the send path in
mbx.length - 10/ 32 B blocks. - The receive buffer is allocated by the runtime: the length of
*datafromdx_eoe_receive_frameis given by*size; the caller only releases it withFreeMemory()and must not pass in a buffer of its own. - Not a NIC: the header states explicitly that this layer provides no TAP / tun, no DHCP server and no NAT; address assignment and routing are the responsibility of the peer device and of the user.
- Every entry point's
timeoutis the timeout for that request.
Example
#include "ethercat.h"
#include <stdio.h>
int main(void)
{
uint16_t master = Initialize();
SetNetwork(master, "\\Device\\NPF_{...}", "");
SetStateSequence(master, EC_STATE_PRE_OP, 5000);
/* Configure IP / mask / gateway*/
dx_eoe_set_ip(master, 1, 0, 0xC0A8010A, 0xFFFFFF00, 0xC0A80101, 5000);
uint32_t ip = 0, mask = 0, gw = 0;
if (dx_eoe_get_ip(master, 1, 0, &ip, &mask, &gw, 5000)) {
printf("ip=0x%08X mask=0x%08X gw=0x%08X\n", ip, mask, gw);
}
/* Send one complete Ethernet frame (total frame length up to 2016 bytes)*/
uint8_t frame[60] = {0};
if (!dx_eoe_send_frame(master, 1, 0, frame, sizeof(frame), 5000)) {
printf("发送失败\n"); /* Send failed */
}
/* Receive frame: *data is allocated by the runtime, call FreeMemory when done*/
uint8_t* rx = NULL;
int rx_size = 0;
if (dx_eoe_receive_frame(master, 1, 0, &rx, &rx_size, 5000)) {
printf("收到 %d 字节\n", rx_size); /* Received %d bytes */
FreeMemory(rx);
}
Dispose(master);
return 0;
}