Skip to main content

VoE (Vendor over EtherCAT)

The VoE protocol lets device vendors exchange custom, vendor-specific data through the EtherCAT mailbox, for non-standard vendor functions (Mailbox Type 0x0F).

Function naming

The public VoE interface is the notification subscription pair voe_register_notification / voe_unregister_notification plus listener-thread control (no handle, no function-pointer table).

Capability detection​

Query it with the tri-state ec_slave_get_proto_support_state(master, slave, MBXPROT_VOE) (returns EC_PROTO_SUPPORT_YES/NO/UNKNOWN). VoE has no dedicated details field in SII General, so when the mailbox capability bit is 0 the only possible answer is UNKNOWN — never report that as "the device does not support VoE".

Sending, receiving and notifications​

VoE lets device vendors exchange custom, vendor-specific data. Vendor pushes are received through Asynchronous notifications below; the synchronous send and receive entry points are defined by the public headers shipped with the package.

Asynchronous notifications (slave/voe.h)​

VoE has no standard event mechanism like CoE, but vendors often need "slave pushes" → "application callback" semantics. slave/voe.h provides this with a background listener thread: the application only registers a subscription and is notified when data arrives.

Listener threads and subscriptions are scoped per master: each master has its own thread and its own subscription table. A VoE push from slave N on master A is delivered only to callbacks registered on A; it never leaks to the same slave index on master B.

voe_notification_cb_t​

typedef void (*voe_notification_cb_t)(uint16_t master_index,
uint16_t slave,
uint32_t vendor_id,
uint16_t vendor_type,
const uint8_t* data,
uint32_t data_size,
void* user_data);

Callback parameters:

  • master_index (uint16_t) — source master of the notification (multi-master routing key)
  • slave (uint16_t) — slave index
  • vendor_id (uint32_t) — vendor ID
  • vendor_type (uint16_t) — vendor-defined type
  • data (const uint8_t*) — received VoE data (valid only during the callback)
  • data_size (uint32_t) — data size
  • user_data (void*) — context pointer supplied at registration

voe_start_notification_listener()​

int voe_start_notification_listener(uint16_t master_index);

Starts the VoE notification listener thread for the given master. Returns 1 on success, 0 when the runtime is not ready or on failure.

voe_register_notification()​

int voe_register_notification(uint16_t master_index, uint16_t slave,
uint32_t vendor_id, uint16_t vendor_type,
voe_notification_cb_t cb, void* user_data);

Registers a VoE notification subscription (filtered by vendor_id / vendor_type). The subscription belongs to the master given by master_index; each master is independent. Returns a subscription index >= 0; a negative value means failure.

voe_unregister_notification()​

int voe_unregister_notification(uint16_t master_index, int subscription_index);

Unregisters a subscription by index. Only subscriptions of this master (master_index) can be removed.

voe_stop_notification_listener()​

int voe_stop_notification_listener(uint16_t master_index);

Stops the listener thread of the given master (other masters are unaffected).

voe_is_notification_listening()​

int voe_is_notification_listening(uint16_t master_index);

Queries whether the listener thread of the given master is running (1 = running).

Example:

#include "slave/voe.h"

static void on_voe_data(uint16_t mi, uint16_t si, uint32_t vid, uint16_t vtype,
const uint8_t* data, uint32_t size, void* user)
{
printf("VoE 推送: master=%u, slave=%u, VendorID=0x%08X, Type=0x%04X, %u 字节\n", /* VoE push: master=%u, slave=%u, VendorID=0x%08X, Type=0x%04X, %u bytes */
mi, si, vid, vtype, size);
/* data is valid only during the callback; copy it immediately if you need to keep it */
}

int main(void)
{
uint16_t master = Initialize();
/* ... initialization omitted ... */

/* start this master's listener thread */
voe_start_notification_listener(master);

/* register subscriptions for slaves 1 and 2 on this master */
int sub1 = voe_register_notification(master, 1, 0x12345678, 0x0001, on_voe_data, NULL);
int sub2 = voe_register_notification(master, 2, 0x12345678, 0x0001, on_voe_data, NULL);

/* ... application loop ... */

/* stop and release resources */
voe_unregister_notification(master, sub1);
voe_unregister_notification(master, sub2);
voe_stop_notification_listener(master);

Dispose(master);
return 0;
}
Callback thread

Callbacks run on the listener thread inside the advanced layer, asynchronously to the main program. Guard shared data with a mutex; do not call blocking send or receive interfaces from a callback, because they contend for the mailbox with the listener itself.

Full example​

#include "ethercat.h"
#include "slave/voe.h"
#include <stdio.h>

static void on_voe_data(uint16_t mi, uint16_t si, uint32_t vid, uint16_t vtype,
const uint8_t* data, uint32_t size, void* user)
{
printf("VoE 推送: master=%u, slave=%u, VendorID=0x%08X, Type=0x%04X, %u 字节\n", /* VoE push: master=%u, slave=%u, VendorID=0x%08X, Type=0x%04X, %u bytes */
mi, si, vid, vtype, size);
}

int main(void)
{
uint16_t master = Initialize();
SetNetwork(master, "\\Device\\NPF_{...}", "");
SetStateSequence(master, EC_STATE_PRE_OP, 5000);

/* start the listener and register a subscription */
voe_start_notification_listener(master);
int sub = voe_register_notification(master, 1, 0x12345678, 0x0001,
on_voe_data, NULL);

/* ... application loop ... */

voe_unregister_notification(master, sub);
voe_stop_notification_listener(master);
Dispose(master);
return 0;
}

VoE dx_* interface​

The 5 dx_voe_* functions in slave/voe.h are the synchronous send/receive and capability-query entry points for VoE: send / receive take vendor_id + vendor_type, while send_raw / receive_raw exchange whole frames directly.

CategoryFunctionReturn typeRead/writeDescription
Senddx_voe_sendBOOLwrite-onlySends a VoE request by vendor_id + vendor_type with a payload of data / data_size
dx_voe_send_rawBOOLwrite-onlySends the whole frame frame_data / frame_size directly, without the vendor_id / vendor_type parameters
Receivedx_voe_receiveBOOLread-onlyReceives a VoE response with output parameters vendor_id / vendor_type; *data is allocated by the runtime, its length is in *data_size, and it must be released with FreeMemory()
dx_voe_receive_rawBOOLread-onlyReceives a whole frame into *frame_data / *frame_size, also allocated by the runtime and to be released with FreeMemory()
Capabilitydx_voe_is_supportedBOOLread-onlyWhether this slave supports VoE

Send/receive differences and capability verdicts​

  • Parameterised vs whole frame: dx_voe_send takes the vendor triple (vendor_id / vendor_type plus payload), while dx_voe_send_raw takes a complete VoE frame; on the receive side dx_voe_receive separates vendor_id / vendor_type from the data, while dx_voe_receive_raw returns the raw frame bytes. Use _raw when you build or parse frames yourself, and the parameterised entry points when you only care about vendor data.
  • Receive buffers belong to the runtime: *data from dx_voe_receive and *frame_data from dx_voe_receive_raw are both allocated by the runtime, with lengths in *data_size / *frame_size; release them with FreeMemory().
  • dx_voe_is_supported is a boolean verdict: the header states that the boolean entry point reports "query failed / could not read" as 0, the same shape as "genuinely unsupported". To distinguish "unknown" from "unsupported", use the tri-state query dx_voe_query_support (VOE_SUPPORT_UNKNOWN / VOE_SUPPORT_NO / VOE_SUPPORT_YES).

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);

/* The boolean convention only answers "is it supported"; it reports 0 even when the read fails*/
if (!dx_voe_is_supported(master, 1)) {
printf("不支持 VoE, 或能力读取失败\n"); /* VoE not supported, or the capability read failed */
Dispose(master);
return 0;
}

/* Parameterised send + receive*/
uint8_t req[4] = {0x01, 0x02, 0x03, 0x04};
if (dx_voe_send(master, 1, 0x12345678, 0x0001, req, sizeof(req), 5000)) {
uint32_t vendor_id = 0;
uint16_t vendor_type = 0;
uint8_t* rsp = NULL;
int rsp_size = 0;
if (dx_voe_receive(master, 1, &vendor_id, &vendor_type, &rsp, &rsp_size, 5000)) {
printf("vendor=0x%08X type=0x%04X, %d 字节\n", vendor_id, vendor_type, rsp_size); /* vendor=0x%08X type=0x%04X, %d bytes */
FreeMemory(rsp); /* The receive buffer is allocated by the runtime*/
}
}

/* Whole-frame send/receive*/
uint8_t raw[8] = {0};
dx_voe_send_raw(master, 1, raw, sizeof(raw), 5000);

uint8_t* rsp_raw = NULL;
int rsp_raw_size = 0;
if (dx_voe_receive_raw(master, 1, &rsp_raw, &rsp_raw_size, 5000)) {
FreeMemory(rsp_raw);
}

Dispose(master);
return 0;
}