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); } }
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); } }