在热敏蓝牙打印机上以编程方式更改字体大小

Change font size programmatically on thermal Bluetooth Printer

我有一台 58mm 'MINI Thermal Printer',型号:ZJ-5805DD,可用作我的 POS 应用程序的 POS 打印机。

我已经成功地通过蓝牙以编程方式将我的应用程序连接到打印机,并且可以使用

打印文本。

KitchenPrinter.writeValue(myStringData, for: A2orC2, type: .withoutResponse)

*注意:A2 或 C2 [见下文] 特性产生相同的文本打印输出。


更改字体打印大小已成为我的死胡同。我知道这是可能的,因为打印机手册让我从 AppStore 下载打印测试器 "POS-PrinterV1.0",它可以更改字体大小

根据 Service/Characteristic 发现,我们找到 4 个服务 A、B、C、D(为了讨论的简单性)

甲:

CBService: 0x1c0a6a5c0, isPrimary = YES, UUID = 49535343-FE7D-4AE5-8FA9-9FAFD205E455

CBCharacteristic: 0x1c02adf80, UUID = 49535343-1E4D-4BD9-BA61-23C647249616, properties = 0x10, value = (null), notifying = NO

contains NOTIFY

CBCharacteristic: 0x1c02bba80, UUID = 49535343-8841-43F4-A8D4-ECBE34729BB3, properties = 0xC, value = (null), notifying = NO

contains WRITE WRITEWITHOUTRESPONSE


乙:

CBService: 0x1c0a6ce80, isPrimary = YES, UUID = E7810A71-73AE-499D-8C15-FAA9AEF0C3F2

  CBCharacteristic: 0x1c02adfe0, UUID = BEF8D6C9-9C21-4C9E-B632-BD58C1009F9F, properties = 0x3E, value = (null), notifying = NO

contains WRITE WRITEWITHOUTRESPONSE NOTIFY READ INDICATE


C:

CBService: 0x1c0a69100, isPrimary = YES, UUID = 18F0

  CBCharacteristic: 0x1c02b8000, UUID = 2AF0, properties = 0x30, value = (null), notifying = NO

contains NOTIFY INDICATE

  CBCharacteristic: 0x1c02a5700, UUID = 2AF1, properties = 0xC, value = (null), notifying = NO

contains WRITE WRITEWITHOUTRESPONSE


D:

CBService: 0x1c0a68300, isPrimary = YES, UUID = Device Information

  CBCharacteristic: 0x1c02a5dc0, UUID = Serial Number String, properties = 0x2, value = (null), notifying = NO

contains READ

  CBCharacteristic: 0x1c02a77a0, UUID = Software Revision String, properties = 0x2, value = (null), notifying = NO

contains READ

  CBCharacteristic: 0x1c02a76e0, UUID = Hardware Revision String, properties = 0x2, value = (null), notifying = NO

contains READ

  CBCharacteristic: 0x1c02a6060, UUID = Manufacturer Name String, properties = 0x2, value = (null), notifying = NO

contains READ


几天来我一直在网上搜索 Swift 解决方案。有人可以帮忙吗?

已解决:找到 ESC/POS commands and 后,我能够使用以下函数更改打印机 M58-LL 或 ZJ-5805 上的打印尺寸,该函数采用十六进制代码数组,将它们转换为 UnicodeScalar,然后到 Character,并将它们附加到 String,后者作为文本打印输出被发送到打印机。

let hexs = [0x1b,0x21,0x20] //doubleWide
var hexString = String() 
for all in hexs {
    if let scalar = UnicodeScalar(all) {
        hexString.append(Character(scalar))
    }
}
let theData = hexString.data(using: .utf8)!
myPrinter.writeValue(theData, for: printCharacteristic, type: .withoutResponse)

//printCharacteristic corresponds with Service/Characteristic B

[0x1b,0x21,0x00] //default
[0x1b,0x21,0x01] //small font
[0x1b,0x21,0x08] //bold
[0x1b,0x21,0x10] //doubleHeight
[0x1b,0x21,0x20] //doubleWidth
[0x1b,0x21,0x20] //doubleHeightAndWidth