示例#1
0
 public void Connect()
 {
     if (BleUdpListeners.HasSomething())
     {
         foreach (var bleUdpListener in BleUdpListeners)
         {
             bleUdpListener.Stop();
             bleUdpListener.OnDeviceDiscovery -= OnDeviceDiscovery;
         }
         BleUdpListeners.Clear();
     }
     foreach (var receiver in BleSystemConfiguration.BleReceivers)
     {
         if (!receiver.Value.IsEnabled)
         {
             continue;
         }
         var listener = new BLEUdpListener(receiver.Value);
         listener.OnDeviceDiscovery += OnDeviceDiscovery;
         BleUdpListeners.Add(listener);
         listener.StartListener();
     }
     _monitoringEvents = BleUdpListeners.Any(l => l.IsListening);
     if (OnConnectionStateChanged != null)
     {
         OnConnectionStateChanged(ConnectionState);
     }
 }
示例#2
0
 public void Disconnect()
 {
     _monitoringEvents = false;
     if (BleUdpListeners.HasSomething())
     {
         foreach (var bleUdpListener in BleUdpListeners)
         {
             bleUdpListener.Stop();
             bleUdpListener.OnDeviceDiscovery -= OnDeviceDiscovery;
         }
         BleUdpListeners.Clear();
     }
     if (OnConnectionStateChanged != null)
     {
         OnConnectionStateChanged(ConnectionState);
     }
 }