Exemplo n.º 1
0
 /// <summary>
 /// 主动断开连接
 /// </summary>
 /// <returns></returns>
 public void Dispose()
 {
     CurrentDeviceMAC = null;
     CurrentDevice?.Dispose();
     CurrentDevice = null;
     MessAgeLog(MsgType.NotifyTxt, "主动断开连接");
 }
Exemplo n.º 2
0
 /// <summary>
 /// 主动断开连接
 /// </summary>
 /// <returns></returns>
 public void Dispose()
 {
     CurrentDeviceMAC = null;
     CurrentService?.Dispose();
     CurrentDevice?.Dispose();
     CurrentDevice               = null;
     CurrentService              = null;
     CurrentWriteCharacteristic  = null;
     CurrentNotifyCharacteristic = null;
     ValueChanged(MsgType.NotifyTxt, "主动断开连接");
 }
Exemplo n.º 3
0
 /// <summary>
 /// 主动断开连接
 /// </summary>
 /// <returns></returns>
 public void Dispose()
 {
     CurrentDeviceMAC = null;
     if (CurrentService != null)
     {
         CurrentService.Dispose();
     }
     if (CurrentDevice != null)
     {
         CurrentDevice.Dispose();
     }
     CurrentDevice               = null;
     CurrentService              = null;
     CurrentWriteCharacteristic  = null;
     CurrentNotifyCharacteristic = null;
 }
Exemplo n.º 4
0
 private void CurrentDevice_ConnectionStatusChanged(BluetoothLEDevice sender, object args)
 {
     if (sender.ConnectionStatus == BluetoothConnectionStatus.Disconnected && CurrentDeviceMAC != null)
     {
         string msg = "设备已断开,自动重连";
         ValueChanged(MsgType.NotifyTxt, msg);
         if (!asyncLock)
         {
             asyncLock = true;
             CurrentDevice.Dispose();
             CurrentDevice               = null;
             CurrentService              = null;
             CurrentWriteCharacteristic  = null;
             CurrentNotifyCharacteristic = null;
             SelectDeviceFromIdAsync(CurrentDeviceMAC);
         }
     }
     else
     {
         string msg = "设备已连接";
         ValueChanged(MsgType.NotifyTxt, msg);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 连接状态改变事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void CurrentDevice_ConnectionStatusChanged(BluetoothLEDevice sender, object args)
 {
     if (sender.ConnectionStatus == BluetoothConnectionStatus.Disconnected && CurrentDeviceMAC != null)
     {
         string msg = "Disconnected";
         ValueChanged(MsgType.NotifyTxt, msg);
         CurrentDevice.ConnectionStatusChanged -= CurrentDevice_ConnectionStatusChanged;
         if (!asyncLock)
         {
             asyncLock = true;
             CurrentDevice.Dispose();
             CurrentDevice               = null;
             CurrentService              = null;
             CurrentWriteCharacteristic  = null;
             CurrentNotifyCharacteristic = null;
         }
     }
     else
     {
         string msg = "Success";
         ValueChanged(MsgType.NotifyTxt, msg);
     }
 }