代码之家  ›  专栏  ›  技术社区  ›  Chameleon

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

  •  0
  • Chameleon  · 技术社区  · 7 年前

    我有一台58毫米的微型热敏打印机,型号: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
    

    包含writewithoutresponse


    B:

    cbservice:0x1c0a6ce80,isprimary=yes,uuid=e7801a71-73ae-499d-8c15-faa9aef0c3f2

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

    包含writewithoutresponse notify read指示


    丙:

    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
    

    包含writewithoutresponse


    D:

    cbservice:0x1c0a68300,isprimary=yes,uuid=device information

      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
    

    包含读取


    我在网上搜索了好几天,想找到一个快速的解决方案。有人能帮忙吗?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Chameleon    7 年前

    解决:发现后 ESC/POS commands this 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
    
    推荐文章