我有一个用于Windows Phone 8.0的Visual Studio 2013 C#.net 4.5项目,我正在尝试连接蓝牙打印机。手机已与打印机配对。
我尝试了两种方法。在这两个示例中,只有一个设备与手机配对,FindAllPeersAsync
正确找到了该设备。每个都会产生不同的例外。
方法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());
}
方法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());
}
我已激活ID_CAP_PROXIMITY和ID_CAP_NETWORKING。
能够连接蓝牙设备需要做什么?
答案 0 :(得分:0)
try { /* put your code here */ }
catch(exception ex){MessageBox.Show(ex.message);}
您的申请会出现什么类型的例外?