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

org.bidib.jbidibc.ReadCv 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.VendorData;
import org.bidib.jbidibc.messages.exception.PortNotFoundException;

import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

/**
 * This commands reads the value of the specified CV from the specified node.
 * 
 */
@Command
public class ReadCv extends BidibNodeCommand {

    @Option(names = { "-cv" }, description = "The CV number", required = true)
    private String cvNumber;

    public static void main(String[] args) {
        run(new ReadCv(), 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())) {

                    VendorData vendorData = bidibNode.vendorGet(cvNumber, false);

                    System.out.println("CV" + vendorData.getName() + "=" + vendorData.getValue()); // NOSONAR

                    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