コード例 #1
0
 public static void HandleResult(int result)
 {
     if (!Enum.IsDefined(typeof(BluetoothError), result))
     {
         throw new Win32Exception(result);
     }
     else
     {
         BluetoothError error = (BluetoothError)result;
         if (error != BluetoothError.BTH_ERROR_SUCCESS)
         {
             throw new Win32Exception(result, error.ToString());
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Invoked as an event handler when the status of the publisher changes.
        /// </summary>
        /// <param name="publisher">Instance of publisher that triggered the event.</param>
        /// <param name="eventArgs">Event data containing information about the publisher status change event.</param>
        private async void OnAdvertiserStatusChanged(
            BluetoothLEAdvertisementPublisher publisher,
            BluetoothLEAdvertisementPublisherStatusChangedEventArgs eventArgs)
        {
            // This event handler can be used to monitor the status of the publisher.
            // We can catch errors if the publisher is aborted by the system
            BluetoothLEAdvertisementPublisherStatus status = eventArgs.Status;
            BluetoothError error = eventArgs.Error;

            if (error == BluetoothError.Success)
            {
                setStatus(status.ToString());

                switch (status)
                {
                case BluetoothLEAdvertisementPublisherStatus.Started:
                    setStatus("Connecting...");
                    try
                    {
                        var connectionTask   = this.AncsManager.Connect();
                        var connectionResult = await connectionTask;

                        //var connectionResult = await this.AncsManager.Connect();
                        if (connectionResult == true)
                        {
                            setStatus("Waiting for device...");
                        }
                        else
                        {
                            setStatus("No suitable device");
                        }
                    }
                    catch (Exception ex)
                    {
                        setStatus(ex.Message);
                    }

                    break;
                }
            }
            else
            {
                setStatus(String.Format("Error: {0}", error.ToString()));
            }
        }
コード例 #3
0
        /// <summary>
        /// Invoked as an event handler when the status of the publisher changes.
        /// </summary>
        /// <param name="publisher">Instance of publisher that triggered the event.</param>
        /// <param name="eventArgs">Event data containing information about the publisher status change event.</param>
        private async void OnPublisherStatusChanged(
            BluetoothLEAdvertisementPublisher publisher,
            BluetoothLEAdvertisementPublisherStatusChangedEventArgs eventArgs)
        {
            // This event handler can be used to monitor the status of the publisher.
            // We can catch errors if the publisher is aborted by the system
            BluetoothLEAdvertisementPublisherStatus status = eventArgs.Status;
            BluetoothError error = eventArgs.Error;

            // Update the publisher status displayed in the sample
            // Serialize UI update to the main UI thread
            await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                PublisherStatusBlock.Text = string.Format("Published Status: {0}, Error: {1}",
                                                          status.ToString(),
                                                          error.ToString());
            });
        }
コード例 #4
0
 public static void HandleError(int result)
 {
     if (Enum.IsDefined(typeof(BluetoothError), result))
     {
         BluetoothError error = (BluetoothError)result;
         if (error != BluetoothError.BTH_ERROR_SUCCESS)
         {
             throw new Win32Exception(error.ToString());
         }
     }
     if (result == 0)
     {
         result = Marshal.GetLastWin32Error();
     }
     if (result != 0 && result != 1008 && result != 1168)
     {
         throw new Win32Exception(result);
     }
 }