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

zaber.motion.ascii.Warnings 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.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);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy