Пример #1
0
        public async Task TestSYMO823MReadWriteSunSpecInt16(string property, short data)
        {
            var status = await _symo823m.WritePropertyAsync(property, data.ToString());

            Assert.True(status.IsGood);
            _symo823m.Data = new SYMO823MData();
            status         = await _symo823m.ReadPropertyAsync(property);

            Assert.True(status.IsGood);
            Assert.Equal(data, (short)(int16)_symo823m.Data.GetPropertyValue(property));
        }
Пример #2
0
        public async Task TestSYMO823MReadProperty(string property)
        {
            Assert.True(SYMO823MData.IsProperty(property));
            Assert.True(SYMO823MData.IsReadable(property));
            var status = await _symo823m.ReadPropertyAsync(property);

            Assert.True(status.IsGood);
        }
        public async Task <IActionResult> GetSYMO823MData(string name, bool update = false)
        {
            if (string.IsNullOrEmpty(name))
            {
                _logger?.LogDebug($"GetSYMO823MData() invalid property.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid."));
            }

            try
            {
                _logger?.LogDebug($"GetSYMO823MData({name})...");

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

                            var status = await _symo823m.ReadPropertyAsync(name);

                            if (!status.IsGood)
                            {
                                return(StatusCode(StatusCodes.Status502BadGateway, status));
                            }
                        }
                        else
                        {
                            _logger?.LogDebug($"GetSYMO823MData('{name}') property not readable.");
                            return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Property '{name}' not readable."));
                        }
                    }

                    return(Ok(_symo823m.GetPropertyValue(name)));
                }
                else
                {
                    _logger?.LogDebug($"GetSYMO823MData('{name}') property not found.");
                    return(NotFound($"Property '{name}' not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Пример #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 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);
        }