Beispiel #1
0
        public async Task TestETAPU11ReadWriteTimeSpan(string property, string data)
        {
            var status = await _etapu11.WritePropertyAsync(property, data);

            Assert.True(status.IsGood);
            _etapu11.Data = new ETAPU11Data();
            status        = await _etapu11.ReadPropertyAsync(property);

            Assert.True(status.IsGood);
            Assert.Equal(data, ((TimeSpan)_etapu11.Data.GetPropertyValue(property)).ToString());
        }
Beispiel #2
0
        public async Task TestETAPU11WriteProperty(string property, string data)
        {
            Assert.True(ETAPU11Data.IsProperty(property));
            Assert.True(ETAPU11Data.IsWritable(property));
            var status = await _etapu11.WritePropertyAsync(property, data);

            Assert.True(status.IsGood);
        }
Beispiel #3
0
        public async Task <IActionResult> PutETAPU11Data(string name, [FromQuery] string value)
        {
            if (string.IsNullOrEmpty(name))
            {
                _logger?.LogDebug($"PutETAPU11Data({name}, {value}) invalid property.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property name is invalid."));
            }

            if (string.IsNullOrEmpty(value))
            {
                _logger?.LogDebug($"PutETAPU11Data({name}, {value}) invalid value.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property value is invalid."));
            }

            try
            {
                _logger?.LogDebug($"PutETAPU11Data({name}, {value})...");

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

                        var status = await _etapu11.WritePropertyAsync(name, value);

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

                        return(Ok());
                    }
                    else
                    {
                        _logger?.LogDebug($"PutETAPU11Data('{name}, {value}') property not writable.");
                        return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Property '{name}' not writable."));
                    }
                }
                else
                {
                    _logger?.LogDebug($"PutETAPU11Data('{name}, {value}') property not found.");
                    return(NotFound($"Property '{name}' not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Beispiel #4
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);
        }