コード例 #1
0
        async void RegisterForInboundPairingRequests()
        {
            // Make the system discoverable for Bluetooth
            await MakeDiscoverable();

            // If the attempt to make the system discoverable failed then likely there is no Bluetooth device present
            // so leave the diagnositic message put out by the call to MakeDiscoverable()
            if (App.IsBluetoothDiscoverable)
            {
                string formatString;
                string confirmationMessage;

                // Get state of ceremony checkboxes
                DevicePairingKinds ceremoniesSelected = GetSelectedCeremonies();
                int iCurrentSelectedCeremonies        = (int)ceremoniesSelected;

                // Find out if we changed the ceremonies we orginally registered with - if we have registered before these will be saved
                var    localSettings            = Windows.Storage.ApplicationData.Current.LocalSettings;
                Object supportedPairingKinds    = localSettings.Values["supportedPairingKinds"];
                int    iSavedSelectedCeremonies = -1; // Deliberate impossible value
                if (supportedPairingKinds != null)
                {
                    iSavedSelectedCeremonies = (int)supportedPairingKinds;
                }

                ResourceLoader loader = ResourceLoader.GetForCurrentView();

                if (!DeviceInformationPairing.TryRegisterForAllInboundPairingRequests(ceremoniesSelected))
                {
                    confirmationMessage = loader.GetString("BluetoothInboundRegistrationFailed/Text");
                }
                else
                {
                    // Save off the ceremonies we registered with
                    localSettings.Values["supportedPairingKinds"] = iCurrentSelectedCeremonies;
                    formatString        = loader.GetString("BluetoothInboundRegistrationSucceeded/Text");
                    confirmationMessage = formatString + ceremoniesSelected.ToString();
                }

                // Clear the current collection
                BluetoothDevices.Clear();
                // Start the watcher
                StartWatcher();
                // Display a message
                confirmationMessage += loader.GetString("BluetoothOn/Text");
                DisplayMessagePanelAsync(confirmationMessage, MessageType.InformationalMessage);
            }
        }
コード例 #2
0
        public async void TurnOffBluetooth()
        {
            // Clear any devices in the list
            BluetoothDevices.Clear();
            // Stop the watcher
            //Check StopWatcher();

            // Display a message
            ResourceLoader loader = ResourceLoader.GetForCurrentView();
            string         confirmationMessage = loader.GetString("BluetoothOff/Text");

            DisplayMessagePanelAsync(confirmationMessage, MessageType.InformationalMessage);

            StackLoadingVisibility = false;

            await ToggleBluetoothAsync(false);
        }
コード例 #3
0
        public void SearchForDevices()
        {
            BluetoothDevices.Clear();
            localEndPoint = new BluetoothEndPoint(CurrentAdapter.LocalAddress, BluetoothService.SerialPort);
            client        = new BluetoothClient(localEndPoint);
            foreach (BluetoothDeviceInfo device in client.DiscoverDevices())
            {
                BluetoothDevices.Add(device);
            }

            if (BluetoothDevices.Any())
            {
                ChosenDevice = BluetoothDevices[0];
            }
            else
            {
                MessageBox.Show("No bluetooth devices were found", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #4
0
        public void SearchForDevices()
        {
            // urządzenia znalezione w poprzednim wyszukiwaniu nie muszą być aktywne przy aktualnym wyszukaniu
            BluetoothDevices.Clear();

            // utworzenie endpointu (adres hosta i port usługi (emulacja portu szeregowego))
            localEndPoint = new BluetoothEndPoint(CurrentAdapter.LocalAddress, BluetoothService.SerialPort);
            client        = new BluetoothClient(localEndPoint);

            // przepisanie znalezionych urządzeń za pomocą client.DiscoverDevices() do BluetoothDevice
            foreach (BluetoothDeviceInfo device in client.DiscoverDevices())
            {
                BluetoothDevices.Add(device);
            }

            if (BluetoothDevices.Any())
            {
                ChosenDevice = BluetoothDevices[0];
            }
            else
            {
                MessageBox.Show("Nie znaleziono urządzeń bluetooth", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }