public async Task <IActionResult> GetSYMO823MData(bool block = true, bool update = false)
        {
            try
            {
                _logger?.LogDebug("GetSYMO823MData()...");

                if (!_symo823m.IsLocked)
                {
                    return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished."));
                }

                if (update)
                {
                    var status = block ? await _symo823m.ReadBlockAllAsync() : await _symo823m.ReadAllAsync();

                    if (!status.IsGood)
                    {
                        return(StatusCode(StatusCodes.Status502BadGateway, status));
                    }
                }

                return(Ok(_symo823m.Data));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        public async Task TestSYMO823MBlockRead()
        {
            var status = await _symo823m.ReadBlockAllAsync();

            Assert.True(status.IsGood);
            Assert.True(_symo823m.Data.IsGood);
            Assert.True(_symo823m.CommonModel.IsGood);
            Assert.True(_symo823m.InverterModel.IsGood);
            Assert.True(_symo823m.NameplateModel.IsGood);
            Assert.True(_symo823m.SettingsModel.IsGood);
            Assert.True(_symo823m.ExtendedModel.IsGood);
            Assert.True(_symo823m.ControlModel.IsGood);
            Assert.True(_symo823m.MultipleModel.IsGood);
            Assert.True(_symo823m.FroniusRegister.IsGood);
        }
        /// <summary>
        /// Executes the read and operation.
        /// </summary>
        protected override async Task DoUpdateAsync()
        {
            try
            {
                _logger?.LogDebug("SYMO823MMonitor: DoUpdateAsync...");
                var status = await _symo823m?.ReadBlockAllAsync();

                if (status.IsGood)
                {
                    await _hub.Clients.All.SendAsync("UpdateData", _symo823m.Data);
                }
            }
            catch (Exception ex)
            {
                _logger?.LogWarning(ex, "DoUpdateAsync: Exception");
            }
        }
Beispiel #5
0
        /// <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 SYMO823M options.
                    _symo823m.Slave.Address = Parent.Address;
                    _symo823m.Slave.Port    = Parent.Port;
                    _symo823m.Slave.ID      = Parent.SlaveID;

                    if (Property.Length == 0)
                    {
                        Console.WriteLine($"Reading all data from SYMO823M inverter.");

                        if (OptionB)
                        {
                            await _symo823m.ReadBlockAllAsync();
                        }
                        else
                        {
                            await _symo823m.ReadAllAsync();
                        }

                        Console.WriteLine($"SYMO823M: {JsonConvert.SerializeObject(_symo823m, Formatting.Indented)}");
                    }

                    if (Property.Length > 0)
                    {
                        Console.WriteLine($"Reading property '{Property}' from SYMO823M inverter");
                        _symo823m.ReadPropertyAsync(Property).Wait();
                        Console.WriteLine($"Value of property '{Property}' = {_symo823m.Data.GetPropertyValue(Property)}");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, $"Exception ReadCommand.");
                return(-1);
            }

            return(0);
        }