Exemple #1
0
        private bool RtSetValue(SetValueParam[] toSets)
        {
            if (toSets.Any(t => RtTagExpression.IsExpression(t.Topic)))
            {
                return(false);
            }

            logger.LogInformation("RtSetValue {@toSets}", System.Text.Json.JsonSerializer.Serialize(toSets));

            return(toSets.All(t =>
            {
                if (t.Value.ValueKind == JsonValueKind.Number)
                {
                    return connector.SetNumeric(t.Topic, t.Value.GetDouble());
                }
                else if (t.Value.ValueKind == JsonValueKind.Array || t.Value.ValueKind == JsonValueKind.Object)
                {
                    return connector.SetJson(t.Topic, t.Value);
                }
                else
                {
                    return connector.SetText(t.Topic, t.Value.ToString());
                }
            }));
        }
Exemple #2
0
    private void ParseBlock(ModbusReadBlockConfiguration readBlock, byte[] data)
    {
        foreach (var tag in readBlock.Tags)
        {
            var value = data.Parser(tag.Format, tag.BlockIndex * RowSize);

            if (value is string valStr)
            {
                Console.WriteLine("Write String Tag {0} => {1}", tag.TagName, valStr);

                connector.SetText(tag.TagName, valStr);
            }
            else
            {
                var valDbl = Convert.ToDouble(value);
                Console.WriteLine("Write Numeric Tag {0} => {1}", tag.TagName, valDbl);
                connector.SetNumeric(tag.TagName, valDbl);
            }
        }
    }
Exemple #3
0
    protected override Task ExecuteAsync(CancellationToken stoppingToken)
    {
        return(Task.Run(async() =>
        {
            connector.ConnectAsync(stoppingToken).Wait();

            _logger.LogWarning("Execution Started: {time}", DateTimeOffset.Now);

            int count = 1000;
            while (!stoppingToken.IsCancellationRequested && count-- > 0)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                _logger.LogDebug("Worker running at: {time}", DateTimeOffset.Now);

                connector.SetNumeric("test/ServiceTemplateWorker", DateTime.Now.ToUnixTimestamp());
                await Task.Delay(1000, stoppingToken);
            }
        }).ContinueWith((t) =>
        {
            _logger.LogWarning("Execution Stoped: {time}", DateTimeOffset.Now);
            Environment.Exit(0);
        }));
    }