Replies: 1 comment
-
Yes, that is one idea. @Command(name = "waterMeter", subcommandsRepeatable = true, subcommands = HelpCommand.class)
public class WaterMeterCLI implements Callable<Integer> {
WaterMeterConnection wmConnection;
WaterMeter waterMeter;
AbstractModbusMaster master;
@ArgGroup(exclusive = true) ConnectionOptions connectionOptions;
@ArgGroup(exclusive = true, multiplicity = "1") RedLedOptions redLedOptions;
@ArgGroup(exclusive = true, multiplicity = "1") GreenLedOptions greenLedOptions;
static class ConnectionOptions {
@Option(names = {"-TCP"}) boolean connectionTCP;
@Option(names = {"-RS"}) boolean connectionRS;
}
static class RedLedOptions {
@Option(names = {"-redON"}) boolean redLedON;
@Option(names = {"-redOFF"}) boolean redLedOFF;
}
static class GreenLedOptions {
@Option(names = {"-greenON"}) boolean greenON;
@Option(names = {"-greenOFF"}) boolean greenOFF;
}
@Override
public Integer call() throws Exception {
System.out.println("Podłaczenie do urzadzenia MODBUS...");
wmConnection = new WaterMeterConnection();
if(connectionOptions.connectionRS) { master = wmConnection.getRSModbusMaster();}
if(connectionOptions.connectionTCP) { master = wmConnection.getTCPModbusMaster();}
waterMeter = new WaterMeter(master, wmConnection.getWmConnectionConf());
if(redLedOptions.redLedON) { waterMeter.SetRedLed();}
if(redLedOptions.redLedOFF) { waterMeter.ResetRedLed(); }
if(greenLedOptions.greenON) { waterMeter.SetGreenLed(); }
if(greenLedOptions.greenOFF) { waterMeter.ResetGreenLed(); }
// remaining business logic here...
return 1;
}
public static void main(String... args) {
int exitCode = new CommandLine(new WaterMeterCLI()).execute(args);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi
I really like picocli. I am currently creating a program to manage the water meter. Communication is carried out using the modbus serial or TCP/IP protocol. I wanted to provide the application with information about the selected protocol (-RS or -TCP). The appropriate connection is retrieved in the Constructor of the WaterMeterCLI class. When the constructor is run, there is no static connectionOptions object, which means that I can not determine what connection to use.
regards Jurek
' package pl.rynekdebnicki.waterMeter;
`
I found some solution :)
`
`
Beta Was this translation helpful? Give feedback.
All reactions