Пример #1
0
        public async Task <IActionResult> GetBControlData(bool block = true, bool update = false)
        {
            try
            {
                _logger?.LogDebug("GetBControlData()...");

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

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

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

                return(Ok(_bcontrol.Data));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Пример #2
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 BControl options.
                    _bcontrol.TcpSlave.Address = Parent.Address;
                    _bcontrol.TcpSlave.Port    = Parent.Port;
                    _bcontrol.TcpSlave.ID      = Parent.SlaveID;

                    if (Property.Length == 0)
                    {
                        Console.WriteLine($"Reading all data from BControl energy meter.");
                        DataStatus status;

                        if (OptionB)
                        {
                            status = await _bcontrol.ReadBlockAllAsync();
                        }
                        else
                        {
                            status = await _bcontrol.ReadAllAsync();
                        }

                        if (status.IsGood)
                        {
                            Console.WriteLine($"BControl: {JsonConvert.SerializeObject(_bcontrol, Formatting.Indented)}");
                        }
                        else
                        {
                            Console.WriteLine($"Error reading data from BControl energy meter.");
                            Console.WriteLine($"Reason: {status.Explanation}.");
                        }
                    }
                    else if (Property.Length > 0)
                    {
                        Console.WriteLine($"Reading property '{Property}' from BControl energy meter:");
                        await _bcontrol.ReadPropertyAsync(Property);

                        if (_bcontrol.Data.Status.IsGood)
                        {
                            Console.WriteLine($"Value of property '{Property}' = {_bcontrol.Data.GetPropertyValue(Property)}");
                        }
                        else
                        {
                            Console.WriteLine($"Error reading property '{Property}' from BControl energy meter.");
                            Console.WriteLine($"Reason: {_bcontrol.Data.Status.Explanation}.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, $"Exception ReadCommand.");
                return(-1);
            }

            return(0);
        }
Пример #3
0
        public async Task TestBControlReadBlock()
        {
            await _bcontrol.ReadBlockAllAsync();

            Assert.True(_bcontrol.Data.IsGood);
            Assert.True(_bcontrol.InternalData.IsGood);
            Assert.True(_bcontrol.EnergyData.IsGood);
            Assert.True(_bcontrol.PnPData.IsGood);
            Assert.True(_bcontrol.SunSpecData.IsGood);
        }
Пример #4
0
        /// <summary>
        /// Executes the start operation just once.
        /// </summary>
        protected override async Task DoStartAsync()
        {
            try
            {
                _logger?.LogDebug("BControlMonitor: DoStart...");

                await _bcontrol?.ReadBlockAllAsync();

                await _hub.Clients.All.SendAsync("UpdateData", _bcontrol.Data);

                await _hub.Clients.All.SendAsync("UpdateInternal", _bcontrol.InternalData);

                await _hub.Clients.All.SendAsync("UpdateEnergy", _bcontrol.EnergyData);

                await _hub.Clients.All.SendAsync("UpdatePnP", _bcontrol.PnPData);

                await _hub.Clients.All.SendAsync("UpdateSunSpec", _bcontrol.SunSpecData);
            }
            catch (Exception ex)
            {
                _logger?.LogWarning(ex, "DoStartAsync: Exception");
            }
        }