Exemplo n.º 1
0
        public override bool WriteValue(IRtTag tag, IRtValue value)
        {
            try
            {
                if (mqttClient.IsConnected)
                {
                    RtTagMqttOptions options = tag.Options as RtTagMqttOptions;
                    var writed = mqttClient.Client.Publish(tag.Topic, value.Binary, (byte)options.qosLevels, options.retain);
                    if (writed > 0)
                    {
                        lock (rtTags)
                        {
                            foreach (var _tag in rtTags.Where(t => t.Topic == tag.Topic))
                            {
                                _tag.RaiseOnSetValue(value);
                            }
                        }

                        RaiseOnSetValue(tag);

                        logger?.LogDebug("WriteValue TagName:{0} Value:{1} return:{2}", tag.TagName, tag.Value.Text, true);
                        return(true);
                    }
                }
            }
            catch { }
            logger?.LogWarning("WriteValue TagName:{0} return:{1}", tag.TagName, false);
            return(false);
        }
Exemplo n.º 2
0
 public RtTagMqtt(IRtConnector connector, string tagName, string topic, RtTagMqttOptions options)
 {
     Connector    = connector;
     TagName      = tagName;
     Topic        = topic;
     base.Options = options ?? new RtTagMqttOptions();
 }