Error Connecting to Bluetooth Printer Windows Phone 8.1 Silverlight

3

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

This error only occurred 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();
            }
    
asked by anonymous 12.05.2015 / 14:02

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;
}
    
15.05.2015 / 15:53