/// <summary> /// Method to run when the root command is executed. /// </summary> /// <returns>Zero if ok.</returns> public int OnExecute(CommandLineApplication app) { Console.WriteLine($"Settings: {JsonConvert.SerializeObject(this, Formatting.Indented)}"); try { if (CheckOptions(app)) { // Overriding SYMO823M options. _symo823m.Slave.Address = Address; _symo823m.Slave.Port = Port; _symo823m.Slave.ID = SlaveID; if (_symo823m.Connect()) { Console.WriteLine($"Modbus TCP client found at {Address}:{Port}."); } else { Console.WriteLine($"Modbus TCP client not found at {Address}:{Port}."); } } } catch (Exception ex) { _logger?.LogError(ex, $"Exception RootCommand Run()"); Console.WriteLine($"Error connecting to Modbus TCP client at {Address}:{Port}."); return(-1); } return(0); }