蓝牙打印机无法在Windows Phone 8.1中使用

时间:2015-06-18 10:54:25

标签: windows-phone-7 windows-phone-8 windows-phone windows-phone-8.1 windows-phone-7.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
            {

            }
        }

当我调试代码时,此代码工作正常。但是当我在没有调试操作的情况下运行代码时无法执行。当我贬低这段代码时它的工作正常。我有什么问题。

![Printind demo] [10![]] 1

1 个答案:

答案 0 :(得分: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{ }
}

验证您的发布模式是否允许代码优化。