コード例 #1
0
        internal async Task <bool> ObtainBtDevice()
        {
            if (BtDevice != null)
            {
                return(true);
            }

            try
            {
                BtDevice = await BluetoothDevice.FromIdAsync(BtID);
            }
            catch (Exception)
            {
                if (BtDevice != null)
                {
                    BtDevice.Dispose();
                }

                BtDevice = null;
            }

            if (BtDevice == null)
            {
                return(false);
            }

            BtDevice.ConnectionStatusChanged += ConnectionStatusChanged;
            BtDevice.NameChanged             += NameChanged;
            BtDevice.SdpRecordsChanged       += ServiceChanged;

            if (BtDevice.ConnectionStatus == BluetoothConnectionStatus.Connected)
            {
                BtConnectionStateChangedObservers?.Invoke(this, BtDevice, BtDevice.ConnectionStatus);
            }

            return(true);
        }
コード例 #2
0
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Bluetooth Event Handlers
 private void ConnectionStatusChanged(BluetoothDevice sender, object args)
 {
     Log($"BtConnectionStatusChanged({sender.Name}, {sender.ConnectionStatus})");
     BtConnectionStateChangedObservers?.Invoke(this, sender, sender.ConnectionStatus);
 }