예제 #1
0
        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;
            }
        }
예제 #2
0
 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();
 }
예제 #3
0
 private void BleCallBack_OnServicesUndiscoveredEvent(object sender, YsBleCallBack.EventModel_SII e)
 {
     IsConnected = false;
     Act_OnLeDeviceConnectChange?.Invoke(BleConnectState.DisConnect);
 }
예제 #4
0
 private void BleCallBack_OnDisconnectedEvent(object sender, string e)
 {
     IsConnected = false;
     Act_OnLeDeviceConnectChange?.Invoke(BleConnectState.DisConnect);
 }
예제 #5
0
 private void BleCallBack_OnConnectionErrorEvent(object sender, YsBleCallBack.EventModel_SII e)
 {
     IsConnecting = false;
     IsConnected  = false;
     Act_OnLeDeviceConnectChange?.Invoke(BleConnectState.ConnectionError);
 }
예제 #6
0
 private void BleCallBack_OnConnectTimeoutEvent(object sender, string e)
 {
     IsConnecting = false;
     IsConnected  = false;
     Act_OnLeDeviceConnectChange?.Invoke(BleConnectState.ConnectionTimeOut);
 }