【问题标题】:Bluetooth Printer is not working in windows phone 8.1蓝牙打印机在 windows phone 8.1 中不工作
【发布时间】:2015-06-18 10:54:25
【问题描述】:
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
            {

            }
        }

当我调试代码时,此代码工作正常。但是当我在没有调试操作的情况下运行代码时无法执行。当我调试此代码时,它工作正常。我怎么了。

![打印演示][10![]]1

【问题讨论】:

  • 为什么要大写?
  • 听不懂你说什么

标签: windows-phone-7 windows-phone-8 windows-phone windows-phone-8.1 windows-phone-7.1


【解决方案1】:

我不知道您使用的是什么打印机,但您需要指定一些命令。对于 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{ }
}

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

【讨论】:

  • 听起来很奇怪...可能您在设备搜索方面遇到问题。将您的 try..catch 移动到您的整个代码中以查找错误。在您的捕获中放置一条弹出消息。告诉我。
  • 有时打印正常,但有时打印“ok”“ok”“error1”,有时不打印
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多