Example #1
0
 public void BleHostDisconnect()
 {
     CsrBleDll.CsrBleHostCancel();
     if (CurDevInfo != null)
     {
         if (CsrBleDll.CsrBleHostDisconnect(CurDevInfo.ConnHandle))
         {
             Trace(string.Format("CsrBleHostDisconnect {0} Success!", CurDevInfo));
             OnUpdateBleConnectEvent("蓝牙断开成功:" + CurDevInfo);
             return;
         }
         Trace(string.Format("CsrBleHostDisconnect {0} Fail!", CurDevInfo));
         OnUpdateBleConnectEvent("蓝牙断开失败:" + CurDevInfo);
     }
 }
Example #2
0
        public async Task <bool> BleHostDisconnect(BleGattDevice gattDevice)
        {
            if (!IsBleHosted)
            {
                Error("[CSR]:BleHostInitialize Fail!");
                return(false);
            }

            return(await Task.Run(() =>
            {
                if (CsrBleDll.CsrBleHostDisconnect(gattDevice.Handle))
                {
                    Debug("[CSR]:CsrBleHostDisconnect true!");
                    if (_disconnectEvent.WaitOne(2500))
                    {
                        if (!GattConnectDevices.Contains(gattDevice))
                        {
                            Debug($"[CSR]:CsrBleHostDisconnect {gattDevice.Address} Success!");
                            OnDeviceConnectEvent("蓝牙断开成功:" + gattDevice.Address);
                            gattDevice.OnDeviceDisconnectEvent(true);
                            return true;
                        }
                    }
                }

                if (GattConnectDevices.Contains(gattDevice))
                {
                    GattConnectDevices.Remove(gattDevice);
                }

                gattDevice.OnDeviceDisconnectEvent(false);
                Debug($"[CSR]:CsrBleHostDisconnect {gattDevice.Address} Fail!");
                OnDeviceConnectEvent("蓝牙断开失败:" + gattDevice.Address);
                return false;
            }));
        }