Error Connecting to Windows Phone 8.1 Silverlight Bluetooth Printer

Asked

Viewed 145 times

3

Trying to connect to the Bluetooth Printer gives the following error. " No more data is available. (Exception from HRESULT: 0x80070103)".

This error only came from Visual Studio 2013, in Visual Studio 2012 It worked normal.
My Code.

            PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "BlueTooth Printer";
            var pairedDevices = await PeerFinder.FindAllPeersAsync();

            if (pairedDevices.Count == 0)
            {
                MessageBox.Show("No paired devices were found.");
            }
            else
            {
                PeerInformation selectedDevice = pairedDevices[0];
                StreamSocket socket = new StreamSocket();

                await socket.ConnectAsync(selectedDevice.HostName, "1");
                await socket.OutputStream.WriteAsync(WindowsRuntimeBufferExtensions.AsBuffer(buffer));
                socket.Dispose();
            }
  • 1

    This topic no msdn helps at something?

  • @Thanks guy worked, now adds as an answer to I give you the points.

  • Don’t worry about it, man. Put as answer to your solution and if you have found the reason for this exception to be released on VS2013 and not VS2012, also include. :)

1 answer

2


DeviceInformationCollection DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
var numDevices = DeviceInfoCollection.Count();

if (numDevices == 0)
{
   MessageDialog md = new MessageDialog("No paired devices found", "Title");
   await md.ShowAsync();
   return;
}

DeviceInformation DeviceInfo = DeviceInfoCollection[0];

StreamSocket socket = null;
try
{
   var service = await RfcommDeviceService.FromIdAsync( DeviceInfo.Id);

   socket = new StreamSocket();

// Note: If either parameter is null or empty, the call will throw an exception
await socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName, service.ProtectionLevel);


// If the connection was successful, the RemoteAddress field will be populated
MessageDialog md = new MessageDialog(String.Format("Connected to {0}!", socket.Information.RemoteAddress.DisplayName), "Title");
await md.ShowAsync();
}
catch (Exception ex)
{
  socket.Dispose();
  socket = null;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.