public async Task TestSYMO823MReadWriteSunSpecInt16(string property, short data) { var status = await _symo823m.WritePropertyAsync(property, data.ToString()); Assert.True(status.IsGood); _symo823m.Data = new SYMO823MData(); status = await _symo823m.ReadPropertyAsync(property); Assert.True(status.IsGood); Assert.Equal(data, (short)(int16)_symo823m.Data.GetPropertyValue(property)); }
public async Task TestSYMO823MWriteProperty(string property, string data) { Assert.True(SYMO823MData.IsProperty(property)); Assert.True(SYMO823MData.IsWritable(property)); var status = await _symo823m.WritePropertyAsync(property, data); Assert.True(status.IsGood); }
public async Task <IActionResult> PutSYMO823MData(string name, [FromQuery] string value) { if (string.IsNullOrEmpty(name)) { _logger?.LogDebug($"PutSYMO823MData({name}, {value}) invalid property."); return(StatusCode(StatusCodes.Status400BadRequest, $"Property name is invalid.")); } if (string.IsNullOrEmpty(value)) { _logger?.LogDebug($"PutSYMO823MData({name}, {value}) invalid value."); return(StatusCode(StatusCodes.Status400BadRequest, $"Property value is invalid.")); } try { _logger?.LogDebug($"PutSYMO823MData({name}, {value})..."); if (SYMO823MData.IsProperty(name)) { if (SYMO823MData.IsWritable(name)) { if (!_symo823m.IsLocked) { return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished.")); } var status = await _symo823m.WritePropertyAsync(name, value); if (!status.IsGood) { return(StatusCode(StatusCodes.Status502BadGateway, status)); } return(Ok()); } else { _logger?.LogDebug($"PutSYMO823MData('{name}, {value}') property not writable."); return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Property '{name}' not writable.")); } } else { _logger?.LogDebug($"PutSYMO823MData('{name}, {value}') property not found."); return(NotFound($"Property '{name}' not found.")); } } 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 { // Overriding SYMO823M options. _symo823m.Slave.Address = Parent.Address; _symo823m.Slave.Port = Parent.Port; _symo823m.Slave.ID = Parent.SlaveID; if (CheckOptions(app)) { Console.WriteLine($"Writing value '{Value}' to property '{Property}' at SYMO823M symo"); var status = await _symo823m.WritePropertyAsync(Property, Value); if (status.IsGood) { Console.WriteLine($"Reading properties from SYMO823M inverter."); if (OptionB) { await _symo823m.ReadBlockAllAsync(); } else { await _symo823m.ReadAllAsync(); } if (_symo823m.Data.Status.IsGood) { Console.WriteLine($"Value of property '{Property}' = {_symo823m.Data.GetPropertyValue(Property)}"); } else { Console.WriteLine($"Error reading property '{Property}' from SYMO823M inverter."); Console.WriteLine($"Reason: {status.Explanation}."); } } else { Console.WriteLine($"Error writing property '{Property}' from SYMO823M inverter."); Console.WriteLine($"Reason: {status.Explanation}."); } } } catch (Exception ex) { _logger?.LogError(ex, $"Exception WriteCommand."); return(-1); } return(0); }