VoE (Vendor over EtherCAT)
The VoE protocol is used for vendor-defined data transfer and follows the ETG.1000.6 mailbox communication specification (Mailbox Type 0x0F). Each vendor can define its own VoE header format and data structure.
Obtain a VoEInstance instance through slave.voe().
Properties
| Category | Item | Type | Read/write | Description |
|---|---|---|---|---|
| Configuration | default_timeout_ms (public field) | i32 | read/write | Default timeout (milliseconds), default 500 |
| Constant | VOE_HEADER_SIZE (constant) | usize | read-only | VoE header size (6 bytes: VendorID 4 + VendorType 2) |
| Status | voe_support() | Option<bool> | read-only | Tri-state VoE capability: Some(true) = supported / None = unknown |
| Status | is_support_known() | bool | read-only | Whether the capability conclusion is known (false = unknown, which does not mean unsupported) |
| Status | is_supported() | bool | read-only | Boolean view of VoE capability (true only when known to be supported) |
voe_support() / is_support_known() / is_supported()
pub fn voe_support(&self) -> Option<bool>
pub fn is_support_known(&self) -> bool
pub fn is_supported(&self) -> bool
The SII General Category has no VoE details bit, so mbx_proto bit5 (0x20) can only give a positive conclusion:
Some(true)— bit5 is set, supportedNone— unknown (bit5 = 0 does not prove that VoE is unsupported and must not be folded into false)
is_supported() is true only for Some(true); use is_support_known() when you need to distinguish "unknown" from "unsupported".
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;
| Method | Returns | Description |
|---|---|---|
protocol_type() | u8 | Mailbox protocol type code, VoE = 0x0F |
protocol_name() | &'static str | Protocol name, always "VoE" |
let proto = voe.protocol_type(); // 0x0F
let name = voe.protocol_name(); // "VoE"
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 "Properties" above) and the per-protocol mailbox statistics methods.
Basic operations
send()
pub fn send(&self, vendor_id: u32, vendor_type: u16, data: &[u8]) -> Result<()>
Send VoE data to the slave (using default_timeout_ms).
Parameters:
vendor_id(u32) — vendor ID (4 bytes)vendor_type(u16) — vendor type (2 bytes)data(&[u8]) — data to send
Returns:
Result<()>— success or error
send_with_timeout()
pub fn send_with_timeout(&self, vendor_id: u32, vendor_type: u16,
data: &[u8], timeout_ms: i32) -> Result<()>
Send VoE data to the slave (with an explicit timeout).
Example:
let voe = slave.voe();
voe.send(0x00000002, 0x0001, &[0x01, 0x02, 0x03])?;
receive()
pub fn receive(&self) -> Result<VoEResponse>
Receive VoE data from the slave (using default_timeout_ms).
Returns:
Result<VoEResponse>— VoE response object
receive_with_timeout()
pub fn receive_with_timeout(&self, timeout_ms: i32) -> Result<VoEResponse>
Receive VoE data from the slave (with an explicit timeout).
send_and_receive()
pub fn send_and_receive(&self, vendor_id: u32, vendor_type: u16, data: &[u8]) -> Result<VoEResponse>
Send VoE data and wait for the response (using default_timeout_ms).
Parameters:
vendor_id(u32) — vendor ID (4 bytes)vendor_type(u16) — vendor type (2 bytes)data(&[u8]) — data to send
Returns:
Result<VoEResponse>— VoE response object
Related structures:
pub struct VoEResponse {
pub vendor_id: u32, // Vendor ID
pub vendor_type: u16, // Vendor type
pub data: Vec<u8>, // Response data
}
impl VoEResponse {
/// Format the data as a hex string (e.g. "01 02 03")
pub fn to_hex_string(&self) -> String;
/// Response payload length (bytes, excluding the 6-byte VoE header)
pub fn data_length(&self) -> usize;
}
impl std::fmt::Display for VoEResponse {
// Output: "VoE Response: VendorID=0x00000002, VendorType=0x0001, DataLength=3"
}
VoEResponse::data_length() returns the response payload length in bytes, equal to data.len():
- Does not include the 6-byte VoE header (
VendorID4 bytes +VendorType2 bytes =VOE_HEADER_SIZE);parse_framekeeps only the part after the header indatawhen parsing, sodata_length() == 帧总长度 - VOE_HEADER_SIZE - It reads an in-memory field only: no mailbox transaction is started and it cannot fail; the
DataLengthin theDisplayoutput is the same value
Example:
// send_and_receive takes 3 parameters (uses default_timeout_ms) and returns VoEResponse directly
let resp = voe.send_and_receive(0x00000002, 0x0001, &[0x10])?;
println!("厂商ID: 0x{:08X}", resp.vendor_id); // VendorID: 0x{:08X}
println!("数据: {}", resp.to_hex_string()); // Data: {}
Raw frame operations
send_raw()
pub fn send_raw(&self, frame_data: &[u8]) -> Result<()>
Send a raw VoE frame (using default_timeout_ms; the caller assembles the frame format itself, including the VoE header).
Parameters:
frame_data(&[u8]) — complete VoE frame data (including the VoE header)
Returns:
Result<()>— success or error
send_raw_with_timeout()
pub fn send_raw_with_timeout(&self, frame_data: &[u8], timeout_ms: i32) -> Result<()>
Send a raw VoE frame (with an explicit timeout).
receive_raw()
pub fn receive_raw(&self) -> Result<Vec<u8>>
Receive a raw VoE frame (using default_timeout_ms).
Returns:
Result<Vec<u8>>— raw frame data
receive_raw_with_timeout()
pub fn receive_raw_with_timeout(&self, timeout_ms: i32) -> Result<Vec<u8>>
Receive a raw VoE frame (with an explicit timeout).
send_raw_and_receive()
pub fn send_raw_and_receive(&self, frame_data: &[u8]) -> Result<Vec<u8>>
Send a raw frame and wait for the response (using default_timeout_ms).
Parameters:
frame_data(&[u8]) — complete VoE frame data
Returns:
Result<Vec<u8>>— raw frame data of the response
Example:
// Build a custom VoE frame
let frame = VoEInstance::build_frame(0x00000002, 0x0001, &[0x01, 0x02]);
voe.send_raw(&frame)?; // send_raw takes 1 parameter (uses default_timeout_ms)
// Receive the raw response (receive_raw takes 0 parameters, returns Result<Vec<u8>>)
let raw = voe.receive_raw()?;
if let Some(parsed) = VoEInstance::parse_frame(&raw) {
println!("响应: {}", parsed); // Response: {}
}
Helper methods
VoEInstance::build_frame()
/// Build a standard VoE frame (VoE header + data); associated function (no instance required)
pub fn build_frame(vendor_id: u32, vendor_type: u16, data: &[u8]) -> Vec<u8>
Returns:
Vec<u8>— the constructed VoE frame
VoEInstance::parse_frame()
/// Parse the VoE frame header; associated function (no instance required)
pub fn parse_frame(frame: &[u8]) -> Option<VoEResponse>
Returns:
Option<VoEResponse>— parsed VoE response object; returnsNonewhen parsing fails
Asynchronous notification listening
Some vendor devices push VoE frames to the master proactively when events occur (for example, external sensor alarms or key presses).
The SDK turns these asynchronous pushes into event callbacks through the VoENotificationListener trait,
so the user does not have to poll receive() themselves.
Listeners and subscriptions are split per master: each master has its own listener and its own subscription registration.
VoENotificationEventArgs / VoENotificationListener
Notification event arguments and the listener trait:
#[derive(Debug, Clone)]
pub struct VoENotificationEventArgs {
pub slave_index: u16,
pub vendor_id: u32,
pub vendor_type: u16,
pub data: Vec<u8>,
/// Receive timestamp (microseconds since UNIX_EPOCH)
pub timestamp_us: u64,
}
pub trait VoENotificationListener: Send + Sync + 'static {
fn on_notification(&self, args: &VoENotificationEventArgs);
}
// Any Fn(&VoENotificationEventArgs) closure implements this trait automatically
impl<F> VoENotificationListener for F
where F: Fn(&VoENotificationEventArgs) + Send + Sync + 'static { /* ... */ }
start_notification_listener / stop_notification_listener / stop_all_listeners / is_listener_running
pub fn start_notification_listener<F>(&self, listener: F) -> bool
where F: Fn(&VoENotificationEventArgs) + Send + Sync + 'static
pub fn stop_notification_listener(&self) -> Result<()>
pub fn stop_all_listeners(master_index: u16) -> Result<()> // associated function
pub fn is_listener_running(master_index: u16) -> bool // associated function
start_notification_listener() takes a listener closure, starts the VoE listener and registers a wildcard subscription (vendor_id=0/vendor_type=0). stop_notification_listener() uses the subscription index saved at startup to unregister this master's subscription precisely and removes the listener; stop_all_listeners(master_index) stops the listener of the specified master, while the listeners and subscriptions of other masters stay unchanged. When the runtime does not provide the capability, the SDK degrades safely: start_notification_listener returns false and is_listener_running returns false.
Listeners and subscriptions are registered per master: a notification from slave N on master A enters only A's closure and never crosses over to the same-numbered slave on master B (that is why VoENotificationEventArgs carries no master field; the master identity is determined by the closure bound at registration).
Example:
let voe = slave.voe();
let master_index = slave.master_index();
// Start the listener for this master plus a wildcard subscription, passing the listener closure
let started = voe.start_notification_listener(|args: &VoENotificationEventArgs| {
println!("Slave {} VoE 通知: VID=0x{:08X} 类型=0x{:04X} {} 字节", // Slave {} VoE notification: VID=0x{:08X} type=0x{:04X} {} bytes
args.slave_index, args.vendor_id, args.vendor_type, args.data.len());
});
if !started {
eprintln!("当前运行库不支持 VoE 异步通知, 退化为轮询 receive()"); // The current runtime does not support VoE async notification, degrading to polled receive()
}
// Whether the listener is running (associated function, queried per master)
println!("listener running = {}", VoEInstance::is_listener_running(master_index));
// Application main loop ...
// Stop this master's subscription precisely / or stop this master's listener
voe.stop_notification_listener();
VoEInstance::stop_all_listeners(master_index);
The current Rust SDK uses a wildcard vendor_id=0/vendor_type=0 subscription; when several vendors share one line, your callback must dispatch by args.vendor_id itself.
Complete example
Vendor command interaction
let voe = slave.voe();
if voe.voe_support() != Some(true) {
return Ok(());
}
let resp = voe.send_and_receive(0x00000002, 0x0001, &[0x01, 0x00])?;
println!("{}", resp);
Bulk data transfer
let voe = slave.voe();
if voe.voe_support() != Some(true) {
return Ok(());
}
let payload = vec![0u8; 1024];
voe.send(0x00000002, 0x1000, &payload)?;
let reply = voe.receive()?;
println!("收到 {} 字节响应", reply.data.len()); // Received a {} byte response
Raw frame operations
let voe = slave.voe();
if voe.voe_support() != Some(true) {
return Ok(());
}
// Build and send a raw frame (send_raw_and_receive takes 1 parameter, returns Result<Vec<u8>>)
let frame = VoEInstance::build_frame(0x00000002, 0x0001, &[0x10, 0x20]);
let raw_data = voe.send_raw_and_receive(&frame)?;
println!("原始响应: {} 字节", raw_data.len()); // Raw response: {} bytes
if let Some(parsed) = VoEInstance::parse_frame(&raw_data) {
println!("解析: 厂商ID=0x{:08X}, 数据={}", parsed.vendor_id, parsed.to_hex_string()); // Parsed: VendorID=0x{:08X}, data={}
}