蓝牙打印机的小字体打印命令

时间:2019-07-11 08:59:30

标签: xamarin xamarin.android android-bluetooth thermal-printer

我正在研究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;
                }
            }

0 个答案:

没有答案
相关问题