All Downloads are FREE. Search and download functionalities are using the official Maven repository.

zaber.motion.ascii.DeviceSettings Maven / Gradle / Ivy

Go to download

A library that aims to provide easy-to-use API for communication with Zaber devices using Zaber ASCII Protocol.

There is a newer version: 6.7.0
Show newest version
// ===== THIS FILE IS GENERATED FROM A TEMPLATE ===== //
// ============== DO NOT EDIT DIRECTLY ============== //

package zaber.motion.ascii;

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.
     * For more information refer to the [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_settings).
     * @param setting Name of the setting.
     * @param unit Units of setting.
     * @return A CompletableFuture that can be completed to get the result:
     * Setting value.
     */
    public CompletableFuture getAsync(
        String setting, Units unit) {
        Main.DeviceGetSettingRequest.Builder builder = Main.DeviceGetSettingRequest.newBuilder();
        builder = builder.setInterfaceId(this.device.getConnection().getInterfaceId());
        builder = builder.setDevice(this.device.getDeviceAddress());

        builder = builder.setSetting(setting);
        builder = builder.setUnit(unit.getName());
        CompletableFuture response = Call.callAsync(
            "device/get_setting",
            builder.build(),
            Main.DeviceGetSettingResponse.parser());
        return response
            .thenApply(r -> r.getValue());
    }

    /**
     * Returns any device setting or property.
     * For more information refer to the [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_settings).
     * @param setting Name of the setting.
     * @return A CompletableFuture that can be completed to get the result:
     * Setting value.
     */
    public CompletableFuture getAsync(
        String setting) {
        return getAsync(setting, Units.NATIVE);
    }

    /**
     * Returns any device setting or property.
     * For more information refer to the [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_settings).
     * @param setting Name of the setting.
     * @param unit Units of setting.
     * @return Setting value.
     */
    public double get(
        String 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.
     * For more information refer to the [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_settings).
     * @param setting Name of the setting.
     * @return Setting value.
     */
    public double get(
        String setting) {
        return get(setting, Units.NATIVE);
    }

    /**
     * Sets any device setting.
     * For more information refer to the [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_settings).
     * @param setting Name of the setting.
     * @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(
        String setting, double value, Units unit) {
        Main.DeviceSetSettingRequest.Builder builder = Main.DeviceSetSettingRequest.newBuilder();
        builder = builder.setInterfaceId(this.device.getConnection().getInterfaceId());
        builder = builder.setDevice(this.device.getDeviceAddress());

        builder = builder.setSetting(setting);
        builder = builder.setValue(value);
        builder = builder.setUnit(unit.getName());
        return Call.callAsync("device/set_setting", builder.build(), null)
            .thenApply(r -> (Void) null);
    }

    /**
     * Sets any device setting.
     * For more information refer to the [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_settings).
     * @param setting Name of the setting.
     * @param value Value of the setting.
     * @return A CompletableFuture that can be completed to know when the work is complete.
     */
    public CompletableFuture setAsync(
        String setting, double value) {
        return setAsync(setting, value, Units.NATIVE);
    }

    /**
     * Sets any device setting.
     * For more information refer to the [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_settings).
     * @param setting Name of the setting.
     * @param value Value of the setting.
     * @param unit Units of setting.
     */
    public void set(
        String 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.
     * For more information refer to the [ASCII Protocol Manual](https://www.zaber.com/protocol-manual#topic_settings).
     * @param setting Name of the setting.
     * @param value Value of the setting.
     */
    public void set(
        String setting, double value) {
        set(setting, value, Units.NATIVE);
    }

    /**
     * Convert arbitrary setting value to Zaber native units.
     * @param setting Name of the setting.
     * @param value Value of the setting in units specified by following argument.
     * @param unit Units of the value.
     * @return Setting value.
     */
    public double convertToNativeUnits(
        String setting, double value, Units unit) {
        Main.DeviceConvertSettingRequest.Builder builder = Main.DeviceConvertSettingRequest.newBuilder();
        builder = builder.setInterfaceId(this.device.getConnection().getInterfaceId());
        builder = builder.setDevice(this.device.getDeviceAddress());

        builder = builder.setSetting(setting);
        builder = builder.setValue(value);
        builder = builder.setUnit(unit.getName());
        Main.DeviceConvertSettingResponse response = Call.callSync(
            "device/convert_setting",
            builder.build(),
            Main.DeviceConvertSettingResponse.parser());
        return response.getValue();
    }


    /**
     * Convert arbitrary setting value from Zaber native units.
     * @param setting Name of the setting.
     * @param value Value of the setting in Zaber native units.
     * @param unit Units to convert value to.
     * @return Setting value.
     */
    public double convertFromNativeUnits(
        String setting, double value, Units unit) {
        Main.DeviceConvertSettingRequest.Builder builder = Main.DeviceConvertSettingRequest.newBuilder();
        builder = builder.setInterfaceId(this.device.getConnection().getInterfaceId());
        builder = builder.setDevice(this.device.getDeviceAddress());
        builder = builder.setFromNative(true);

        builder = builder.setSetting(setting);
        builder = builder.setValue(value);
        builder = builder.setUnit(unit.getName());
        Main.DeviceConvertSettingResponse response = Call.callSync(
            "device/convert_setting",
            builder.build(),
            Main.DeviceConvertSettingResponse.parser());
        return response.getValue();
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy