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