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

时间:2018-12-13 19:55:31

标签: swift printing bluetooth font-size cbperipheral

我有一台58毫米的“ MINI热敏打印机”,型号:ZJ-5805DD,可与POS应用程序一起用作POS打印机。

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

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

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


改变字体的打印尺寸对我来说已是死胡同。我知道这是有可能的,因为打印机操作员让我从AppStore下载了打印测试仪“ POS-PrinterV1.0”,可以更改字体大小

关于服务/特征发现,我们发现4个服务A,B,C,D(为简化讨论)

A:

  

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

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

包含通知

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

包含写信时无回应


B:

  

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

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

包含写信无应答通知读指示


C:

  

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

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

包含通知指示

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

包含写信时无回应


D:

  

CBService:0x1c0a68300,​​isPrimary = YES,UUID =设备信息

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

包含READ

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

包含READ

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

包含READ

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

包含读取


几天来,我一直在互联网上寻找Swift解决方案。请有人帮忙吗?

1 个答案:

答案 0 :(得分:0)

已解决:找到ESC/POS commandsthis StackOverflow post之后,我可以使用以下采用十六进制数组的函数来更改名为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