Skip to main content

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​

CategoryPropertyTypeRead/writeDescription
Default parametersdefaultTimeoutMs() / defaultTimeoutMs(int)intread/writeDefault timeout (milliseconds), default 500
ConstantVOE_HEADER_SIZEintread-onlyVoE header size constant (6 bytes: VendorID 4 + VendorType 2, static final)
Capability detectionisSupported()booleanread-onlyWhether the slave supports the VoE mailbox protocol; returns false when the capability is unknown (fail-closed)
supportState()Booleanread-onlyCapability tri-state: TRUE=supported, FALSE=confirmed unsupported, null=unknown
isSupportKnown()booleanread-onlyWhether 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 be null, in which case a 0-length payload is sent
  • timeoutMs (int) — timeout (milliseconds, optional); when omitted, defaultTimeoutMs() is used (default 500)

Returns:

  • boolean — true on success; false on 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 (Data is never null; length 0 when there is no payload); a receive failure or a timeout returns null

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 be null
  • timeoutMs (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 return null

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
}
FieldTypeDescription
VendorIdintVendor ID in the frame header (4 bytes, parsed as little-endian)
VendorTypeshortVendor type in the frame header (2 bytes, parsed as little-endian)
Databyte[]Payload bytes, never null (length 0 when there is no payload)
MethodReturnsDescription
dataLength()intPayload byte count
toHexString()StringOutputs the payload in hexadecimal with a single space between bytes (for example "01 02 03"); an empty string when there is no payload
toString()StringVoE 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 — true on success; an empty frame (null or length 0) returns false (recorded as an invalid argument, not a successful send); a send failure likewise returns false, and getLastStatus() 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 returns null. When an empty frame is received the transaction itself succeeded; use getLastStatus() 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 return null (an internal exception is logged, and then null is 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 ID
  • vendorType (short) — vendor type
  • data (byte[]) — payload (may be null, in which case only the header is produced)

Returns:

  • byte[] — the built VoE frame; its length is always VOE_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; returns frame when null is VOE_HEADER_SIZE or shorter than null (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)
MethodDescription
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)
}
FieldTypeDescription
slaveIndexshortSource slave of the notification
vendorIdintVendor ID
vendorTypeshortVendor type
databyte[]Payload bytes, never null; does not include the VoE header, so unpack it according to the vendor protocol
timestampUnixMslongEvent 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).

CategoryMethodTypeRead/writeDescription
Protocol identificationgetProtocolType()byteread-onlyProtocol type constant (VoE=0x0F)
getProtocolName()Stringread-onlyProtocol name ("VoE")
isSupported()booleanread-onlyWhether the slave supports this protocol; returns false when the capability is unknown (fail-closed)
supportState()Booleanread-onlyCapability tri-state: TRUE=supported, FALSE=confirmed unsupported, null=unknown
isSupportKnown()booleanread-onlyWhether the capability conclusion is known (supportState() != null)
Transaction statusgetLastStatus()MailboxStatusread-onlyUnified status of the most recent mailbox transaction
getLastErrorCode()longread-onlyMost recent protocol-layer error code (0=no error)
StatisticsgetStatistics()MailboxStatisticsread-onlyMailbox statistics snapshot
resetStatistics()voidwrite-onlyResets the mailbox statistics counters
  • getLastStatus() — unified status of the most recent mailbox transaction; initially PENDING. Every send / 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 to PENDING and the error code to 0.
  • 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​

SymptomCauseHandling
send returns falseThe slave does not accept the vendor data, or the mailbox rejects it / times outConfirm the VendorID matches the slave and check isSupported(); use getLastStatus() to tell a timeout from a mailbox error
sendAndReceive returns nullThe send failed, or the slave did not respond within the timeoutIncrease timeoutMs, or confirm the slave has implemented that VendorType
receive returns nullNo data was reported within the timeoutExtend the receive time appropriately, or switch to sendAndReceive
sendRaw returns falseAn empty frame was passed (invalid argument) or the send failedFirst confirm the frame is not empty; then use getLastStatus() to tell an invalid argument from a timeout
receiveRaw returns nullTimeout / failure, or an empty frame was receivedUse getLastStatus() to tell "empty frame but a successful transaction" from a real failure
The asynchronous method completes with VoEProtocolExceptionThe corresponding synchronous call failed (false / null)Handle it in exceptionally as a synchronous failure; do not treat it as a program error
startNotificationListener returns falseThe listener thread failed to start or the subscription failedCheck getLastStatus() / getLastErrorCode(); or switch to polling with receive
isSupported() is falseThe 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().