Unable to connect to bluetooth printer

2

I have a Visual Studio 2013 C#.net 4.5 project for Windows Phone 8.0 where I am trying to connect with a bluetooth printer. The phone is already paired with the printer.

I've tried two methods. In both examples only one device is paired with the phone and that device is correctly found by FindAllPeersAsync. Each yields a different exception.

Method 1:

PeerFinder.AllowBluetooth = true;
PeerFinder.Start();
PeerFinder.AlternateIdentities["Bluetooth:SDP"] = "{00001101-0000-1000-8000-00805F9B34FB}"; // Serial
var peers = await PeerFinder.FindAllPeersAsync();

// System.Exception: The connection was refused. (Exception from HRESULT: 0x8063010B)
using (var ss = await PeerFinder.ConnectAsync(peer))
{
    await ss.OutputStream.WriteAsync(System.Text.Encoding.UTF8.GetBytes("this is a test").AsBuffer());
}

Method 2:

PeerFinder.AllowBluetooth = true;
PeerFinder.Start();
PeerFinder.AlternateIdentities["Bluetooth:SDP"] = "{00001101-0000-1000-8000-00805F9B34FB}";
var peers = await PeerFinder.FindAllPeersAsync();
using (StreamSocket ss = new StreamSocket())
{

    // System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
    await ss.ConnectAsync(peers[0].HostName, "1", SocketProtectionLevel.PlainSocket);

    await ss.OutputStream.WriteAsync(System.Text.Encoding.UTF8.GetBytes("this is a test").AsBuffer());
}

I have ID_CAP_PROXIMITY and ID_CAP_NETWORKING activated.

What do I need to do to be able to connect with a bluetooth device?

c#
windows-phone-8
bluetooth
asked on Stack Overflow Mar 28, 2014 by PaulH

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0