首页 > 解决方案 > 蓝牙打印机小字体打印命令

问题描述

我正在开发 Xamarin android 中的蓝牙热敏打印机实现,我可以在其中重置打印机并使用打印命令添加另外三行,但在将字体重置为最小尺寸时遇到问题。

我正在使用命令“btInitialise”重置打印机,然后尝试使用命令“btFontB”设置小字体,然后使用“btAdvance3Lines”添加 3 个空白附加行。

“btFontB”中的命令无法正常工作或命令错误或我试图实现的方式错误。在这里将不胜感激。

using (BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter)
            {
                BluetoothDevice device = (from bd in bluetoothAdapter?.BondedDevices where bd?.Name == deviceName
 select bd).FirstOrDefault();

                try
                {
                    using (BluetoothSocket bluetoothSocket = device?.
                        CreateRfcommSocketToServiceRecord(
                        UUID.FromString("00001101-0000-1000-8000-00805f9b34fb")))
                    {
                        if (bluetoothSocket == null)
                            return;

                        string btInitialise = "\x001b\x0040\n";
                        string btFontB = "\x001b\x0021\x0000\n";
                        string btAdvance3Lines = "\x001b\x0064\x0003\n";

                        await bluetoothSocket.ConnectAsync();

                        byte[] resetPrinter = Encoding.ASCII.GetBytes(btInitialise);
                        await bluetoothSocket.OutputStream.WriteAsync(resetPrinter, 0, resetPrinter.Length);

                        byte[] setFont = Encoding.ASCII.GetBytes(btFontB);
                        await bluetoothSocket.OutputStream.WriteAsync(setFont, 0, setFont.Length);



                        byte[] buffer = Encoding.UTF8.GetBytes(text);
                        await bluetoothSocket.OutputStream.WriteAsync(buffer, 0, buffer.Length);


                        byte[] addLines = Encoding.ASCII.GetBytes(btAdvance3Lines);
                        await bluetoothSocket.OutputStream.WriteAsync(addLines, 0, addLines.Length);
                    }
                }
                catch (Exception exp)
                {
                    throw exp;
                }
            }

标签: xamarinxamarin.androidandroid-bluetooththermal-printer

解决方案


推荐阅读