zaber.motion.ascii.Axis Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of motion-library Show documentation
Show all versions of motion-library Show documentation
A library that aims to provide easy-to-use API for communication with Zaber devices using Zaber ASCII Protocol.
// ===== THIS FILE IS GENERATED FROM A TEMPLATE ===== //
// ============== DO NOT EDIT DIRECTLY ============== //
package zaber.motion.ascii;
import zaber.motion.Units;
import zaber.motion.Measurement;
import zaber.motion.protobufs.Main;
import zaber.motion.gateway.Call;
import zaber.motion.exceptions.MotionLibException;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.concurrent.ExecutionException;
/**
* Represents an axis of motion associated with a device.
*/
public class Axis {
private Device device;
/**
* @return Device that controls this axis.
*/
public Device getDevice() {
return this.device;
}
private int axisNumber;
/**
* @return The axis number identifies the axis on the device.
* The first axis has the number one.
*/
public int getAxisNumber() {
return this.axisNumber;
}
private AxisSettings settings;
/**
* @return Settings and properties of this axis.
*/
public AxisSettings getSettings() {
return this.settings;
}
private Warnings warnings;
/**
* @return Warnings and faults of this axis.
*/
public Warnings getWarnings() {
return this.warnings;
}
/**
* @return Identity of the axis.
*/
public AxisIdentity getIdentity() {
return this.retrieveIdentity();
}
/**
* @return Unique ID of the peripheral hardware.
*/
public int getPeripheralId() {
return this.getIdentity().getPeripheralId();
}
/**
* @return Name of the peripheral.
*/
public String getPeripheralName() {
return this.getIdentity().getPeripheralName();
}
/**
* @return Indicates whether the axis is a peripheral or part of an integrated device.
*/
public boolean getIsPeripheral() {
return this.getIdentity().getIsPeripheral();
}
/**
* @return Determines the type of an axis and units it accepts.
*/
public AxisType getAxisType() {
return this.getIdentity().getAxisType();
}
public Axis(
Device device, int axisNumber) {
this.device = device;
this.axisNumber = axisNumber;
this.settings = new AxisSettings(this);
this.warnings = new Warnings(device, axisNumber);
}
/**
* Homes axis. Axis returns to its homing position.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture homeAsync(
boolean waitUntilIdle) {
Main.DeviceHomeRequest.Builder builder = Main.DeviceHomeRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setWaitUntilIdle(waitUntilIdle);
return Call.callAsync("device/home", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Homes axis. Axis returns to its homing position.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture homeAsync() {
return homeAsync(true);
}
/**
* Homes axis. Axis returns to its homing position.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
*/
public void home(
boolean waitUntilIdle) {
try {
homeAsync(waitUntilIdle).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Homes axis. Axis returns to its homing position.
*/
public void home() {
home(true);
}
/**
* Stops ongoing axis movement. Decelerates until zero speed.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture stopAsync(
boolean waitUntilIdle) {
Main.DeviceStopRequest.Builder builder = Main.DeviceStopRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setWaitUntilIdle(waitUntilIdle);
return Call.callAsync("device/stop", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Stops ongoing axis movement. Decelerates until zero speed.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture stopAsync() {
return stopAsync(true);
}
/**
* Stops ongoing axis movement. Decelerates until zero speed.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
*/
public void stop(
boolean waitUntilIdle) {
try {
stopAsync(waitUntilIdle).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Stops ongoing axis movement. Decelerates until zero speed.
*/
public void stop() {
stop(true);
}
/**
* Parks the axis in anticipation of turning the power off.
* It can later be powered on, unparked, and moved without first having to home it.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture parkAsync() {
Main.DeviceParkRequest.Builder builder = Main.DeviceParkRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
return Call.callAsync("device/park", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Parks the axis in anticipation of turning the power off.
* It can later be powered on, unparked, and moved without first having to home it.
*/
public void park() {
try {
parkAsync().get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Unparks axis. Axis will now be able to move.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture unparkAsync() {
Main.DeviceParkRequest.Builder builder = Main.DeviceParkRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
return Call.callAsync("device/unpark", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Unparks axis. Axis will now be able to move.
*/
public void unpark() {
try {
unparkAsync().get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Returns bool indicating whether the axis is parked or not.
* @return A CompletableFuture that can be completed to get the result:
* True if the axis is currently parked. False otherwise.
*/
public CompletableFuture isParkedAsync() {
Main.DeviceParkRequest.Builder builder = Main.DeviceParkRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
CompletableFuture response = Call.callAsync(
"device/is_parked",
builder.build(),
Main.DeviceIsParkedResponse.parser());
return response
.thenApply(r -> r.getIsParked());
}
/**
* Returns bool indicating whether the axis is parked or not.
* @return True if the axis is currently parked. False otherwise.
*/
public boolean isParked() {
try {
return isParkedAsync().get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Waits until axis stops moving.
* @param throwErrorOnFault Determines whether to throw error when fault is observed.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture waitUntilIdleAsync(
boolean throwErrorOnFault) {
Main.DeviceWaitUntilIdleRequest.Builder builder = Main.DeviceWaitUntilIdleRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setThrowErrorOnFault(throwErrorOnFault);
return Call.callAsync("device/wait_until_idle", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Waits until axis stops moving.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture waitUntilIdleAsync() {
return waitUntilIdleAsync(true);
}
/**
* Waits until axis stops moving.
* @param throwErrorOnFault Determines whether to throw error when fault is observed.
*/
public void waitUntilIdle(
boolean throwErrorOnFault) {
try {
waitUntilIdleAsync(throwErrorOnFault).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Waits until axis stops moving.
*/
public void waitUntilIdle() {
waitUntilIdle(true);
}
/**
* Returns bool indicating whether the axis is executing a motion command.
* @return A CompletableFuture that can be completed to get the result:
* True if the axis is currently executing a motion command.
*/
public CompletableFuture isBusyAsync() {
Main.DeviceIsBusyRequest.Builder builder = Main.DeviceIsBusyRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
CompletableFuture response = Call.callAsync(
"device/is_busy",
builder.build(),
Main.DeviceIsBusyResponse.parser());
return response
.thenApply(r -> r.getIsBusy());
}
/**
* Returns bool indicating whether the axis is executing a motion command.
* @return True if the axis is currently executing a motion command.
*/
public boolean isBusy() {
try {
return isBusyAsync().get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Move axis to absolute position.
* @param position Absolute position.
* @param unit Units of position.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveAbsoluteAsync(
double position, Units unit, boolean waitUntilIdle) {
Main.DeviceMoveRequest.Builder builder = Main.DeviceMoveRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setType(Main.DeviceMoveRequest.MoveType.ABS);
builder = builder.setArg(position);
builder = builder.setUnit(unit.getName());
builder = builder.setWaitUntilIdle(waitUntilIdle);
return Call.callAsync("device/move", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Move axis to absolute position.
* @param position Absolute position.
* @param unit Units of position.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveAbsoluteAsync(
double position, Units unit) {
return moveAbsoluteAsync(position, unit, true);
}
/**
* Move axis to absolute position.
* @param position Absolute position.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveAbsoluteAsync(
double position) {
return moveAbsoluteAsync(position, Units.NATIVE, true);
}
/**
* Move axis to absolute position.
* @param position Absolute position.
* @param unit Units of position.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
*/
public void moveAbsolute(
double position, Units unit, boolean waitUntilIdle) {
try {
moveAbsoluteAsync(position, unit, waitUntilIdle).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Move axis to absolute position.
* @param position Absolute position.
* @param unit Units of position.
*/
public void moveAbsolute(
double position, Units unit) {
moveAbsolute(position, unit, true);
}
/**
* Move axis to absolute position.
* @param position Absolute position.
*/
public void moveAbsolute(
double position) {
moveAbsolute(position, Units.NATIVE, true);
}
/**
* Moves the axis to the maximum position as specified by limit.max.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveMaxAsync(
boolean waitUntilIdle) {
Main.DeviceMoveRequest.Builder builder = Main.DeviceMoveRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setType(Main.DeviceMoveRequest.MoveType.MAX);
builder = builder.setWaitUntilIdle(waitUntilIdle);
return Call.callAsync("device/move", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Moves the axis to the maximum position as specified by limit.max.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveMaxAsync() {
return moveMaxAsync(true);
}
/**
* Moves the axis to the maximum position as specified by limit.max.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
*/
public void moveMax(
boolean waitUntilIdle) {
try {
moveMaxAsync(waitUntilIdle).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Moves the axis to the maximum position as specified by limit.max.
*/
public void moveMax() {
moveMax(true);
}
/**
* Moves the axis to the minimum position as specified by limit.min.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveMinAsync(
boolean waitUntilIdle) {
Main.DeviceMoveRequest.Builder builder = Main.DeviceMoveRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setType(Main.DeviceMoveRequest.MoveType.MIN);
builder = builder.setWaitUntilIdle(waitUntilIdle);
return Call.callAsync("device/move", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Moves the axis to the minimum position as specified by limit.min.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveMinAsync() {
return moveMinAsync(true);
}
/**
* Moves the axis to the minimum position as specified by limit.min.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
*/
public void moveMin(
boolean waitUntilIdle) {
try {
moveMinAsync(waitUntilIdle).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Moves the axis to the minimum position as specified by limit.min.
*/
public void moveMin() {
moveMin(true);
}
/**
* Move axis to position relative to current position.
* @param position Relative position.
* @param unit Units of position.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveRelativeAsync(
double position, Units unit, boolean waitUntilIdle) {
Main.DeviceMoveRequest.Builder builder = Main.DeviceMoveRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setType(Main.DeviceMoveRequest.MoveType.REL);
builder = builder.setArg(position);
builder = builder.setUnit(unit.getName());
builder = builder.setWaitUntilIdle(waitUntilIdle);
return Call.callAsync("device/move", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Move axis to position relative to current position.
* @param position Relative position.
* @param unit Units of position.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveRelativeAsync(
double position, Units unit) {
return moveRelativeAsync(position, unit, true);
}
/**
* Move axis to position relative to current position.
* @param position Relative position.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveRelativeAsync(
double position) {
return moveRelativeAsync(position, Units.NATIVE, true);
}
/**
* Move axis to position relative to current position.
* @param position Relative position.
* @param unit Units of position.
* @param waitUntilIdle Determines whether function should return after the movement is finished or just started.
*/
public void moveRelative(
double position, Units unit, boolean waitUntilIdle) {
try {
moveRelativeAsync(position, unit, waitUntilIdle).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Move axis to position relative to current position.
* @param position Relative position.
* @param unit Units of position.
*/
public void moveRelative(
double position, Units unit) {
moveRelative(position, unit, true);
}
/**
* Move axis to position relative to current position.
* @param position Relative position.
*/
public void moveRelative(
double position) {
moveRelative(position, Units.NATIVE, true);
}
/**
* Begins to move axis at specified speed.
* @param velocity Movement velocity.
* @param unit Units of velocity.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveVelocityAsync(
double velocity, Units unit) {
Main.DeviceMoveRequest.Builder builder = Main.DeviceMoveRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setType(Main.DeviceMoveRequest.MoveType.VEL);
builder = builder.setArg(velocity);
builder = builder.setUnit(unit.getName());
return Call.callAsync("device/move", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Begins to move axis at specified speed.
* @param velocity Movement velocity.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture moveVelocityAsync(
double velocity) {
return moveVelocityAsync(velocity, Units.NATIVE);
}
/**
* Begins to move axis at specified speed.
* @param velocity Movement velocity.
* @param unit Units of velocity.
*/
public void moveVelocity(
double velocity, Units unit) {
try {
moveVelocityAsync(velocity, unit).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Begins to move axis at specified speed.
* @param velocity Movement velocity.
*/
public void moveVelocity(
double velocity) {
moveVelocity(velocity, Units.NATIVE);
}
/**
* Returns current axis position.
* @param unit Units of position.
* @return A CompletableFuture that can be completed to get the result:
* Axis position.
*/
public CompletableFuture getPositionAsync(
Units unit) {
Main.DeviceGetSettingRequest.Builder builder = Main.DeviceGetSettingRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setSetting("pos");
builder = builder.setUnit(unit.getName());
CompletableFuture response = Call.callAsync(
"device/get_setting",
builder.build(),
Main.DeviceGetSettingResponse.parser());
return response
.thenApply(r -> r.getValue());
}
/**
* Returns current axis position.
* @return A CompletableFuture that can be completed to get the result:
* Axis position.
*/
public CompletableFuture getPositionAsync() {
return getPositionAsync(Units.NATIVE);
}
/**
* Returns current axis position.
* @param unit Units of position.
* @return Axis position.
*/
public double getPosition(
Units unit) {
try {
return getPositionAsync(unit).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Returns current axis position.
* @return Axis position.
*/
public double getPosition() {
return getPosition(Units.NATIVE);
}
/**
* Sends a generic ASCII command to this axis.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @param checkErrors Controls whether to throw an exception when the device rejects the command.
* @param timeout The timeout, in milliseconds, for a device to respond to the command.
* Overrides the connection default request timeout.
* @return A CompletableFuture that can be completed to get the result:
* A response to the command.
*/
public CompletableFuture genericCommandAsync(
String command, boolean checkErrors, int timeout) {
Main.GenericCommandRequest.Builder builder = Main.GenericCommandRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setCommand(command);
builder = builder.setCheckErrors(checkErrors);
builder = builder.setTimeout(timeout);
CompletableFuture response = Call.callAsync(
"interface/generic_command",
builder.build(),
Main.GenericCommandResponse.parser());
return response
.thenApply(r -> Response.fromProtobuf(r));
}
/**
* Sends a generic ASCII command to this axis.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @param checkErrors Controls whether to throw an exception when the device rejects the command.
* @return A CompletableFuture that can be completed to get the result:
* A response to the command.
*/
public CompletableFuture genericCommandAsync(
String command, boolean checkErrors) {
return genericCommandAsync(command, checkErrors, 0);
}
/**
* Sends a generic ASCII command to this axis.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @return A CompletableFuture that can be completed to get the result:
* A response to the command.
*/
public CompletableFuture genericCommandAsync(
String command) {
return genericCommandAsync(command, true, 0);
}
/**
* Sends a generic ASCII command to this axis.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @param checkErrors Controls whether to throw an exception when the device rejects the command.
* @param timeout The timeout, in milliseconds, for a device to respond to the command.
* Overrides the connection default request timeout.
* @return A response to the command.
*/
public Response genericCommand(
String command, boolean checkErrors, int timeout) {
try {
return genericCommandAsync(command, checkErrors, timeout).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Sends a generic ASCII command to this axis.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @param checkErrors Controls whether to throw an exception when the device rejects the command.
* @return A response to the command.
*/
public Response genericCommand(
String command, boolean checkErrors) {
return genericCommand(command, checkErrors, 0);
}
/**
* Sends a generic ASCII command to this axis.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @return A response to the command.
*/
public Response genericCommand(
String command) {
return genericCommand(command, true, 0);
}
/**
* Sends a generic ASCII command to this axis and expect multiple responses.
* Responses are returned in order of arrival.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @param checkErrors Controls whether to throw an exception when a device rejects the command.
* @param timeout The timeout, in milliseconds, for a device to respond to the command.
* Overrides the connection default request timeout.
* @return A CompletableFuture that can be completed to get the result:
* All responses to the command.
*/
public CompletableFuture genericCommandMultiResponseAsync(
String command, boolean checkErrors, int timeout) {
Main.GenericCommandRequest.Builder builder = Main.GenericCommandRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setCommand(command);
builder = builder.setCheckErrors(checkErrors);
builder = builder.setTimeout(timeout);
CompletableFuture response = Call.callAsync(
"interface/generic_command_multi_response",
builder.build(),
Main.GenericCommandResponseCollection.parser());
return response
.thenApply(r -> r.getResponsesList().stream()
.map(resp -> Response.fromProtobuf(resp)).toArray(Response[]::new));
}
/**
* Sends a generic ASCII command to this axis and expect multiple responses.
* Responses are returned in order of arrival.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @param checkErrors Controls whether to throw an exception when a device rejects the command.
* @return A CompletableFuture that can be completed to get the result:
* All responses to the command.
*/
public CompletableFuture genericCommandMultiResponseAsync(
String command, boolean checkErrors) {
return genericCommandMultiResponseAsync(command, checkErrors, 0);
}
/**
* Sends a generic ASCII command to this axis and expect multiple responses.
* Responses are returned in order of arrival.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @return A CompletableFuture that can be completed to get the result:
* All responses to the command.
*/
public CompletableFuture genericCommandMultiResponseAsync(
String command) {
return genericCommandMultiResponseAsync(command, true, 0);
}
/**
* Sends a generic ASCII command to this axis and expect multiple responses.
* Responses are returned in order of arrival.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @param checkErrors Controls whether to throw an exception when a device rejects the command.
* @param timeout The timeout, in milliseconds, for a device to respond to the command.
* Overrides the connection default request timeout.
* @return All responses to the command.
*/
public Response[] genericCommandMultiResponse(
String command, boolean checkErrors, int timeout) {
try {
return genericCommandMultiResponseAsync(command, checkErrors, timeout).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Sends a generic ASCII command to this axis and expect multiple responses.
* Responses are returned in order of arrival.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @param checkErrors Controls whether to throw an exception when a device rejects the command.
* @return All responses to the command.
*/
public Response[] genericCommandMultiResponse(
String command, boolean checkErrors) {
return genericCommandMultiResponse(command, checkErrors, 0);
}
/**
* Sends a generic ASCII command to this axis and expect multiple responses.
* Responses are returned in order of arrival.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @return All responses to the command.
*/
public Response[] genericCommandMultiResponse(
String command) {
return genericCommandMultiResponse(command, true, 0);
}
/**
* Sends a generic ASCII command to this axis without expecting a response and without adding a message ID
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture genericCommandNoResponseAsync(
String command) {
Main.GenericCommandRequest.Builder builder = Main.GenericCommandRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setCommand(command);
return Call.callAsync("interface/generic_command_no_response", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Sends a generic ASCII command to this axis without expecting a response and without adding a message ID
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param command Command and its parameters.
*/
public void genericCommandNoResponse(
String command) {
try {
genericCommandNoResponseAsync(command).get();
} catch (ExecutionException e) {
if (e.getCause() instanceof MotionLibException) {
throw (MotionLibException) e.getCause();
} else {
throw new MotionLibException(e.getCause());
}
} catch (InterruptedException e) {
throw new MotionLibException(e);
}
}
/**
* Formats parameters into a command and performs unit conversions.
* Parameters in the command template are denoted by a question mark.
* Command returned is only valid for this axis and this device.
* For more information refer to: [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_commands).
* @param commandTemplate Template of a command to prepare. Parameters are denoted by question marks.
* @param parameters Variable number of command parameters.
* @return Command with converted parameters.
*/
public String prepareCommand(
String commandTemplate, Measurement... parameters) {
Main.PrepareCommandRequest.Builder builder = Main.PrepareCommandRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
builder = builder.setCommandTemplate(commandTemplate);
builder = builder.addAllParameters(Arrays.asList(parameters).stream()
.map(p -> Measurement.toProtobuf(p)).collect(Collectors.toList()));
Main.PrepareCommandResponse response = Call.callSync(
"device/prepare_command",
builder.build(),
Main.PrepareCommandResponse.parser());
return response.getCommand();
}
/**
* Returns a string that represents the axis.
* @return A string that represents the axis.
*/
public String toString() {
Main.ToStringRequest.Builder builder = Main.ToStringRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
Main.ToStringResponse response = Call.callSync(
"device/axis_to_string",
builder.build(),
Main.ToStringResponse.parser());
return response.getToStr();
}
/**
* Returns identity.
* @return Axis identity.
*/
private AxisIdentity retrieveIdentity() {
Main.DeviceGetAxisIdentityRequest.Builder builder = Main.DeviceGetAxisIdentityRequest.newBuilder();
builder = builder.setInterfaceId(getDevice().getConnection().getInterfaceId());
builder = builder.setDevice(getDevice().getDeviceAddress());
builder = builder.setAxis(getAxisNumber());
Main.DeviceGetAxisIdentityResponse response = Call.callSync(
"device/get_axis_identity",
builder.build(),
Main.DeviceGetAxisIdentityResponse.parser());
return AxisIdentity.fromProtobuf(response.getIdentity());
}
}