public void ConnectToBleDevice(string leMacAdress) { try { if (!IsConnecting) { IsConnecting = true; if (!string.IsNullOrEmpty(leMacAdress) && mLeService != null) { if (!string.IsNullOrEmpty(ConnectedBluetoothDeviceMAC)) { mLeService.SetAutoConnect(ConnectedBluetoothDeviceMAC, false); } mLeService.Connect(leMacAdress, true); Act_OnLeDeviceConnectChange.Invoke(BleConnectState.Connecting); ConnectedBluetoothDeviceMAC = leMacAdress; ConnectedBluetoothDeviceMAC = string.IsNullOrEmpty(ConnectedBluetoothDeviceMAC) ? "" : ConnectedBluetoothDeviceMAC; } } } catch (Exception ex) { IsConnecting = false; Act_OnLeDeviceConnectChange?.Invoke(BleConnectState.ConnectionError); throw ex; } }
private void BleCallBack_OnServicesDiscoveredEvent(object sender, string e) { IsConnected = true; Act_OnLeDeviceConnectChange?.Invoke(BleConnectState.Connected); new Thread(new ThreadStart(() => { Thread.Sleep(300); EnableNotification(e, BleUUIDS.PrimaryService, BleUUIDS.Characters[1]); })).Start(); }
private void BleCallBack_OnServicesUndiscoveredEvent(object sender, YsBleCallBack.EventModel_SII e) { IsConnected = false; Act_OnLeDeviceConnectChange?.Invoke(BleConnectState.DisConnect); }
private void BleCallBack_OnDisconnectedEvent(object sender, string e) { IsConnected = false; Act_OnLeDeviceConnectChange?.Invoke(BleConnectState.DisConnect); }
private void BleCallBack_OnConnectionErrorEvent(object sender, YsBleCallBack.EventModel_SII e) { IsConnecting = false; IsConnected = false; Act_OnLeDeviceConnectChange?.Invoke(BleConnectState.ConnectionError); }
private void BleCallBack_OnConnectTimeoutEvent(object sender, string e) { IsConnecting = false; IsConnected = false; Act_OnLeDeviceConnectChange?.Invoke(BleConnectState.ConnectionTimeOut); }