2014-03-28 132 views
2

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

是的。我將手機更新爲更新的AK並開始工作。 – PaulH

回答

0
       try { /* put your code here */ } 
           catch(exception ex){MessageBox.Show(ex.message);} 

什麼類型的異常會給你的應用程序?

+1

例外情況在代碼塊中作爲註釋生成它們的代碼行之上。第一個是winsock錯誤,第二個是權限錯誤。 – PaulH