示例#1
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 ETAPU11 options.
                    _etapu11.TcpSlave.Address = Parent.Address;
                    _etapu11.TcpSlave.Port    = Parent.Port;
                    _etapu11.TcpSlave.ID      = Parent.SlaveID;

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

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

                        if (status.IsGood)
                        {
                            Console.WriteLine($"ETAPU11: {JsonConvert.SerializeObject(_etapu11, Formatting.Indented)}");
                        }
                        else
                        {
                            Console.WriteLine($"Error reading data from ETAPU11 boiler.");
                            Console.WriteLine($"Reason: {status.Explanation}.");
                        }
                    }
                    else if (Property.Length > 0)
                    {
                        Console.WriteLine($"Reading property '{Property}' from ETAPU11 boiler");
                        _etapu11.ReadPropertyAsync(Property).Wait();

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

            return(0);
        }
示例#2
0
        public async Task <IActionResult> GetETAPU11Data(bool block = true, bool update = false)
        {
            try
            {
                _logger?.LogDebug("GetETAPU11Data()...");

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

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

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

                return(Ok(_etapu11.Data));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
示例#3
0
        public async Task TestETAPU11ReadWrite()
        {
            await _etapu11.WriteAllAsync();

            Assert.True(_etapu11.Data.IsGood);
            await _etapu11.ReadAllAsync();

            Assert.True(_etapu11.Data.IsGood);
        }
示例#4
0
        public async Task TestETAPU11Read()
        {
            await _etapu11.ReadAllAsync();

            Assert.True(_etapu11.Data.IsGood);
            Assert.True(_etapu11.BoilerData.IsGood);
            Assert.True(_etapu11.HotwaterData.IsGood);
            Assert.True(_etapu11.HeatingData.IsGood);
            Assert.True(_etapu11.StorageData.IsGood);
            Assert.True(_etapu11.SystemData.IsGood);
            _logger?.LogInformation($"ETAPU11: {JsonConvert.SerializeObject(_etapu11, Formatting.Indented)}");
        }
示例#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 ETAPU11 options.
                    _etapu11.TcpSlave.Address = Parent.Address;
                    _etapu11.TcpSlave.Port    = Parent.Port;
                    _etapu11.TcpSlave.ID      = Parent.SlaveID;

                    Console.WriteLine($"Writing value '{Value}' to property '{Property}' at ETAPU11 boiler");
                    var status = await _etapu11.WritePropertyAsync(Property, Value);

                    if (status.IsGood)
                    {
                        Console.WriteLine($"Reading properties from ETAPU11 boiler");

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

                        if (_etapu11.Data.Status.IsGood)
                        {
                            Console.WriteLine($"Value of property '{Property}' = {_etapu11.Data.GetPropertyValue(Property)}");
                        }
                        else
                        {
                            Console.WriteLine($"Error reading property '{Property}' from ETAPU11 boiler.");
                            Console.WriteLine($"Reason: {status.Explanation}.");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Error writing property '{Property}' from ETAPU11 boiler.");
                        Console.WriteLine($"Reason: {status.Explanation}.");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, $"Exception WriteCommand.");
                return(-1);
            }

            return(0);
        }