xamarin - 蓝牙打印机小字体打印命令
问题描述
我正在开发 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;
}
}
解决方案
推荐阅读
- python - 如何在python中解决这个Nameerror
- mysql - 如何从多个数据库中调用信息并将其显示在单个页面上?
- scala - 我可以使用 memoization 来缓存来自 spark 作业的 hbase 读写数据吗?
- python - python 3中具有多个输入的函数
- swiftui - SwiftUI 不使用 UIViewRepresentable 和 ObservableObject 刷新我的自定义 UIView
- c# - 如何仅在 Tesseract C# 中捕获数字
- ti-basic - 试图显示矩阵编辑器的位置
- linkedin - LinkedIn 访问基本资料
- java - 如果增加迭代次数,顺序流比并行流快
- json - 我需要使用 powershell 从 Json 文件中获取特定值