/// <summary> /// Updates the holding register data store. /// </summary> private void UpdateDataStoreHoldingRegisters() { _storage.HoldingRegisters.WritePoints(BControlData.GetOffset("InternalDataBlock1"), GetPoints(_data.InternalDataBlock1)); _storage.HoldingRegisters.WritePoints(BControlData.GetOffset("InternalDataBlock2"), GetPoints(_data.InternalDataBlock2)); _storage.HoldingRegisters.WritePoints(BControlData.GetOffset("EnergyDataBlock1"), GetPoints(_data.EnergyDataBlock1)); _storage.HoldingRegisters.WritePoints(BControlData.GetOffset("EnergyDataBlock2"), GetPoints(_data.EnergyDataBlock2)); _storage.HoldingRegisters.WritePoints(BControlData.GetOffset("EnergyDataBlock3"), GetPoints(_data.EnergyDataBlock3)); _storage.HoldingRegisters.WritePoints(BControlData.GetOffset("PnPDataBlock1"), _data.PnPDataBlock1); _storage.HoldingRegisters.WritePoints(BControlData.GetOffset("SunSpecDataBlock1"), _data.SunSpecDataBlock1); _storage.HoldingRegisters.WritePoints(BControlData.GetOffset("SunSpecDataBlock2"), _data.SunSpecDataBlock2); }
public async Task <IActionResult> GetBControlData(string name, bool update = false) { if (string.IsNullOrEmpty(name)) { _logger?.LogDebug($"GetBControlData() invalid property."); return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid.")); } try { _logger?.LogDebug($"GetBControlData({name})..."); if (BControlData.IsProperty(name)) { if (update) { if (BControlData.IsReadable(name)) { if (!_bcontrol.IsLocked) { return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished.")); } var status = await _bcontrol.ReadPropertyAsync(name); if (!status.IsGood) { return(StatusCode(StatusCodes.Status502BadGateway, status)); } } else { _logger?.LogDebug($"GetBControlData('{name}') property not readable."); return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Property '{name}' not readable.")); } } return(Ok(_bcontrol.GetPropertyValue(name))); } else { _logger?.LogDebug($"GetBControlData('{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 (!BControlData.IsProperty(Property)) { _logger?.LogError($"The property '{Property}' has not been found."); return(false); } if (!BControlData.IsReadable(Property)) { _logger?.LogError($"The property '{Property}' is not readable."); return(false); } } return(true); }