VoE (Vendor over EtherCAT)
The VoE protocol carries vendor-specific data and follows 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().
Properties
| Category | Property | Type | Read/write | Description |
|---|---|---|---|---|
| Default parameters | defaultTimeoutMs() / defaultTimeoutMs(int) | int | read/write | Default timeout (milliseconds), default 500 |
| Constant | VOE_HEADER_SIZE | int | read-only | VoE header size constant (6 bytes: VendorID 4 + VendorType 2, static final) |
| Capability detection | isSupported() | boolean | read-only | Whether the slave supports the VoE mailbox protocol; returns false when the capability is unknown (fail-closed) |
| supportState() | Boolean | read-only | Capability tri-state: TRUE=supported, FALSE=confirmed unsupported, null=unknown | |
| isSupportKnown() | boolean | read-only | Whether the capability conclusion is known (supportState() != null) |
Basic operations
send(int vendorId, short vendorType, byte[] data, int timeoutMs)
public boolean send(int vendorId, short vendorType, byte[] data, int timeoutMs)
public boolean send(int vendorId, short vendorType, byte[] data)
Sends VoE data to the slave (the SDK fills in the VoE header, and the header and payload are sent together).
Parameters:
vendorId(int) — vendor ID (4 bytes, little-endian)vendorType(short) — vendor type (2 bytes, little-endian)data(byte[]) — data to send; may benull, in which case a 0-length payload is senttimeoutMs(int) — timeout (milliseconds, optional); when omitted,defaultTimeoutMs()is used (default 500)
Returns:
boolean—trueon success;falseon failure
Throws:
- A runtime exception thrown by the underlying call is propagated as is and is not swallowed into
false
The failure reason is available from getLastStatus() / getLastErrorCode() (for example TIMEOUT).
Example:
slave.voe().send(0x00000002, (short) 0x0001, new byte[] { 0x01, 0x02, 0x03 });
receive(int timeoutMs)
public VoEResponse receive(int timeoutMs)
public VoEResponse receive()
Receives VoE data from the slave (the vendor header is parsed out).
Parameters:
timeoutMs(int) — timeout (milliseconds, optional); when omitted,defaultTimeoutMs()is used (default 500)
Returns:
VoEResponse— VoE response object (Datais nevernull; length 0 when there is no payload); a receive failure or a timeout returnsnull
Throws:
- A runtime exception thrown by the underlying call is propagated as is and is not swallowed into
null
sendAndReceive(int vendorId, short vendorType, byte[] data, int timeoutMs)
public VoEResponse sendAndReceive(int vendorId, short vendorType, byte[] data, int timeoutMs)
public VoEResponse sendAndReceive(int vendorId, short vendorType, byte[] data)
Sends VoE data and waits for one response (equivalent to send(...) first, then receive(timeoutMs) on success).
Parameters:
vendorId(int) — vendor ID (4 bytes, little-endian)vendorType(short) — vendor type (2 bytes, little-endian)data(byte[]) — data to send; may benulltimeoutMs(int) — timeout (milliseconds, optional); shared by the send and the receive stage; when omitted,defaultTimeoutMs()is used
Returns:
VoEResponse— VoE response object; a send failure, a receive failure or a timeout all returnnull
Throws:
- A runtime exception thrown by the underlying call is propagated as is
Example:
VoE.VoEResponse response = slave.voe().sendAndReceive(0x00000002, (short) 0x0001, new byte[] { 0x10 });
if (response != null) {
System.out.printf("厂商ID: 0x%08X%n", response.VendorId); // Vendor ID: 0x%08X%n
System.out.println("数据: " + response.toHexString()); // Data: {response.toHexString()}
}
Related structures:
VoEResponse
public static class VoEResponse {
public int VendorId; // vendor ID
public short VendorType; // vendor type
public byte[] Data; // response data
public int dataLength(); // payload byte count
public String toHexString(); // format the payload as hexadecimal (e.g. "01 02 03")
public String toString(); // full description
}
| Field | Type | Description |
|---|---|---|
| VendorId | int | Vendor ID in the frame header (4 bytes, parsed as little-endian) |
| VendorType | short | Vendor type in the frame header (2 bytes, parsed as little-endian) |
| Data | byte[] | Payload bytes, never null (length 0 when there is no payload) |
| Method | Returns | Description |
|---|---|---|
dataLength() | int | Payload byte count |
toHexString() | String | Outputs the payload in hexadecimal with a single space between bytes (for example "01 02 03"); an empty string when there is no payload |
toString() | String | VoE Response: VendorID=0x…, VendorType=0x…, DataLength=… |
Asynchronous send and receive
public CompletableFuture<Boolean> sendAsync(int vendorId, short vendorType, byte[] data, int timeoutMs)
public CompletableFuture<Boolean> sendAsync(int vendorId, short vendorType, byte[] data)
public CompletableFuture<VoEResponse> receiveAsync(int timeoutMs)
public CompletableFuture<VoEResponse> receiveAsync()
public CompletableFuture<VoEResponse> sendAndReceiveAsync(int vendorId, short vendorType, byte[] data, int timeoutMs)
public CompletableFuture<VoEResponse> sendAndReceiveAsync(int vendorId, short vendorType, byte[] data)
Asynchronous forms of the three synchronous methods above, with parameters and return semantics in one-to-one correspondence. The only difference is how a failure is expressed: the synchronous versions fold a failure into false / null, while the asynchronous versions make the CompletableFuture complete exceptionallyVoEProtocolException with **** (the result of a successful sendAsync is always true).
The executing thread is determined by defaultExecutor() (common thread pool by default; a subclass can override it to use a custom thread pool).
Example:
slave.voe().sendAndReceiveAsync(0x00000002, (short) 0x0001, new byte[] { 0x10 })
.thenAccept(r -> System.out.println("收到 " + r.dataLength() + " 字节")) // Received {received.length} bytes
.exceptionally(e -> { System.out.println("VoE 失败: " + e.getMessage()); return null; }); // VoE failed:
VoEProtocolException
public static class VoEProtocolException extends RuntimeException
Runtime exception thrown when an asynchronous send/receive fails. It appears only in the CompletableFuture of the three asynchronous methods above; the synchronous methods do not use it to express a failure (they return false / null).
Raw frame operations
sendRaw(byte[] frameData, int timeoutMs)
public boolean sendRaw(byte[] frameData, int timeoutMs)
public boolean sendRaw(byte[] frameData)
Sends a raw VoE frame (the caller assembles the frame format, including the VoE header). Use it when the frame format already carries a complete vendor header; otherwise use send.
Parameters:
frameData(byte[]) — raw frame data (must be non-empty)timeoutMs(int) — timeout (milliseconds, optional); when omitted,defaultTimeoutMs()is used
Returns:
boolean—trueon success; an empty frame (nullor length 0) returnsfalse(recorded as an invalid argument, not a successful send); a send failure likewise returnsfalse, andgetLastStatus()tells them apart
receiveRaw(int timeoutMs)
public byte[] receiveRaw(int timeoutMs)
public byte[] receiveRaw()
Receives a raw VoE frame (the vendor header is not parsed).
Parameters:
timeoutMs(int) — timeout (milliseconds, optional); when omitted,defaultTimeoutMs()is used
Returns:
byte[]— raw frame data; a failure, a timeout or an empty frame returnsnull. When an empty frame is received the transaction itself succeeded; usegetLastStatus()to tell that apart from a real failure.
sendRawAndReceive(byte[] frameData, int timeoutMs)
public byte[] sendRawAndReceive(byte[] frameData, int timeoutMs)
public byte[] sendRawAndReceive(byte[] frameData)
Sends a raw frame and waits for the response (sendRaw first, then receiveRaw on success).
Parameters:
frameData(byte[]) — raw frame data (must be non-empty)timeoutMs(int) — timeout (milliseconds, optional); shared by the send and the receive stage; when omitted,defaultTimeoutMs()is used
Returns:
byte[]— raw frame data of the response; a send failure, a receive failure, an empty frame or an internal exception all returnnull(an internal exception is logged, and thennullis returned without propagating it)
Helper methods
buildVoEFrame(int vendorId, short vendorType, byte[] data)
public byte[] buildVoEFrame(int vendorId, short vendorType, byte[] data)
Builds a standard VoE frame (VoE header + payload). The header layout is fixed: VendorID 4 bytes + VendorType 2 bytes, both little-endian.
Parameters:
vendorId(int) — vendor IDvendorType(short) — vendor typedata(byte[]) — payload (may benull, in which case only the header is produced)
Returns:
byte[]— the built VoE frame; its length is alwaysVOE_HEADER_SIZE + data 长度
parseVoEFrame(byte[] frame)
public VoEResponse parseVoEFrame(byte[] frame)
Parses the VoE frame header (the first 6 bytes: VendorID 4 + VendorType 2, little-endian) and puts the remaining bytes into Data as the payload.
Parameters:
frame(byte[]) — VoE frame data
Returns:
VoEResponse— the parsed VoE response object; returnsframewhennullisVOE_HEADER_SIZEor shorter thannull(a parse failure does not throw)
Notification listening
VoE also supports vendor frames pushed by the slave on its own initiative (vendor-initiated notifications), which coexist with the request/response send and receive above.
public void addNotificationListener(NotificationListener listener)
public void removeNotificationListener(NotificationListener listener)
public boolean startNotificationListener()
public void stopNotificationListener()
public static void stopAllListeners(short masterIndex)
public static boolean isListenerRunning(short masterIndex)
| Method | Description |
|---|---|
addNotificationListener(NotificationListener) / removeNotificationListener(NotificationListener) | Registers / unregisters the callback; a null argument is ignored |
startNotificationListener() | Starts the listener thread and subscribes to this slave (vendorId / vendorType wildcard). Returns true on success; returns false on failure and records it in getLastStatus() / getLastErrorCode() |
stopNotificationListener() | Unregisters this instance's subscription and clears this instance's callbacks |
stopAllListeners(short masterIndex) | Static method that stops the listener thread of the given master; other masters are unaffected. Listener threads are per master, so a real master index must be passed and a constant placeholder must not be used |
isListenerRunning(short masterIndex) | Static method that queries whether the listener thread of the given master is running; returns false when it cannot be determined |
The callback interface has a single method: void onNotification(VoENotificationEventArgs args). An exception thrown by one callback does not interrupt dispatch and does not affect other subscribers.
Related structures:
VoENotificationEventArgs
public static class VoENotificationEventArgs {
public final short slaveIndex; // source slave of the notification
public final int vendorId; // vendor ID
public final short vendorType; // vendor type
public final byte[] data; // payload (never null; length 0 when there is no payload)
public final long timestampUnixMs; // event generation time (Unix milliseconds)
}
| Field | Type | Description |
|---|---|---|
| slaveIndex | short | Source slave of the notification |
| vendorId | int | Vendor ID |
| vendorType | short | Vendor type |
| data | byte[] | Payload bytes, never null; does not include the VoE header, so unpack it according to the vendor protocol |
| timestampUnixMs | long | Event generation time (Unix milliseconds) |
toString() outputs VoE Notification: Slave=…, VendorID=0x…, VendorType=0x…, DataLen=….
dispatchNotification(VoENotificationEventArgs args)
protected void dispatchNotification(VoENotificationEventArgs args)
Notification dispatch entry point: after a vendor-pushed frame arrives, the event is handed to every registered NotificationListener in registration order. An exception thrown by a single listener does not interrupt dispatch and does not affect the other listeners.
The SDK calls this method when a notification arrives; the application side must not call it manually. To receive notifications, register a listener with addNotificationListener(...).
Parameters:
args(VoENotificationEventArgs) — the event object to dispatch
Returns: None (void).
Mailbox statistics
VoE implements the unified IMailboxProtocol interface. As of 2.5.x, getStatistics() / resetStatistics() return real statistics (earlier versions returned an empty placeholder snapshot).
| Category | Method | Type | Read/write | Description |
|---|---|---|---|---|
| Protocol identification | getProtocolType() | byte | read-only | Protocol type constant (VoE=0x0F) |
| getProtocolName() | String | read-only | Protocol name ("VoE") | |
| isSupported() | boolean | read-only | Whether the slave supports this protocol; returns false when the capability is unknown (fail-closed) | |
| supportState() | Boolean | read-only | Capability tri-state: TRUE=supported, FALSE=confirmed unsupported, null=unknown | |
| isSupportKnown() | boolean | read-only | Whether the capability conclusion is known (supportState() != null) | |
| Transaction status | getLastStatus() | MailboxStatus | read-only | Unified status of the most recent mailbox transaction |
| getLastErrorCode() | long | read-only | Most recent protocol-layer error code (0=no error) | |
| Statistics | getStatistics() | MailboxStatistics | read-only | Mailbox statistics snapshot |
| resetStatistics() | void | write-only | Resets the mailbox statistics counters |
getLastStatus()— unified status of the most recent mailbox transaction; initiallyPENDING. Everysend/receive/sendRaw/receiveRaw/ notification subscription updates it.getLastErrorCode()— most recent protocol-layer error code;0= no error, a value other than 0 on failure; use it together with the status code to locate the cause.resetStatistics()— resets the statistics counters, and at the same time resets the status toPENDINGand the error code to0.getStatistics()— mailbox statistics snapshot (an empty snapshot when the statistics capability is unavailable).
The MailboxStatus enum values and the MailboxStatistics field table are in CoE · MailboxStatus enum and CoE · Mailbox statistics (the seven mailbox protocols share the same set).
Full example
Vendor command exchange
VoE voe = slave.voe();
if (voe.isSupported()) {
VoE.VoEResponse response = voe.sendAndReceive(
0x00000002, (short) 0x0001,
new byte[] { 0x01, 0x00 }
);
if (response != null)
System.out.println(response.toString());
}
Bulk data transfer
VoE voe = slave.voe();
if (voe.isSupported()) {
byte[] payload = new byte[1024];
voe.send(0x00000002, (short) 0x1000, payload);
VoE.VoEResponse reply = voe.receive();
if (reply != null)
System.out.println("收到 " + reply.dataLength() + " 字节响应"); // Received a {reply.dataLength()}-byte response
}
Failures and handling
| Symptom | Cause | Handling |
|---|---|---|
send returns false | The slave does not accept the vendor data, or the mailbox rejects it / times out | Confirm the VendorID matches the slave and check isSupported(); use getLastStatus() to tell a timeout from a mailbox error |
sendAndReceive returns null | The send failed, or the slave did not respond within the timeout | Increase timeoutMs, or confirm the slave has implemented that VendorType |
receive returns null | No data was reported within the timeout | Extend the receive time appropriately, or switch to sendAndReceive |
sendRaw returns false | An empty frame was passed (invalid argument) or the send failed | First confirm the frame is not empty; then use getLastStatus() to tell an invalid argument from a timeout |
receiveRaw returns null | Timeout / failure, or an empty frame was received | Use getLastStatus() to tell "empty frame but a successful transaction" from a real failure |
The asynchronous method completes with VoEProtocolException | The corresponding synchronous call failed (false / null) | Handle it in exceptionally as a synchronous failure; do not treat it as a program error |
startNotificationListener returns false | The listener thread failed to start or the subscription failed | Check getLastStatus() / getLastErrorCode(); or switch to polling with receive |
isSupported() is false | The slave does not support VoE, or the capability is unknown (fail-closed) | Use supportState() to tell "unknown" from "confirmed unsupported"; when it is confirmed unsupported, switch to a protocol the slave supports |
After any failure, read getLastStatus() / getLastErrorCode() to locate the cause (an error code of 0 means no error); for the statistics view see getStatistics().