Skip to main content

VoE (Vendor over EtherCAT)

The VoE protocol carries vendor-defined data transfers and supports the ETG.1000.6 mailbox communication specification (Mailbox Type 0x0F). Each vendor can define its own VoE header format and data structures.

Accessed through slave.voe (the instance is created lazily and always returns an object). Whether a slave supports VoE is determined with slave.voe.is_supported: that property yields only True (positive evidence in the SII mailbox protocol bits) or None (unknown) and never produces False, so it cannot be used to conclude "confirmed unsupported".​

Method overview​

CategoryMethodTypeRead/writeDescription
Command transfersendboolwrite-onlySends one vendor command to the slave without waiting for a response
receiveVoEResponse or Noneread-onlyReceives one vendor data record sent spontaneously by the slave
send_and_receiveVoEResponse or Noneread/writeSends a command and waits for the response of the same transaction
send_asyncbool (await)write-onlyasync variant of send; the blocking round trip runs on the VoE thread pool
receive_asyncVoEResponse or None (await)read-onlyasync variant of receive
send_and_receive_asyncVoEResponse or None (await)read/writeasync variant of send_and_receive
Raw framesend_rawboolwrite-onlySends a complete self-assembled frame (including the 6-byte header)
receive_rawbytes or Noneread-onlyReceives one raw frame
send_raw_and_receivebytes or Noneread/writeSends a raw frame and waits for the response
Frame encoding/decodingbuild_framebytesread-onlyStatic method: assembles the standard frame header and data
parse_frameVoEResponse or Noneread-onlyStatic method: splits the frame header; returns None when the frame is shorter than the header
Notificationstart_notification_listenerboolwrite-onlyStarts the listening thread of this master and subscribes this slave to all vendor notifications
stop_notification_listenerNonewrite-onlyRemoves this slave's subscription and clears the callbacks registered on this instance
stop_all_listenersNonewrite-onlyStops the master listening thread and removes every subscription of that master
add_notification_listenerNonewrite-onlyRegisters a notification callback
remove_notification_listenerNonewrite-onlyRemoves a notification callback

Properties​

CategoryPropertyTypeRead/writeDescription
Configurationdefault_timeout_msintread/writeDefault timeout (milliseconds), 5000 by default
Capabilityis_supportedOptional[bool]read-onlyWhether the slave SII declares the VoE mailbox protocol (mbx_proto bit 5). Yields only True (positive evidence) / None (unknown); this path never produces False
Frame formatVOE_HEADER_SIZEintread-onlyVoE header size (6 bytes: VendorID 4 + VendorType 2)

Basic operations​

send()​

def send(self, vendor_id: int, vendor_type: int, data: bytes,
timeout_ms: int = 0) -> bool

Sends VoE data to the slave. When timeout_ms=0, default_timeout_ms is used.

Example:

slave.voe.send(0x00000002, 0x0001, bytes([0x01, 0x02, 0x03]))

receive()​

def receive(self, timeout_ms: int = 0) -> Optional[VoEResponse]

Receives VoE data from the slave.

send_and_receive()​

def send_and_receive(self, vendor_id: int, vendor_type: int, data: bytes,
timeout_ms: int = 0) -> Optional[VoEResponse]

Sends VoE data and waits for the response.

VoEResponse class:

class VoEResponse:
vendor_id: int # vendor ID
vendor_type: int # vendor type
data: bytes # response data

@property
def data_length(self) -> int # data length (derived from data, read-only)

def to_hex_string(self) -> str:
"""数据格式化为十六进制字符串(如 "01 02 03")""" # Format the data as a hexadecimal string (e.g. 01 02 03)
...

Example:

response = slave.voe.send_and_receive(0x00000002, 0x0001, bytes([0x10]))
if response is not None:
print(f"厂商ID: 0x{response.vendor_id:08X}") # VendorID: 0x{response.vendor_id:08X}
print(f"数据: {response.to_hex_string()}") # Data: {response.to_hex_string()}

send_async()​

async def send_async(self, vendor_id: int, vendor_type: int, data: bytes,
timeout_ms: int = 0) -> bool

The async variant of send(): the same frame encoding and send path, with the blocking mailbox round trip executed on a VoE-dedicated thread pool so the event loop is not occupied. The return-value semantics are exactly the same as send().

Parameters:

  • vendor_id (int) — vendor ID (4 bytes)
  • vendor_type (int) — vendor type (2 bytes)
  • data (bytes) — data to send
  • timeout_ms (int) — mailbox wait timeout (milliseconds); 0 = use default_timeout_ms

Returns:

  • bool — True the send succeeded; False the slave rejected it or the mailbox send failed
The timeout has two layers; 0 does not mean "return immediately"

With timeout_ms=0 the instance's default_timeout_ms is taken first as the mailbox timeout, and the await side then allows 200 ms more on top of that value; past it asyncio.TimeoutError is raised, while the send already running on the thread pool still runs to completion.

Example:

import asyncio

async def main():
ok = await slave.voe.send_async(0x00000002, 0x0001, bytes([0x01, 0x02]))
print("发送成功" if ok else "发送失败") # Send succeeded / send failed

asyncio.run(main())

receive_async()​

async def receive_async(self, timeout_ms: int = 0) -> Optional['VoEResponse']

The async variant of receive(), waiting for one vendor data record sent proactively by the slave.

Parameters:

  • timeout_ms (int) — receive wait timeout (milliseconds); 0 = use default_timeout_ms

Returns:

  • VoEResponse — the received vendor response (with vendor_id / vendor_type / data)
  • None — timed out, or there is no data in the mailbox to receive

The mailbox side uses the effective timeout (0 when default_timeout_ms), and the await side allows 200 ms more; on timeout asyncio.TimeoutError is raised.

Example:

async def poll_once():
reply = await slave.voe.receive_async(timeout_ms=1000)
if reply is not None:
print(f"0x{reply.vendor_type:04X}: {reply.to_hex_string()}")

send_and_receive_async()​

async def send_and_receive_async(self, vendor_id: int, vendor_type: int,
data: bytes, timeout_ms: int = 0
) -> Optional['VoEResponse']

The async variant of send_and_receive(): it sends first and then receives, and the two mailbox round trips share the same timeout_ms.

Parameters:

  • vendor_id (int) — vendor ID (4 bytes)
  • vendor_type (int) — vendor type (2 bytes)
  • data (bytes) — data to send
  • timeout_ms (int) — timeout (milliseconds); 0 = use default_timeout_ms

Returns:

  • VoEResponse — the slave's response to this frame
  • None — the send failed (the receive is not attempted afterwards), or the receive timed out
The total duration can be about twice the timeout

The send and the receive each use timeout_ms once, so the await side only gives up after 2 × 超时 + 400 ms; estimating a business timeout from a single mailbox round trip underestimates the wait by half.

Example:

async def query():
resp = await slave.voe.send_and_receive_async(
vendor_id=0x00000002, vendor_type=0x0001, data=bytes([0x10]))
if resp is not None:
print(resp.to_hex_string())
Raw frame direction

send_raw / receive_raw / send_raw_and_receive each have _async variants of the same name; their behaviour corresponds one-to-one with the synchronous versions, and the same timeout-margin rules apply.

Raw frame operations​

send_raw()​

def send_raw(self, frame_data: bytes, timeout_ms: int = 0) -> bool

Sends a raw VoE frame (the caller assembles the frame format, including the VoE header).

Parameters:

  • frame_data (bytes) — complete VoE frame data (6-byte VoE header + data)
  • timeout_ms (int) — timeout (milliseconds); 0 = use default_timeout_ms

Returns:

  • bool — True on success

receive_raw()​

def receive_raw(self, timeout_ms: int = 0) -> Optional[bytes]

Receives a raw VoE frame.

Returns:

  • bytes | None — raw frame data; None on failure

send_raw_and_receive()​

def send_raw_and_receive(self, frame_data: bytes, timeout_ms: int = 0) -> Optional[bytes]

Sends a raw frame and waits for the response.

Returns:

  • bytes | None — raw frame data of the response; None on failure

Example:

# assemble a VoE frame manually
import struct
frame = struct.pack('<IH', 0x00000002, 0x0001) + bytes([0x10, 0x20])
raw_resp = slave.voe.send_raw_and_receive(frame)
if raw_resp is not None:
print(f"原始响应: {raw_resp.hex()}") # Raw response: {raw_resp.hex()}

Helper methods​

build_frame()​

@staticmethod
def build_frame(vendor_id: int, vendor_type: int, data: Optional[bytes] = None) -> bytes

Builds a standard VoE frame (VoE header + data). Static method; it can be called on an instance (slave.voe.build_frame(...)) or on the class (VoE.build_frame(...)).

Parameters:

  • vendor_id (int) — vendor ID (4 bytes)
  • vendor_type (int) — vendor type (2 bytes)
  • data (bytes, optional) — data payload

Returns:

  • bytes — the assembled VoE frame

parse_frame()​

@staticmethod
def parse_frame(frame: bytes) -> Optional[VoEResponse]

Parses the VoE frame header. Static method.

Parameters:

  • frame (bytes) — complete VoE frame

Returns:

  • VoEResponse | None — parsed VoE response object; None when parsing fails

Example:

# build a frame
frame = slave.voe.build_frame(0x00000002, 0x0001, bytes([0x10]))

# parse the frame
parsed = slave.voe.parse_frame(frame)
if parsed is not None:
print(f"厂商ID: 0x{parsed.vendor_id:08X}") # VendorID: 0x{parsed.vendor_id:08X}
print(f"类型: 0x{parsed.vendor_type:04X}") # Type: 0x{parsed.vendor_type:04X}
print(f"数据: {parsed.to_hex_string()}") # Data: {parsed.to_hex_string()}

Complete example​

Vendor command exchange​

if slave.voe.is_supported:
response = slave.voe.send_and_receive(
vendor_id=0x00000002,
vendor_type=0x0001,
data=bytes([0x01, 0x00])
)

if response is not None:
print(str(response))

Bulk data transfer​

if slave.voe.is_supported:
payload = bytes(1024)
slave.voe.send(0x00000002, 0x1000, payload)

reply = slave.voe.receive()
if reply is not None:
print(f"收到 {reply.data_length} 字节响应") # Received a {reply.data_length}-byte response

Vendor notification listener​

Some vendors push state changes proactively through the VoE mailbox. The SDK keeps one resident listening thread per master; start_notification_listener() subscribes this slave to all vendor notifications, and received notifications are dispatched through Python callbacks.

The listening thread and the subscriptions are both scoped per master: a notification from slave N on master A only reaches A's callbacks and never leaks to the slave with the same number on master B.

VoENotificationEventArgs​

from darra_ethercat.slave.voe import VoENotificationEventArgs

class VoENotificationEventArgs:
master_index: int # source master (routing key when several masters exist)
slave_index: int # slave index that raised the notification
vendor_id: int # vendor ID (0x00000002 = Beckhoff)
vendor_type: int # vendor command type
data: bytes # notification payload (may be empty)
timestamp: float # time.time() timestamp

start_notification_listener()​

def start_notification_listener(self) -> bool

Starts the listening thread of the master this instance belongs to and subscribes this slave to all vendor notifications. Re-entrant safe; repeated calls are idempotent.

Returns:

  • True — started successfully; notifications are dispatched through the callbacks registered with add_notification_listener()
  • False — the underlying library does not support notification listening, or registration failed

stop_notification_listener()​

def stop_notification_listener(self) -> None

Removes this slave's subscription and clears the Python callbacks already registered on this instance (the callbacks added with add_notification_listener). It does not stop the master listening thread; other slaves on the same master can still subscribe.

stop_all_listeners()​

def stop_all_listeners(self) -> None

Removes all subscriptions on the current master and stops the listening thread of that master (threads and subscriptions of other masters are unaffected).

is_listener_running​

@property
def is_listener_running(self) -> bool

Whether the listening thread of the master this instance belongs to is running (queried per master; instances on different masters each return their own result).

add_notification_listener() / remove_notification_listener()​

def add_notification_listener(self, listener: Callable[[VoENotificationEventArgs], None]) -> None
def remove_notification_listener(self, listener: Callable[[VoENotificationEventArgs], None]) -> None

Registers / removes a notification callback on the Python side. Multiple callbacks may exist at the same time; an exception in one callback does not affect the others.

Example:

from darra_ethercat.slave.voe import VoENotificationEventArgs

def on_voe_notify(args: VoENotificationEventArgs):
print(f"[VoE] master={args.master_index} slave={args.slave_index} "
f"vendor=0x{args.vendor_id:08X} "
f"type=0x{args.vendor_type:04X} "
f"data={args.data.hex()}")

slave.voe.add_notification_listener(on_voe_notify)
if not slave.voe.start_notification_listener():
print("启动监听失败") # Failed to start the listener
else:
print(f"监听运行中: {slave.voe.is_listener_running}") # Listener running: {slave.voe.is_listener_running}
# ... receive notifications ...
slave.voe.remove_notification_listener(on_voe_notify)
slave.voe.stop_notification_listener()
Callbacks run on the underlying library listening thread

Notification callbacks run on the underlying library listening thread. The SDK swallows exceptions to avoid a crash, but time-consuming work slows notification dispatch. Keep the callback to light logging / queueing and move real processing to a business thread.

# high level: 6-byte frame header = u32 VendorID (little-endian) + u16 VendorType (little-endian)
frame = slave.voe.build_frame(0x00000002, 0x0001, bytes([0x10]))
parsed = slave.voe.parse_frame(frame)
print(parsed.vendor_id, parsed.vendor_type, parsed.data)

# low level: send_raw / receive_raw use the same frame encoding and can be compared byte for byte with SDK in other languages
assert slave.voe.build_frame(0x00000002, 0x0001) == bytes([0x02, 0x00, 0x00, 0x00, 0x01, 0x00])
Frame header layout consistency

The low-level interfaces are byte-for-byte equivalent to the high-level build_frame / parse_frame (the same 6-byte header layout); field order and byte order are identical, so SDKs in different languages can compare them byte by byte. There is no branch where "the Python header differs from the underlying library header"; when the frame is shorter than 6 bytes parsing fails, and a too-short frame is never padded with 0 into a valid frame.

Failures and handling​

SymptomCauseHandling
send returns FalseThe slave rejects this VendorID / VendorType, or the mailbox is unavailable / the send timed outCheck the command number against the slave documentation and first confirm with CoE that the slave is communicable; do not resend the same command repeatedly
send_and_receive returns None after waiting out the full timeoutThe slave does not answer this command, or the mailbox is occupied by another protocolConfirm the slave has reached a communicable state, increase the timeout and retry once
send_raw raises ValueErrorThe frame passed in is emptyFrame data cannot be empty; this is a caller-side framing error, not a link failure
is_supported is None and every call failsThe slave does not declare VoE and the capability bit cannot be readSwitch to CoE or another interface given by the device documentation; retrying will not solve it

shutdown_voe_async_executor()​

from darra_ethercat.slave.voe import shutdown_voe_async_executor

def shutdown_voe_async_executor(wait: bool = True) -> None

Shuts down the VoE async thread pool. send_async / receive_async / send_and_receive_async and their raw frame variants share this pool; it is created lazily on the first asynchronous method call, and calling this function before the program exits releases it.

Parameters:

  • wait (bool) — True (the default) waits for the asynchronous sends and receives already submitted to finish before shutting down; False returns immediately and unfinished tasks are not guaranteed to complete
Pool reclamation only

Idempotent; repeated calls have no side effects; calling an asynchronous method after shutdown lazily recreates the pool. It does not remove notification subscriptions — stopping the listener still goes through stop_notification_listener() / stop_all_listeners().

Example:

import asyncio
from darra_ethercat.slave.voe import shutdown_voe_async_executor

async def main():
resp = await slave.voe.send_and_receive_async(0x00000002, 0x0001, b"\x10")
print(resp.to_hex_string() if resp is not None else "无响应") # No response

try:
asyncio.run(main())
finally:
shutdown_voe_async_executor()