带有ConnectAsync的Windows Phone 8蓝牙错误 [英] Windows Phone 8 Bluetooth Error w/ ConnectAsync

查看:89
本文介绍了带有ConnectAsync的Windows Phone 8蓝牙错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Windows Phone连接到蓝牙设备。该设备已配对。该设备已知在Android手机上工作和测试。

I'm attempting to connect to a Bluetooth device from a Windows Phone. The device is already paired. The device is know to work and tested on an Android phone.

当目标设备是Windows Phone 8时调用ConnectAsync时出现以下错误:

When calling ConnectAsync when the target device is Windows Phone 8 I get the following error:

"无法执行对套接字的操作,因为系统缺少足够的缓冲区空间或因为队列已满。无法执行套接字上的操作,因为系统缺少足够的缓冲区空间或因为队列是
已满。"

"An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full. An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full."

  在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

  在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

  在System.Runtime.CompilerServices.TaskAwaiter.GetResult()

  在BluetoothTest.MainPage< ConnectAppToDevice> d__1.MoveNext()

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at BluetoothTest.MainPage.<ConnectAppToDevice>d__1.MoveNext()

如果我使目标设备的Windows Phone 8.1我得到以下错误(无代码的修改):

If I make the target device Windows Phone 8.1 I get the following error (no code modifications):

"找不到元素。 (HRESULT的例外情况:0x80070490)"

"Element not found. (Exception from HRESULT: 0x80070490)"

  在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)

  在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)

  在System.Runtime.CompilerServices.TaskAwaiter.GetResult()

  在BluetoothTest.MainPage< ConnectToDevice> d__4.MoveNext()

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at BluetoothTest.MainPage.<ConnectToDevice>d__4.MoveNext()

所述设备的供应商向我保证服务名称为正确(掩蔽瓦特/ XXXX):

The vendor of the device assures me that the service name is correct (masked w/ XXXX):

<跨度风格=" 颜色:#a31515;字体大小:小">" {0000XXXX-0000-1000-8000-00805f9b34fb}"

        private async void ConnectAppToDevice()

        {

           试试
            {

                PeerFinder.AlternateIdentities ["蓝牙:配对"] ="英寸;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; VAR同行=等待PeerFinder.FindAllPeersAsync();

        private async void ConnectAppToDevice()
        {
            try
            {
                PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
                var peers = await PeerFinder.FindAllPeersAsync();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; //短路,以获得专门从列举的设备

&NBSP配对的设备;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; PeerInformation伙伴=同行[1];

                // short circuit to get the know paired device from enumerated devices
                PeerInformation partner = peers[1];

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; StreamSocket插座=新StreamSocket();

                StreamSocket socket = new StreamSocket();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;提供的,因为它不是在PeerInformation类

&NBSP填充//服务名;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP; await socket.ConnectAsync(partner.HostName,SERVICE_NAME);

            }
            catch(例外情况)

            {

                if((uint)ex.HResult == 0x8007048F)

                {

                    MessageBox.Show(QUOT;蓝牙OFF");

                // service name supplied because it is not populated in the PeerInformation class
                await socket.ConnectAsync(partner.HostName, SERVICE_NAME);
            }
            catch (Exception ex)
            {
                if ((uint)ex.HResult == 0x8007048F)
                {
                    MessageBox.Show("Bluetooth OFF");

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;尝试

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; ConnectionSettingsTask connectionSettingsTask =新ConnectionSettingsTask

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; ConnectionSettingsType = ConnectionSettingsType.Bluetooth

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP; };

                    try
                    {
                        ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask
                        {
                            ConnectionSettingsType = ConnectionSettingsType.Bluetooth
                        };

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP; connectionSettingsTask.Show();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP; }
                   赶上(例外)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; MessageBox.Show(ex.Message);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; }
                }
               否则,如果((UINT)ex.HResult == 0X80070005)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; {

                    MessageBox.Show(QUOT;缺少帽");

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }
               否则b $ b                {

                    MessageBox.Show(ex.Message);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }
            }
        }

                        connectionSettingsTask.Show();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else if ((uint)ex.HResult == 0x80070005)
                {
                    MessageBox.Show("Missing Caps");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }




































































































































































































































































































































































































































































































SERVICE_NAME =
" {00001815-0000-1000-8000-00805f9b34fb}" ;

SERVICE_NAME = "{00001815-0000-1000-8000-00805f9b34fb}";

推荐答案

您可以在这里试用代码:

https://msdn.microsoft.com/en-us/library/windows/apps/dn264579.aspx

Can you try the code here:
https://msdn.microsoft.com/en-us/library/windows/apps/dn264579.aspx

什么样的设备是什么,你想做什么?

What kind of device is it and what are you trying to do?


这篇关于带有ConnectAsync的Windows Phone 8蓝牙错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆