zaber.motion.ascii.Warnings 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.gateway.Call;
import zaber.motion.protobufs.Main;
import zaber.motion.exceptions.MotionLibException;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
/**
* Class used to check and reset warnings and faults on device or axis.
*/
public class Warnings {
private Device device;
private int axisNumber;
public Warnings(
Device device, int axisNumber) {
this.device = device;
this.axisNumber = axisNumber;
}
/**
* Returns current warnings and faults on axis or device.
* @return A CompletableFuture that can be completed to get the result:
* Retrieved warnings and faults. Refer to WarningFlags to check a particular flag.
*/
public CompletableFuture> getFlagsAsync() {
Main.DeviceGetWarningsRequest.Builder builder = Main.DeviceGetWarningsRequest.newBuilder();
builder = builder.setInterfaceId(this.device.getConnection().getInterfaceId());
builder = builder.setDevice(this.device.getDeviceAddress());
builder = builder.setAxis(this.axisNumber);
builder = builder.setClear(false);
CompletableFuture response = Call.callAsync(
"device/get_warnings",
builder.build(),
Main.DeviceGetWarningsResponse.parser());
return response
.thenApply(r -> new HashSet(r.getFlagsList()));
}
/**
* Returns current warnings and faults on axis or device.
* @return Retrieved warnings and faults. Refer to WarningFlags to check a particular flag.
*/
public Set getFlags() {
try {
return getFlagsAsync().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);
}
}
/**
* Clears (acknowledges) current warnings and faults on axis or device and returns them.
* @return A CompletableFuture that can be completed to get the result:
* Warnings and faults before clearing. Refer to WarningFlags to check a particular flag.
*/
public CompletableFuture> clearFlagsAsync() {
Main.DeviceGetWarningsRequest.Builder builder = Main.DeviceGetWarningsRequest.newBuilder();
builder = builder.setInterfaceId(this.device.getConnection().getInterfaceId());
builder = builder.setDevice(this.device.getDeviceAddress());
builder = builder.setAxis(this.axisNumber);
builder = builder.setClear(true);
CompletableFuture response = Call.callAsync(
"device/get_warnings",
builder.build(),
Main.DeviceGetWarningsResponse.parser());
return response
.thenApply(r -> new HashSet(r.getFlagsList()));
}
/**
* Clears (acknowledges) current warnings and faults on axis or device and returns them.
* @return Warnings and faults before clearing. Refer to WarningFlags to check a particular flag.
*/
public Set clearFlags() {
try {
return clearFlagsAsync().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);
}
}
}