/// <summary> /// Method to run when command is executed. /// </summary> /// <returns>Zero if ok.</returns> public async Task <int> OnExecuteAsync(CommandLineApplication app) { try { if (CheckOptions(app)) { // Overriding ETAPU11 options. _etapu11.TcpSlave.Address = Parent.Address; _etapu11.TcpSlave.Port = Parent.Port; _etapu11.TcpSlave.ID = Parent.SlaveID; if (Property.Length == 0) { Console.WriteLine($"Reading all data from ETAPU11 boiler."); DataStatus status; if (OptionB) { status = await _etapu11.ReadBlockAllAsync(); } else { status = await _etapu11.ReadAllAsync(); } if (status.IsGood) { Console.WriteLine($"ETAPU11: {JsonConvert.SerializeObject(_etapu11, Formatting.Indented)}"); } else { Console.WriteLine($"Error reading data from ETAPU11 boiler."); Console.WriteLine($"Reason: {status.Explanation}."); } } else if (Property.Length > 0) { Console.WriteLine($"Reading property '{Property}' from ETAPU11 boiler"); _etapu11.ReadPropertyAsync(Property).Wait(); if (_etapu11.Data.Status.IsGood) { Console.WriteLine($"Value of property '{Property}' = {_etapu11.Data.GetPropertyValue(Property)}"); } else { Console.WriteLine($"Error reading property '{Property}' from KWLEC200 hvac."); Console.WriteLine($"Reason: {_etapu11.Data.Status.Explanation}."); } } } } catch (Exception ex) { _logger?.LogError(ex, $"Exception ReadCommand."); return(-1); } return(0); }
public async Task TestETAPU11BlockRead() { var status = await _etapu11.ReadBlockAllAsync(); Assert.True(status.IsGood); Assert.True(_etapu11.Data.IsGood); Assert.True(_etapu11.BoilerData.IsGood); Assert.True(_etapu11.HotwaterData.IsGood); Assert.True(_etapu11.HeatingData.IsGood); Assert.True(_etapu11.StorageData.IsGood); Assert.True(_etapu11.SystemData.IsGood); }
public async Task <IActionResult> GetETAPU11Data(bool block = true, bool update = false) { try { _logger?.LogDebug("GetETAPU11Data()..."); if (!_etapu11.IsLocked) { return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished.")); } if (update) { var status = block ? await _etapu11.ReadBlockAllAsync() : await _etapu11.ReadAllAsync(); if (!status.IsGood) { return(StatusCode(StatusCodes.Status502BadGateway, status)); } } return(Ok(_etapu11.Data)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
/// <summary> /// Method to run when command is executed. /// </summary> /// <returns>Zero if ok.</returns> public async Task <int> OnExecuteAsync(CommandLineApplication app) { try { if (CheckOptions(app)) { // Overriding ETAPU11 options. _etapu11.TcpSlave.Address = Parent.Address; _etapu11.TcpSlave.Port = Parent.Port; _etapu11.TcpSlave.ID = Parent.SlaveID; Console.WriteLine($"Writing value '{Value}' to property '{Property}' at ETAPU11 boiler"); var status = await _etapu11.WritePropertyAsync(Property, Value); if (status.IsGood) { Console.WriteLine($"Reading properties from ETAPU11 boiler"); if (OptionB) { await _etapu11.ReadBlockAllAsync(); } else { await _etapu11.ReadAllAsync(); } if (_etapu11.Data.Status.IsGood) { Console.WriteLine($"Value of property '{Property}' = {_etapu11.Data.GetPropertyValue(Property)}"); } else { Console.WriteLine($"Error reading property '{Property}' from ETAPU11 boiler."); Console.WriteLine($"Reason: {status.Explanation}."); } } else { Console.WriteLine($"Error writing property '{Property}' from ETAPU11 boiler."); Console.WriteLine($"Reason: {status.Explanation}."); } } } catch (Exception ex) { _logger?.LogError(ex, $"Exception WriteCommand."); return(-1); } return(0); }
/// <summary> /// Executes the update operation every minute. /// </summary> protected override async Task DoWorkAsync() { try { _logger?.LogDebug("ETAPU11Monitor: DoWork..."); await _etapu11?.ReadBlockAllAsync(); await _hub?.Clients.All.SendAsync("UpdateData", _etapu11.Data); await _hub?.Clients.All.SendAsync("UpdateBoiler", _etapu11.BoilerData); await _hub?.Clients.All.SendAsync("UpdateHeating", _etapu11.HeatingData); await _hub?.Clients.All.SendAsync("UpdateHotwater", _etapu11.HotwaterData); await _hub?.Clients.All.SendAsync("UpdateStorage", _etapu11.StorageData); await _hub?.Clients.All.SendAsync("UpdateSystem", _etapu11.SystemData); } catch (Exception ex) { _logger?.LogWarning(ex, "DoWorkAsync: Exception"); } }