【问题标题】:Change font size programmatically on thermal Bluetooth Printer在热敏蓝牙打印机上以编程方式更改字体大小
【发布时间】:2019-05-15 02:27:47
【问题描述】:

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

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

正常打印文本

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

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


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

在服务/特征发现时,我们发现 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

包含通知

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

包含 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

包含 WRITE WRITETHOUTRESPONSE NOTIFY READ INDICATE


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

包含 WRITE WRITEWITHOUTRESPONSE


D:

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

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

包含阅读

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

包含阅读

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

包含阅读

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

包含阅读


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

【问题讨论】:

    标签: swift printing bluetooth font-size cbperipheral


    【解决方案1】:

    已解决:在找到 ESC/POS commandsthis StackOverflow post 后,我能够使用以下函数更改称为 M58-LL 或 ZJ-5805 的打印机的打印尺寸,该函数采用十六进制代码数组,将它们转换为 @987654323 @,然后添加到Character 并将它们附加到String,该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
    

    【讨论】:

    • 对于双倍高宽,正确的是:[0x1b,0x21,0x30] //doubleHeightAndWidth
    • 小字体和默认字体之间有没有可用于中等字体的命令?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 2019-11-23
    • 2019-01-27
    • 2019-08-27
    • 2022-12-25
    • 2013-11-11
    相关资源
    最近更新 更多