Skip to main content

VoE (Vendor over EtherCAT)

VoE exchanges vendor-defined data with a slave. It follows the ETG.1000.6 Mailbox specification (Mailbox Type 0x0F): every message carries a VendorID and VendorType header, and the data format inside the frame is defined by the vendor. Before sending a command you can use ValidateVendorId to confirm the peer is the expected vendor.

Access it through slave.GetVoE(). It returns a VoE& reference and the instance always exists; use IsSupported() to decide whether the slave supports VoE, and treat "cannot determine" as not supported.​

Method overview​

CategoryMethodTypeRead/writeDescription
Data sendSendboolWrite-onlySends a block of vendor data with a VendorID / VendorType
Data receiveReceiveoptional VoEResponseRead-onlyReceives one frame of vendor data; returns empty on timeout
Data receiveReceive (buffer form)boolRead-onlyReceives into a caller buffer; a payload that is too long fails outright instead of being truncated
Request/responseSendAndReceiveoptional VoEResponseRead/writeSends and then waits for one response frame; check the VendorID / VendorType of the response
Raw frameSendRaw / ReceiveRaw / SendRawAndReceivebool / byte arrayRead/writeSends or receives a raw frame that carries the VoE header
Frame encode/decodeBuildVoEFrame / ParseVoEFramebyte array / optional VoEResponseRead-onlyBuilds a frame and parses a frame
HeaderGetVoEHeader / SetVoEHeaderoptional VoEHeader / boolRead/writeReads the header of the most recent frame / sets the header by sending an empty frame
Vendor checkValidateVendorIdboolRead-onlyChecks whether the VendorID in the slave SII equals the expected value or is in the allowed list
Capability queryIsSupportedboolRead-onlyWhether the slave declares support for VoE

Frame format​

From the caller's side you supply only the VoE header + data; the mailbox header is handled by the SDK. VoE frame layout (raw frames for SendRaw / ReceiveRaw also start with the VoE header):

OffsetFieldTypeDescription
0VendorIduint32Vendor ID, little-endian
4VendorTypeuint16Vendor type, little-endian
6Databyte arrayVendor-defined payload

Query the maximum payload per call with GetMaxVoEDataSize().

Properties​

CategoryPropertyTypeRead/writeDescription
CapabilityIsSupported()boolRead-onlyWhether the slave supports the VoE protocol
GetMaxVoEDataSize()intRead-onlyMaximum VoE data payload size
Vendor checkValidateVendorId()boolRead-onlyWhether the VendorID in the slave SII equals the expected value / is in the allowed list
GetVendorId()uint32Read-onlyReads the raw SII VendorID; returns 0 on failure

Basic operations​

Send()​

bool Send(uint32_t vendorId, uint16_t vendorType,
const uint8_t* data, int dataLen, int timeoutMs = 500) const;

Sends VoE data to the slave.

Parameters:

  • vendorId (uint32_t) — vendor ID (4 bytes)
  • vendorType (uint16_t) — vendor type (2 bytes)
  • data (const uint8_t*) — data contents (may be nullptr, meaning an empty payload)
  • dataLen (int) — data length (bytes)
  • timeoutMs (int) — timeout (milliseconds, default 500)

Returns:

  • bool — true on success; false when the slave does not support VoE, has not yet reached a communicable state, or the send times out

Example:

auto& voe = master.GetSlave(1).GetVoE();

uint8_t cmd[] = {0x01, 0x00};
voe.Send(0x00000002, 0x0001, cmd, sizeof(cmd));

Receive()​

std::optional<VoEResponse> Receive(int timeoutMs = 500) const;

Receives one frame of VoE data from the slave.

Parameters:

  • timeoutMs (int) — timeout (milliseconds, default 500)

Returns:

  • std::optional<VoEResponse> — the VoE response object; std::nullopt on timeout / no data

Related structures:

struct VoEResponse {
uint32_t VendorId; // Vendor ID
uint16_t VendorType; // Vendor data type
std::vector<uint8_t> Data; // Data content

int DataLength() const; // Data length
std::string ToHexString() const; // Formatted as a hex string (e.g. "01 02 03")
std::string ToString() const; // Full description
};

Example:

auto& voe = master.GetSlave(1).GetVoE();

auto resp = voe.Receive();
if (resp) {
printf("厂商ID: 0x%08X, 类型: 0x%04X, 数据: %zu 字节\n", // Vendor ID: 0x%08X, type: 0x%04X, data: %zu bytes
resp->VendorId, resp->VendorType, resp->Data.size());
printf("十六进制: %s\n", resp->ToHexString().c_str()); // Hex: %s
}

Receive() buffer form​

bool Receive(uint8_t* buf, int maxLen, int* actualLen,
uint32_t* vendorIdOut = nullptr,
uint16_t* vendorTypeOut = nullptr,
int timeoutMs = 500) const;

The caller supplies an allocated receive buffer; the function fills it and returns the length actually written. When the payload exceeds maxLen it is not truncated — the call returns false outright (so the layer above cannot mistake the length).

Parameters:

  • buf (uint8_t*) — receive buffer (owned by the caller, at least maxLen bytes)
  • maxLen (int) — buffer size
  • actualLen (int*) — bytes actually written (0 on failure)
  • vendorIdOut (uint32_t*) — output VendorID (optional)
  • vendorTypeOut (uint16_t*) — output VendorType (optional)
  • timeoutMs (int) — timeout (milliseconds, default 500)

Returns:

  • bool — true = a frame was received and buf holds the payload; false = timeout / buf too small / wrong parameter

Example:

uint8_t buf[256];
int n = 0;
uint32_t vid = 0;
uint16_t vtype = 0;
if (voe.Receive(buf, sizeof(buf), &n, &vid, &vtype))
printf("VID=0x%08X type=0x%04X %d 字节\n", vid, vtype, n); // VID=0x%08X type=0x%04X %d bytes

SendAndReceive()​

Sends data and waits for a response (a send + receive combination). Raw pointer and std::vector versions are supported, and there is also an overload without VendorID / VendorType (it sends an empty VoE header).

std::optional<VoEResponse> SendAndReceive(uint32_t vendorId, uint16_t vendorType,
const uint8_t* data, int dataLen,
int timeoutMs = 500) const;

std::optional<VoEResponse> SendAndReceive(uint32_t vendorId, uint16_t vendorType,
const std::vector<uint8_t>& data,
int timeoutMs = 500) const;

std::optional<VoEResponse> SendAndReceive(const std::vector<uint8_t>& data,
int timeoutMs = 500) const;

Sends a block of vendor data and then waits for one response frame. The VendorID / VendorType of the response come back with the VoEResponse, and the caller checks whether it is the peer's reply.

Parameters:

  • vendorId (uint32_t) — vendor ID
  • vendorType (uint16_t) — vendor type
  • data / dataLen — the payload to send
  • timeoutMs (int) — timeout for the send and the receive individually (milliseconds, default 500)

Returns:

  • std::optional<VoEResponse> — the response received; std::nullopt when the send fails or no response arrives before the timeout

SendReceive(...) is an alias for the same operation, with the same overload forms.

Example:

auto& voe = master.GetSlave(1).GetVoE();

uint8_t cmd[] = {0x10, 0x00};
auto response = voe.SendAndReceive(0x00000002, 0x0001, cmd, sizeof(cmd));
if (response) {
printf("厂商ID: 0x%08X\n", response->VendorId); // Vendor ID: 0x%08X
printf("数据: %s\n", response->ToHexString().c_str()); // Data: %s
} else {
printf("无响应\n"); // No response
}

Raw frame operations​

SendRaw() / ReceiveRaw()​

bool SendRaw(const uint8_t* frame, int frameLen, int timeoutMs = 500) const;
std::vector<uint8_t> ReceiveRaw(int timeoutMs = 500) const;

Sends / receives a raw VoE frame (including the VoE header; for the layout see "Frame format").

Parameters:

  • frame (const uint8_t*) / frameLen (int) — the raw frame and its length (SendRaw)
  • timeoutMs (int) — timeout (milliseconds, default 500)

Returns:

  • SendRaw — bool, true on success and false on failure
  • ReceiveRaw — std::vector<uint8_t>, an empty array on failure / timeout

SendRawAndReceive()​

std::vector<uint8_t> SendRawAndReceive(const uint8_t* frame, int frameLen,
int timeoutMs = 500) const;
std::vector<uint8_t> SendRawAndReceive(const std::vector<uint8_t>& frame,
int timeoutMs = 500) const;

Sends a raw frame and waits for a response. Raw pointer and std::vector versions are supported.

Returns:

  • std::vector<uint8_t> — the raw frame data of the response; an empty vector on failure

Helper methods​

BuildVoEFrame()​

static std::vector<uint8_t> BuildVoEFrame(uint32_t vendorId, uint16_t vendorType,
const uint8_t* data, int dataLen);

Builds a standard VoE frame (VoE header + data) for use with SendRaw().

Parameters:

  • vendorId (uint32_t) — vendor ID
  • vendorType (uint16_t) — vendor type
  • data (const uint8_t*) / dataLen (int) — payload (may be empty)

Returns:

  • std::vector<uint8_t> — the assembled raw frame (6-byte header + payload)

ParseVoEFrame()​

static std::optional<VoEResponse> ParseVoEFrame(const uint8_t* frame, int frameLen);

Parses the VoE frame header and payload. Returns std::nullopt when the frame is shorter than 6 bytes or the pointer is null.

Parameters:

  • frame (const uint8_t*) / frameLen (int) — the raw frame and its length

Returns:

  • std::optional<VoEResponse> — the parsed VoE response object; std::nullopt when parsing fails

VoE header information​

GetVoEHeader() / SetVoEHeader()​

std::optional<VoEHeader> GetVoEHeader(int timeoutMs = 500) const;
bool SetVoEHeader(uint32_t vendorId, uint16_t vendorType, int timeoutMs = 500) const;

Gets / sets the VoE header information. GetVoEHeader() extracts the header from the most recently received frame. SetVoEHeader() sends an empty data frame to set the header.

Parameters:

  • vendorId (uint32_t) / vendorType (uint16_t) — the header to set (SetVoEHeader)
  • timeoutMs (int) — timeout (milliseconds, default 500)

Returns:

  • GetVoEHeader() — std::optional<VoEHeader>, std::nullopt when none is available
  • SetVoEHeader() — bool, true on success

Related structures:

struct VoEHeader {
uint32_t VendorId; // Vendor ID
uint16_t VendorType; // Vendor type
};

Protocol support detection​

IsSupported()​

bool IsSupported() const;

Checks whether the slave supports the VoE protocol (detected through the mailbox protocol bits).

Returns:

  • bool — true when supported; "not supported" or "cannot determine" are both treated as false

GetMaxVoEDataSize()​

int GetMaxVoEDataSize() const;

Gets the maximum VoE data payload size (the mailbox write length minus the 6-byte VoE header and the 6-byte mailbox header).

Returns:

  • int — maximum payload in bytes; 0 when the mailbox write length cannot hold both headers

Vendor check​

ValidateVendorId()​

bool ValidateVendorId(uint32_t expectedVendorId) const;
bool ValidateVendorId(const std::vector<uint32_t>& allowedVendorIds) const;

Checks whether the VendorID in the slave SII equals the expected value, or is in the allowed list (any match gives true). Use it to confirm the peer is the expected vendor before VoE communication, so a command is not sent to the wrong slave.

Parameters:

  • expectedVendorId (uint32_t) — the expected VendorID (for example Beckhoff = 0x00000002)
  • allowedVendorIds (const std::vector<uint32_t>&) — the list of allowed VendorIDs

Returns:

  • bool — true = match; false = no match / VendorID cannot be read from SII (reading 0 does not count as a match)

GetVendorId()​

uint32_t GetVendorId() const;

Reads the raw SII VendorID so the caller can decide for itself.

Returns:

  • uint32_t — the VendorID; 0 on failure

VoENotificationManager​

Some vendor devices report "events / alarms" spontaneously as VoE frames (not through SDO and not through EMCY). Subscribe to those spontaneous reports with VoENotificationManager, an RAII-style per-master subscription manager.

The C++ VoENotificationManager interface is a two-step one

C++ VoENotificationManager does not provide single-call wrappers such as Subscribe(slaveIndex, cb) / Unsubscribe() / UnsubscribeAll() / ActiveCount() (those are the AoESubscriptionManager interface, not VoE's). A C++ VoE subscription takes two steps: first AddListener(cb) to add callbacks, then StartNotificationListener(slaveIndex) to start listening. For the full signatures see VoENotificationManager usage flow below.

class VoENotificationManager {
public:
explicit VoENotificationManager(dll_t& dll, uint16_t masterIndex);
~VoENotificationManager(); // The destructor does StopNotificationListener automatically

/// Start the master listener thread and register a wildcard subscription by (slaveIndex / vendorId=0 / vendorType=0)
bool StartNotificationListener(uint16_t slaveIndex = 0);
/// Stop this instance's subscription (called automatically by the destructor)
bool StopNotificationListener();

/// Add a stacked event listener (callable multiple times), callback signature void(const VoENotificationEventArgs&)
void AddListener(VoENotificationCallback cb);
void ClearListeners();
size_t ListenerCount() const;

/// Master-wide listener thread control (static, per master)
static bool IsListenerRunning(dll_t& dll, uint16_t masterIndex);
static bool StopAllListeners(dll_t& dll, uint16_t masterIndex);
};

Event structure:

struct VoENotificationEventArgs {
uint16_t MasterIndex; // Source master index (the multi-master routing key)
uint16_t SlaveIndex; // Slave index
uint32_t VendorId; // Vendor ID
uint16_t VendorType; // Vendor type
std::vector<uint8_t> Data; // Report data
int64_t TimestampUs; // Receive timestamp (UNIX epoch microseconds)
};

Characteristics:

  • RAII unsubscription: the manager destructor calls StopNotificationListener automatically, removing this instance's subscription so no callback is left with a dangling pointer
  • Multiple callbacks: the same manager can take several std::function callbacks through repeated AddListener, fired in registration order; an exception thrown by one callback does not affect the others
  • Background thread: callbacks run on the SDK notification thread, so touching UI or shared state needs std::mutex / std::atomic; do not block inside a callback

Member overview:

CategoryMethodTypeRead/writeDescription
LifetimeStartNotificationListenerboolWrite-onlyStarts the master listener thread and registers one wildcard subscription (vendorId=0 / vendorType=0); slaveIndex=0 means any slave
LifetimeStopNotificationListenerboolWrite-onlyRemoves this instance's subscription; when removal fails the local subscription state is kept and the call can be retried
CallbackAddListenervoidWrite-onlyAdds one event callback; may be called repeatedly
CallbackClearListenersvoidWrite-onlyClears all registered callbacks
CallbackListenerCountsize_tRead-onlyNumber of callbacks currently registered
StateSubscriptionIndexintRead-onlyThe subscription index assigned underneath; -1 means there is currently no subscription
StateMasterIndexuint16_tRead-onlyIndex of the master this manager belongs to
DispatchDispatchvoidWrite-onlyInternal dispatch entry point that passes one event to all callbacks in registration order
DiagnosticsLastStopErrorintRead-onlyResult of the most recent stop, 0 = no error, 1 = removal failed
DiagnosticsUnregisterFailureCountuint32_tRead-onlyCumulative number of removal failures

Dispatch(args) is an internal dispatch entry point that application code does not need to call: when a VoE frame arrives, the manager's callback bridge calls it, walking the registered callbacks in order; an exception thrown by one callback is swallowed and does not affect the callbacks after it. Calling Dispatch by hand merely forwards one event to the current callbacks unchanged and does not interact with the device at all, so it can be used to replay existing events in a test.

SubscriptionIndex() returns the subscription index assigned underneath after StartNotificationListener succeeds; -1 = this instance currently has no subscription. When removal fails the value stays as it was (the local subscription state is kept and the call can be retried), so it is also the direct basis for telling whether "the subscription is still there": SubscriptionIndex() >= 0 means this subscription has not been fully removed.

Difference from Receive()
  • Receive() is an active pull: the calling thread blocks waiting for one frame and returns when it arrives
  • VoENotificationManager is an event subscription: a report from the slave at any time triggers the callback, and the application thread is not blocked

Use VoENotificationManager when you need event-driven handling, and SendAndReceive() for request-response.

Full example​

Vendor command exchange​

#include <cstdio>
#include <vector>
#include "ethercat.hpp"

int main() {
darra::ethercat::dll_t dll;
darra::EtherCATMaster master(dll);
if (!master.SetENI("C:\\EtherCAT\\MyProject.deni").Build())
return 1;
if (!master.SetState(darra::EcState::OP))
return 1;

auto& voe = master.GetSlave(1).GetVoE();

// Check support
if (!voe.IsSupported()) {
printf("从站不支持 VoE\n"); // Slave does not support VoE
return 1;
}

printf("VoE 最大载荷: %d 字节\n", voe.GetMaxVoEDataSize()); // VoE max payload: %d bytes

// Confirm the peer is the expected vendor first, so the command does not go to the wrong slave
if (!voe.ValidateVendorId(0x00000002)) {
printf("VendorID 不在允许列表\n"); // VendorID is not on the allowlist
return 1;
}

// Send a command and receive the response
uint8_t cmd[] = {0x01, 0x00};
auto resp = voe.SendAndReceive(0x00000002, 0x0001, cmd, sizeof(cmd));
if (resp)
printf("%s\n", resp->ToString().c_str());
else
printf("无响应\n"); // No response

getchar();
return 0;
}

Bulk data transfer​

auto& voe = master.GetSlave(1).GetVoE();

// Send a large data block
std::vector<uint8_t> payload(1024, 0);
voe.Send(0x00000002, 0x1000, payload.data(), static_cast<int>(payload.size()));

// Receive the response
auto reply = voe.Receive();
if (reply)
printf("收到 %d 字节响应\n", reply->DataLength()); // Received a %d byte response

VoENotificationManager usage flow​

A subscription in the C++ SDK takes two steps: first AddListener to add callbacks, then StartNotificationListener to start the listener thread and register the subscription.

StartNotificationListener()​

class VoENotificationManager {
public:
/// Start the master-wide listener thread and register a wildcard subscription by (slaveIndex / vendorId=0 / vendorType=0)
bool StartNotificationListener(uint16_t slaveIndex = 0);
/// Stop this instance's subscription (called automatically by the destructor)
bool StopNotificationListener();

/// Add an event listener (can be called repeatedly to register several)
void AddListener(VoENotificationCallback cb);
void ClearListeners();
size_t ListenerCount() const;

/// Listener thread control for a specific master (static)
static bool IsListenerRunning(dll_t& dll, uint16_t masterIndex);
static bool StopAllListeners(dll_t& dll, uint16_t masterIndex);
};

StartNotificationListener(slaveIndex) — slaveIndex=0 means wildcard (a VoE frame from any slave triggers it); otherwise only the given slave matches. It first starts the master listener thread and then registers one wildcard subscription with vendorId=0 / vendorType=0; on failure it returns false (SDK not ready / registration refused).

StopNotificationListener() — stops this instance's subscription. true means the subscription was removed (not being subscribed in the first place also counts); false means removal failed, and the local subscription is kept so the call can be retried; check LastStopError() (0 = no error, 1 = removal failed) and UnregisterFailureCount() (cumulative number of removal failures).

AddListener(cb) — cb has the signature void(const VoENotificationEventArgs&); the same manager can register several callbacks by calling it repeatedly, and they run in registration order when fired (an exception from one handler does not affect later handlers). To enable or disable a callback dynamically, filter inside the lambda with a std::atomic_bool — the SDK does not remove an individual listener by handle.

Static control methods​

IsListenerRunning(dll, masterIndex) returns whether the VoE listener thread of the given master is running. Listener threads are per master: each master has its own thread and its own subscription table, so a notification from slave N on master A goes only to A's manager and never crosses to the same slave index on master B.

StopAllListeners(dll, masterIndex) stops the listener thread of the given master. After the call, every manager subscription on that master is no longer valid; other masters' listener threads and subscriptions stay as they were, and the caller must clean up the managers of the stopped master. Destroying a VoENotificationManager does not trigger StopAllListeners; it removes only its own subscription.

Real example​

using darra::ethercat::VoENotificationManager;
using darra::ethercat::VoENotificationEventArgs;

VoENotificationManager voeMgr(dll, master.MasterNumber());

voeMgr.AddListener([](const VoENotificationEventArgs& ev) {
printf("[VoE] 主站=%u 从站=%u VID=0x%08X type=0x%04X 时间戳=%lld us, %zu B\n", // [VoE] master=%u slave=%u VID=0x%08X type=0x%04X timestamp=%lld us, %zu B
ev.MasterIndex, ev.SlaveIndex, ev.VendorId, ev.VendorType,
static_cast<long long>(ev.TimestampUs), ev.Data.size());
});

if (!voeMgr.StartNotificationListener(/*slaveIndex=*/0)) {
printf("VoE 监听启动失败\n"); // VoE listening failed to start
}

// ... application running ...

// Before exiting
voeMgr.StopNotificationListener(); // Cancel this instance's subscription
// VoENotificationManager::StopAllListeners(dll, master.MasterNumber()); // stops only this master's thread, use on exit only
Do not call Start repeatedly on several managers

There is one listener thread per master — calling StartNotificationListener in several places within one master does not start several threads, but every manager registers its own subscription and receives events itself. In application code, keeping one manager per master is the simplest arrangement.

Relation to the higher-level Subscribe(si, cb) wrapper

C++ splits "subscribe" into two steps (Start + AddListener), which lets you tell "start listening filtered by slave" apart from "add several callbacks", and also tell a start failure apart from a subscription that succeeded but receives no events. The equivalent two-step form:

mgr.AddListener(cb);
mgr.StartNotificationListener(slaveIndex);

Failures and handling​

SymptomCauseHandling
Send returns falseThe slave does not support VoE, or has not yet reached a communicable stateCheck with IsSupported first, and confirm the slave has entered PreOp or a higher state
Receive / SendAndReceive returns emptyNo response within the timeoutIncrease timeoutMs and check that VendorID / VendorType match the device documentation
ValidateVendorId returns falseThe VendorID in the slave SII is not in the allowed listCheck the device vendor ID; do not send vendor commands to an unexpected device
Response data is emptyThe slave returns only an acknowledgement without a payloadParse according to the protocol definition for that VendorType; do not assume data is always present