示例#1
0
        //public ComfoBoxMqttClient(string brokerHostName, int brokerPort, ComfoBoxClient comfoBoxClient)
        //{
        //    _comfoBoxClient = comfoBoxClient;
        //    var client = new MqttClient(brokerHostName, brokerPort, false, MqttSslProtocols.None, null, null);
        //    client.Connect($"ComfoBox{DateTime.Now.Ticks}");
        //    _mqttClients = new[] { client };
        //}

        //public ComfoBoxMqttClient(string brokerHostName, ComfoBoxClient comfoBoxClient) 
        //{
        //    _comfoBoxClient = comfoBoxClient;
        //    var client = new MqttClient(brokerHostName);
        //    client.Connect($"ComfoBox{DateTime.Now.Ticks}");
        //    _mqttClients = new[] { client };
        //}

        public ComfoBoxMqttClient(string[] brokerHostNames, ComfoBoxClient comfoBoxClient)
        {
            _comfoBoxClient = comfoBoxClient;

            _mqttClients = brokerHostNames.Select(i => new MqttClient(i)).ToArray();
            Logger.Info($"MQTT Brokers: {string.Join(", ", brokerHostNames)}");
        }
示例#2
0
 public override async Task ReadAllValuesAsync(ComfoBoxClient client)
 {
     foreach (var child in Children)
     {
         await child.ReadAllValuesAsync(client);
     }
 }
示例#3
0
 public async void Connect()
 {
     try
     {
         if (_client != null)
         {
             //Disconnect
             _client.Stop();
             _client = null;
             ConnectButtonText = "Connect";
             CurrentState = "Disconnected";
             Logger.Info("Disconnected");
         }
         else
         {
             //Connect
             _client = new ComfoBoxClient(Port, Baudrate, Settings.Default.BacnetClientId);
             Logger.Info($"Connecting to Port={Port} with Baudrate={Baudrate}");
             ConnectButtonText = "Disconnect";
             CurrentState = "Connecting...";
             await _client.StartAsync();
             Logger.Info("Connected! Reading All Values...");
             CurrentState = "Connected! Reading All Values...";
             await ReadAllValuesAsync();
             Logger.Info("Connected! All values read.");
             CurrentState = "Connected! All values read.";
         }
     }
     catch (Exception ex)
     {
         Logger.Error($"Connect() has thrown an exception: {ex.Message}");
         MessageBox.Show(ex.Message, "Error");
     }
 }
示例#4
0
 public override async Task ReadAllValuesAsync(ComfoBoxClient client)
 {
     await Item.ReadValueAsync(client);
 }
示例#5
0
 public abstract Task ReadAllValuesAsync(ComfoBoxClient client);
示例#6
0
 public async Task ReadAsync(ComfoBoxClient comfoBoxClient)
 {
     await ItemValue.ReadValueAsync(comfoBoxClient);
 }