Windows phone 8.1 streamsocket.connectAsync生成“没有更多数据可用。(HRESULT异常:0x80070103)”

时间:2015-07-04 21:10:57

标签: bluetooth windows-phone-8.1

我正在开发必须在蓝牙打印机上打印的Windows Phone 8.1商店应用程序(XAML)。

使用前两种方法成功找到设备:

 PeerFinder.AllowBluetooth = True
            PeerFinder.Role = PeerRole.Client
            PeerFinder.AlternateIdentities.Item("Bluetooth:SDP") = "{00001101-0000-1000-8000-00805F9B34FB}"
            'PeerFinder.AlternateIdentities.Item("Bluetooth:Paired") = ""

            Dim devs = Await PeerFinder.FindAllPeersAsync()
            Dim dev As PeerInformation = devs(0)

            Dim btdevs = Await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelector())
            Dim btdv = btdevs(0)

未找到:

            Dim dfdevs1 = Await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort))
            ' same result with Await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(New Guid("00001101-0000-1000-8000-00805F9B34FB")))

不幸的是,只有最后一个方法会给我“streamServiceName”才能在StreamSocket.ConnectAsync中使用

我尝试过StreamSocket.ConnectAsync的不同组合:

dim _soc = New StreamSocket()
Await _soc.ConnectAsync(dev.HostName, "1")

“没有更多数据可用。(HRESULT异常:0x80070103)”

相同
 dim _soc = New StreamSocket()
 Await _soc.ConnectAsync(dev.HostName, "{00001101-0000-1000-8000-00805F9B34FB}"

正如你可以想象的那样

 dim _soc = New StreamSocket()
 Await _soc.ConnectAsync(btdv.HostName, "{00001101-0000-1000-8000-00805F9B34FB}"
经过几天的敲打,我真的没有想法了。最让我烦恼的是,第一个代码组合适用于Windows Phone 8.0

是的,在AppManifest中,一切都已确定:

 <DeviceCapability Name="proximity" />
    <m2:DeviceCapability Name="bluetooth.rfcomm">
      <m2:Device Id="any">
        <!--<m2:Function Type="name:serialPort" />-->
        <m2:Function Type="serviceId:00001101-0000-1000-8000-00805F9B34FB" />
      </m2:Device>
    </m2:DeviceCapability>

任何想法都将受到高度赞赏。

1 个答案:

答案 0 :(得分:1)

在我们发言时,我也正在研究这个问题,并且我取得了很好的进展。对我来说,问题出现在我从WP8升级到WP8.1(silverlight)之后。

确保您的appxmanifest设置了以下权限:

<m2:DeviceCapability Name="bluetooth.rfcomm">
  <m2:Device Id="any">
    <m2:Function Type="serviceId:00001101-0000-1000-8000-00805f9b34fb" />
    <m2:Function Type="name:serialPort" />
  </m2:Device>
</m2:DeviceCapability>

下面是我的示例代码,似乎允许连接(至少在我的测试中到目前为止!)

                PeerFinder.AlternateIdentities["Bluetooth:SDP"] = "{00001101-0000-1000-8000-00805f9b34fb}";

                //find the device from the device list we are trying to connect to
                var selector = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort);
                var dev = await DeviceInformation.FindAllAsync(selector, null);
                var devA = dev.Where(f => f.Name.Equals(_item.Device.DisplayName)).FirstOrDefault();

                //get the service
                RfcommDeviceService service = await RfcommDeviceService.FromIdAsync(devA.Id);

                //create the connection
                await Common.Instance.Socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName);
                MetaData.Instance.BlueBoxRef = _item.Device.DisplayName.Substring(8);
                NavigationService.Navigate(new Uri("/OpenDevice.xaml", UriKind.RelativeOrAbsolute));

我仍然需要检查这是否适用于其他设备,但请告诉我你是如何继续的!