Windows phone 8.1 streamsocket.connectAsync generate "No more data is available. (Exception from HRESULT: 0x80070103)"

5

I am developing Windows Phone 8.1 stores app (XAML) that must print on Bluetooth printer.

The device is found successfully with first two methods:

 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)

And not found in:

            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")))

Unfortunately, only the last method will give to me the "remoteServiceName" for using in StreamSocket.ConnectAsync

I have tried different combination for StreamSocket.ConnectAsync :

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

"No more data is available. (Exception from HRESULT: 0x80070103)"

Same for

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

And as you can imagine the same for

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

I am really out of ideas after some days of banging my head. And what annoys me most is that the first combination of code work perfectly for Windows Phone 8.0

And Yes, in AppManifest everything is set:

 <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>

Any ideas will be highly appreciated.

bluetooth
windows-phone-8.1
asked on Stack Overflow Jul 4, 2015 by jspassov

1 Answer

1

I am also working on this problem as we speak and I've made good progress. For me, the problem came about after I upgraded from WP8 to WP8.1 (silverlight).

Make sure your appxmanifest has the following permissions set:

<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>

Below is my sample code that appears to allow connections through (at least, so far in my testing!)

                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));

I still need to check if this works on other devices but please let me know how you get on!

answered on Stack Overflow Dec 8, 2016 by Will Johnson

User contributions licensed under CC BY-SA 3.0