Windows phone 7 蓝牙打印机在windows phone 8.1中不工作

Windows phone 7 蓝牙打印机在windows phone 8.1中不工作,windows-phone-7,windows-phone-8,windows-phone,windows-phone-8.1,windows-phone-7.1,Windows Phone 7,Windows Phone 8,Windows Phone,Windows Phone 8.1,Windows Phone 7.1,当我调试代码时,该代码运行良好。但是,当我在没有调试的情况下运行代码时,无法执行操作。当我去毛刺这个代码,它的工作很好。我怎么了 !![Printind demo][10![]我不知道您使用的是哪台打印机,但您需要指定一些命令。对于Zebra打印机,您的代码如下所示: string command = "Welcome To Solutions....

当我调试代码时,该代码运行良好。但是,当我在没有调试的情况下运行代码时,无法执行操作。当我去毛刺这个代码,它的工作很好。我怎么了


!![Printind demo][10![]

我不知道您使用的是哪台打印机,但您需要指定一些命令。对于Zebra打印机,您的代码如下所示:

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
            {

            }
        }

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

为什么使用大写字母?不明白您说的话听起来很奇怪。。。您可能在设备搜索方面有问题。将try..catch移到整个代码中以查找错误。在你的catch中放一条弹出消息。让我知道。有时打印ok,但有时打印“ok”“ok”“error1”,有时不打印
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{ }
}