zaber.motion.binary.DeviceSettings 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.binary;
import zaber.motion.Units;
import zaber.motion.protobufs.Main;
import zaber.motion.gateway.Call;
import zaber.motion.exceptions.MotionLibException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
/**
* Class providing access to various device settings and properties.
*/
public class DeviceSettings {
private Device device;
public DeviceSettings(
Device device) {
this.device = device;
}
/**
* Returns any device setting or property.
* @param setting Setting to get.
* @param unit Units of setting.
* @return A CompletableFuture that can be completed to get the result:
* Setting value.
*/
public CompletableFuture getAsync(
BinarySettings setting, Units unit) {
Main.BinaryDeviceGetSettingRequest.Builder builder = Main.BinaryDeviceGetSettingRequest.newBuilder();
builder = builder.setInterfaceId(this.device.getConnection().getInterfaceId());
builder = builder.setDevice(this.device.getDeviceAddress());
builder = builder.setSetting(setting.getValue());
builder = builder.setUnit(unit.getName());
CompletableFuture response = Call.callAsync(
"binary/device/get_setting",
builder.build(),
Main.BinaryDeviceGetSettingResponse.parser());
return response
.thenApply(r -> r.getValue());
}
/**
* Returns any device setting or property.
* @param setting Setting to get.
* @return A CompletableFuture that can be completed to get the result:
* Setting value.
*/
public CompletableFuture getAsync(
BinarySettings setting) {
return getAsync(setting, Units.NATIVE);
}
/**
* Returns any device setting or property.
* @param setting Setting to get.
* @param unit Units of setting.
* @return Setting value.
*/
public double get(
BinarySettings setting, Units unit) {
try {
return getAsync(setting, 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 any device setting or property.
* @param setting Setting to get.
* @return Setting value.
*/
public double get(
BinarySettings setting) {
return get(setting, Units.NATIVE);
}
/**
* Sets any device setting.
* @param setting Setting to set.
* @param value Value of the setting.
* @param unit Units of setting.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture setAsync(
BinarySettings setting, double value, Units unit) {
Main.BinaryDeviceSetSettingRequest.Builder builder = Main.BinaryDeviceSetSettingRequest.newBuilder();
builder = builder.setInterfaceId(this.device.getConnection().getInterfaceId());
builder = builder.setDevice(this.device.getDeviceAddress());
builder = builder.setSetting(setting.getValue());
builder = builder.setValue(value);
builder = builder.setUnit(unit.getName());
return Call.callAsync("binary/device/set_setting", builder.build(), null)
.thenApply(r -> (Void) null);
}
/**
* Sets any device setting.
* @param setting Setting to set.
* @param value Value of the setting.
* @return A CompletableFuture that can be completed to know when the work is complete.
*/
public CompletableFuture setAsync(
BinarySettings setting, double value) {
return setAsync(setting, value, Units.NATIVE);
}
/**
* Sets any device setting.
* @param setting Setting to set.
* @param value Value of the setting.
* @param unit Units of setting.
*/
public void set(
BinarySettings setting, double value, Units unit) {
try {
setAsync(setting, value, 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);
}
}
/**
* Sets any device setting.
* @param setting Setting to set.
* @param value Value of the setting.
*/
public void set(
BinarySettings setting, double value) {
set(setting, value, Units.NATIVE);
}
}