【问题标题】:Printing Text on Thermal Printer using Bluetooth and ESC/POS使用蓝牙和 ESC/POS 在热敏打印机上打印文本
【发布时间】:2021-04-14 14:56:04
【问题描述】:

我正在尝试使用 ESC/POS 命令在我的蓝牙热敏打印机上打印文本,但我无法实现。我有一个连接到蓝牙的类:

try
            {
                BluetoothDevice printer = null;

                if (devices == null)
                    devices = BluetoothAdapter.DefaultAdapter.BondedDevices;

                List<BluetoothDevice> devicesBonded = new List<BluetoothDevice>();

                foreach (var device in devices)
                {
                    if (device.Name != name)
                        continue;

                    printer = device;
                    break;
                }

                socket = printer.CreateInsecureRfcommSocketToServiceRecord(UUID.FromString("00001101-0000-1000-8000-00805F9B34FB"));
                socket.Connect();

                if (!socket.IsConnected)
                    return false;

                return true;
            }
            catch (Exception)
            {
                return false;
            }

还有一个要打印的类,称为Print(byte[] bytesPrint):

try
            {
                string textPrint = System.Text.Encoding.UTF8.GetString(bytesPrint);

                bytesPrint = Encoding.UTF8.GetBytes(textPrint);

                var teste = socket.RemoteDevice;

                var outStream = (OutputStreamInvoker) socket.OutputStream;

                await outStream.WriteAsync(bytesPrint, 0, bytesPrint.Length);
                
                socket.Close();
            }catch(Exception e)
            {
                socket.Close();
            }

在某些情况下它位于 byte[] 中,但打印正确(没有 ESC/POS 命令)。但我需要对齐文本、更改字体大小、字体系列并打印出来!但是我找不到带有 ESC/POS 命令及其用法的库或类。我不想使用AppendFormat(),因为它太相关了,取决于我要打印的纸张尺寸。

有谁知道怎么做(请举例)?

【问题讨论】:

  • 找到命令手册:pos-x.com/download/escpos-programming-manual 有用吗?
  • 我已经很久没有这样做了,但是这个字节数组应该打开 bold; new byte[]{0x1b, 0x45, 0x00}
  • @Russ 不,它没有如何更改字体大小和字体系列。请发布一些示例以澄清。
  • @Jason 不工作。我尝试了其他命令并进行了其他操作,但我找不到帖子中的上述三个(文本对齐、字体大小和字体系列)。如果可以的话,请发布一些示例。
  • 您阅读过您的打印机的手册吗?这些东西可能因供应商而异,甚至因型号而异。还有 235 个标记为“escpos”的问题,您可以查看以获取想法。

标签: c# xamarin xamarin.forms thermal-printer escpos


【解决方案1】:

使用reference 将字节数组发送到蓝牙流。不使用 ESC/P 就无法真正进行打印,它只是隐藏在 SDK 抽象层之下。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-23
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 2014-06-27
    • 2014-02-18
    • 2019-08-27
    相关资源
    最近更新 更多