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

zaber.motion.Tools 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;

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 various utility functions.
 */
public final class Tools {
    private Tools() {
    }

    /**
     * Lists all serial ports on the computer.
     * @return A CompletableFuture that can be completed to get the result:
     * Array of serial port names.
     */
    public static CompletableFuture listSerialPortsAsync() {
        Main.EmptyRequest.Builder builder = Main.EmptyRequest.newBuilder();

        CompletableFuture response = Call.callAsync(
            "tools/list_serial_ports",
            builder.build(),
            Main.ToolsListSerialPortsResponse.parser());
        return response
            .thenApply(r -> r.getPortsList().stream().toArray(String[]::new));
    }

    /**
     * Lists all serial ports on the computer.
     * @return Array of serial port names.
     */
    public static String[] listSerialPorts() {
        try {
            return listSerialPortsAsync().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