-1
string command = "Welcome To Solutions....                               "; 
     Byte[] buffer = new byte[command.Length]; 
     StreamSocket socket = null; 
     buffer = StringToAscii(command); 
     PeerFinder.AlternateIdentities["Bluetooth:Paired"] = ""; 
     var pairedDevices = await PeerFinder.FindAllPeersAsync(); 
     if (pairedDevices.Count == 0) 
     { 
      Debug.WriteLine("No paired devices were found."); 
     } 
     else 
     { 
      try 
      { 
       PeerInformation selectedDevice = pairedDevices[0]; 
       socket = new StreamSocket(); 
       await socket.ConnectAsync(selectedDevice.HostName, "1"); 
       await socket.OutputStream.WriteAsync(WindowsRuntimeBufferExtensions.AsBuffer(buffer)); 
       socket.Dispose(); 
       Array.Clear(buffer, 0, buffer.Length); 
      } 
      catch 
      { 

      } 
     } 

此代碼工作很好當我調試代碼。但是,當我運行代碼沒有調試行動無法執行。當我debuig這個代碼它工作正常。我怎麼了。藍牙打印機不工作在Windows Phone 8.1中

![Printind演示] [10![] 1

+0

爲什麼使用大寫字母? – moffeltje

+0

不明白你在說什麼 – Pradip

回答

0

我不知道什麼是您使用的打印機,但你需要指定一些命令。對於Zebra打印機,您的代碼如下所示:

string command = "^XA^LH30,30^F020,10^AD^FDWelcome To Solutions...^FS^XZ"; 
Byte[] buffer = new byte[command.Length]; 
StreamSocket socket = null; 
buffer = StringToAscii(command); 
PeerFinder.AlternateIdentities["Bluetooth:Paired"] = ""; 
var pairedDevices = await PeerFinder.FindAllPeersAsync(); 
if (pairedDevices.Count == 0) 
{ 
    Debug.WriteLine("No paired devices were found."); 
} 
else 
{ 
    try 
    { 
     PeerInformation selectedDevice = pairedDevices[0]; 
     socket = new StreamSocket(); 
     await socket.ConnectAsync(selectedDevice.HostName, "1"); 
     await socket.OutputStream.WriteAsync(WindowsRuntimeBufferExtensions.AsBuffer(buffer)); 
     socket.Dispose(); 
     Array.Clear(buffer, 0, buffer.Length); 
    } 
    catch{ } 
} 

驗證您的發行模式是否允許代碼優化。

+0

感謝你的回覆,但不工作 – Pradip

+0

聽起來很奇怪......你可能在設備搜索時遇到問題。將您的try..catch移動到您的整個代碼中,以便找到錯誤。在你的catch中加上一個Popup消息。讓我知道。 –

+0

有些時候可以打印,但有些時候可以打印「ok」「ok」「error1」,有些時候不打印 – Pradip