org.bidib.jbidibc.WriteCv Maven / Gradle / Ivy
package org.bidib.jbidibc;
import org.bidib.jbidibc.core.node.BidibNode;
import org.bidib.jbidibc.messages.Node;
import org.bidib.jbidibc.messages.exception.PortNotFoundException;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
/**
* This commands writes the value into the specified CV of the specified node.
*
*/
@Command
public class WriteCv extends BidibNodeCommand {
@Option(names = { "-cv" }, description = "The CV number", required = true)
private String cvNumber;
@Option(names = { "-value" }, description = "The CV value", required = true)
private String cvValue;
public static void main(String[] args) {
run(new WriteCv(), args);
}
@Override
public Integer call() {
int result = 20;
try {
openPort(getPortName(), null);
Node node = findNode();
if (node != null) {
BidibNode bidibNode = getBidib().getNode(node);
if (bidibNode.vendorEnable(node.getUniqueId())) {
bidibNode.vendorSet(cvNumber, cvValue);
bidibNode.vendorDisable();
result = 0;
}
}
else {
System.err.println("node with unique id \"" + getNodeIdentifier() + "\" not found"); // NOSONAR
}
getBidib().close();
}
catch (PortNotFoundException ex) {
System.err
.println("The provided port was not found: " + ex.getMessage() // NOSONAR
+ ". Verify that the BiDiB device is connected.");
}
catch (Exception ex) {
System.err.println("Execute command failed: " + ex); // NOSONAR
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy