示例#1
0
        private async void Mqtt_OnReceiveAttributesAsync(object sender, IoTSharp.EdgeSdk.MQTT.AttributeResponse e)
        {
            try
            {
                string key = $"{e.DeviceName}_{e.KeyName}";
                var    sc  = await _factory.GetScheduler();

                var      job     = JobBuilder.Create <Slaver>().WithIdentity($"{e.DeviceName}_{e.KeyName}").Build();
                ITrigger trigger = TriggerBuilder.Create()
                                   .WithIdentity(key).UsingJobData(nameof(ModBusConfig), e.Data).UsingJobData(nameof(e.DeviceName), e.DeviceName).UsingJobData(nameof(e.KeyName), e.KeyName).ForJob(job)
                                   .WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever()).StartNow().Build();

                if (await sc.CheckExists(new JobKey(key)))
                {
                    await sc.RescheduleJob(new TriggerKey(key), trigger);
                }
                else
                {
                    await sc.ScheduleJob(job, trigger);
                }
                modBusConfig = JToken.Parse(e.Data).SelectToken("ModBusConfig").ToObject <ModBusConfig>();
                if (modBusConfig != null)
                {
                    _modbusuri       = modBusConfig.ModBusUri;
                    HaveModBusConfig = true;
                }
            }
            catch (Exception ex)
            {
                HaveModBusConfig = false;
                _logger.LogError($"Mqtt_OnReceiveAttributesAsync: {ex.GetType().Name}{ex.Message}");
            }
        }
示例#2
0
        private async void Mqtt_OnReceiveAttributesAsync(object sender, IoTSharp.EdgeSdk.MQTT.AttributeResponse e)
        {
            string key = $"{e.DeviceName}_{e.KeyName}";
            var    sc  = await _factory.GetScheduler();

            var      job     = JobBuilder.Create <Slaver>().WithIdentity($"{e.DeviceName}_{e.KeyName}").Build();
            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity(key).UsingJobData(nameof(ModBusConfig), e.Data).UsingJobData(nameof(e.DeviceName), e.DeviceName).UsingJobData(nameof(e.KeyName), e.KeyName).ForJob(job)
                               .WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever()).StartNow().Build();

            if (await sc.CheckExists(new JobKey(key)))
            {
                await sc.RescheduleJob(new TriggerKey(key), trigger);
            }
            else
            {
                await sc.ScheduleJob(job, trigger);
            }
        }