public void TestKWLEC200ReadProperty(string property) { Assert.True(KWLEC200Data.IsProperty(property)); Assert.True(KWLEC200Data.IsReadable(property)); var status = _kwlec200.ReadProperty(property); Assert.True(status.IsGood); }
public IActionResult GetKWLEC200Data(string name, bool update = false) { if (string.IsNullOrEmpty(name)) { _logger?.LogDebug($"GetKWLEC200Data() invalid property."); return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid.")); } try { _logger?.LogDebug($"GetKWLEC200Data({name})..."); if (KWLEC200Data.IsProperty(name)) { if (update) { if (KWLEC200Data.IsReadable(name)) { if (!_kwlec200.IsLocked) { return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished.")); } var status = _kwlec200.ReadProperty(name); if (!status.IsGood) { return(StatusCode(StatusCodes.Status502BadGateway, status)); } } else { _logger?.LogDebug($"GetKWLEC200Data('{name}') property not readable."); return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Property '{name}' not readable.")); } } return(Ok(_kwlec200.GetPropertyValue(name))); } else { _logger?.LogDebug($"GetKWLEC200Data('{name}') property not found."); return(NotFound($"Property '{name}' not found.")); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
/// <summary> /// Helper method to check options. /// </summary> /// <param name="app"></param> /// <returns>True if options are OK.</returns> private bool CheckOptions(CommandLineApplication app) { if (Property.Length > 0) { if (!KWLEC200Data.IsProperty(Property)) { _logger?.LogError($"The property '{Property}' has not been found."); return(false); } if (!KWLEC200Data.IsReadable(Property)) { _logger?.LogError($"The property '{Property}' is not readable."); return(false); } } return(true); }
/// <summary> /// Helper method to write the property value to the storage. /// </summary> /// <param name="property">The property name.</param> private void ReturnData(string property) { if (!string.IsNullOrEmpty(property)) { if (KWLEC200Data.IsProperty(property)) { if (KWLEC200Data.IsReadable(property)) { object value = Data.GetPropertyValue(property); string name = KWLEC200Data.GetName(property); ushort size = KWLEC200Data.GetSize(property); ushort count = KWLEC200Data.GetCount(property); string text = string.Empty; _logger?.LogDebug($"Property '{property}' => Type: {value.GetType()}, Name: {name}, Size: {size}, Count: {count}."); if (value is bool) { text = Helios.GetBoolData(name, size, count, (bool)value); } else if (value is int) { text = Helios.GetIntegerData(name, size, count, (int)value); } else if (value is double) { text = Helios.GetDoubleData(name, size, count, (double)value); } else if (value is DateTime) { text = Helios.GetDateData(name, size, count, (DateTime)value); } else if (value is TimeSpan) { text = Helios.GetTimeData(name, size, count, (TimeSpan)value); } else if (((dynamic)value).GetType().IsEnum) { text = Helios.GetIntegerData(name, size, count, (int)value); } else if (value is string) { text = Helios.GetStringData(name, size, count, (string)value); } if (!string.IsNullOrEmpty(text)) { _pending = true; _storage.HoldingRegisters.WritePoints(OFFSET, text.ToRegisters()); _logger?.LogDebug($"Property '{property}' => '{text}'."); } } else { _logger?.LogDebug($"ReturnData property '{property}' not readable."); } } else { _logger?.LogWarning($"ReturnData property '{property}' not found."); } } else { _logger?.LogError($"ReturnData property invalid."); } }