コード例 #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);
 }