public async Task TestETAPU11ReadWriteTimeSpan(string property, string data) { var status = await _etapu11.WritePropertyAsync(property, data); Assert.True(status.IsGood); _etapu11.Data = new ETAPU11Data(); status = await _etapu11.ReadPropertyAsync(property); Assert.True(status.IsGood); Assert.Equal(data, ((TimeSpan)_etapu11.Data.GetPropertyValue(property)).ToString()); }
/// <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 TestETAPU11ReadProperty(string property) { Assert.True(ETAPU11Data.IsProperty(property)); Assert.True(ETAPU11Data.IsReadable(property)); var status = await _etapu11.ReadPropertyAsync(property); Assert.True(status.IsGood); }
public async Task <IActionResult> GetETAPU11Data(string name, bool update = false) { if (string.IsNullOrEmpty(name)) { _logger?.LogDebug($"GetETAPU11Data() invalid property."); return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid.")); } try { _logger?.LogDebug($"GetETAPU11Data({name})..."); if (ETAPU11Data.IsProperty(name)) { if (update) { if (ETAPU11Data.IsReadable(name)) { if (!_etapu11.IsLocked) { return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished.")); } var status = await _etapu11.ReadPropertyAsync(name); if (status.IsGood) { return(StatusCode(StatusCodes.Status502BadGateway, status)); } } else { _logger?.LogDebug($"GetETAPU11Data('{name}') property not readable."); return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Property '{name}' not readable.")); } } return(Ok(_etapu11.GetPropertyValue(name))); } else { _logger?.LogDebug($"GetETAPU11Data('{name}') property not found."); return(NotFound($"Property '{name}' not found.")); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }