连接到微型打印机ZEBRA iMZ320和nativescript

问题描述 投票:0回答:1

我想以蓝牙不安全模式连接ZEBRA打印机。我遵循了文档,但无法write

我做的第一件事是导入所有需要的.jar库:

List of folders

首先是我的ticket.component.ts

declare var com: any

现在,我可以访问.jar,因此我尝试进行打印:

ngOnInit() {
    let bluetooth = new Bluetooth()
    bluetooth
      .enable()
      .then(enableb => {
        this.thePrinterConn = new com.zebra.sdk.comm.BluetoothConnectionInsecure(
          "AC:3F:A3:51:D2:12"
        )

        this.thePrinterConn.open()

        // This sends down JSON to the status channel to retrieve the 'appl.name'
        // setting
        let firmwareVersion = new com.zebra.sdk.printer.SGD.GET(
          "appl.name",
          this.thePrinterConn
        )

        console.log("The firmware version is : ", firmwareVersion)

        let str = "^XA^FO20,20^A0N,25,25^FD Works! ZPL^FS^XZ"

        var bytesv2 = [] // char codes

        for (var i = 0; i < str.length; ++i) {
          var code = str.charCodeAt(i)

          bytesv2 = bytesv2.concat([code & 0xff, (code / 256) >>> 0])
        }

        // 72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 220, 122
        console.log("bytesv2", bytesv2)

        // Send the data to printer as a byte array.
        try {
          this.thePrinterConn.write(bytesv2)

          // Make sure the data got to the printer before closing the connection
          setTimeout(() => {
            // Close the insecure connection to release resources.
            console.log("Close")
            this.thePrinterConn.close()
          }, 1000)
        } catch (error) {
          throw error
        }
      })
      .catch(err => {
        console.log(err)
        this.thePrinterConn.close()
      })
  }

但我收到此错误:

JS:错误:无法将数组转换为Ljava / io / InputStream;在索引0

Docs from zebra

编辑

显然,如果我用以下几行转换bytestv2,则可以使用:

 var byteArr = Array.create("byte", bytesv2.length)

        let contador = 0
        bytesv2.forEach(x => {
          byteArr[contador] = x
          contador++
        })

nativescript docs中找到

但是打印机仅送纸。

android nativescript nativescript-angular zebra-printers
1个回答
0
投票

将LF和CR添加到ZPL字符串的末尾以确保正确的结尾let str =“ ^ XA ^ FO20,20 ^ A0N,25,25 ^ FD工作!ZPL ^ FS ^ XZ \ r \ n”

如果仅看到进纸但没有看到实际打印,请确保将打印机语言设置为ZPL,并且将介质长度设置为足以覆盖打印高度。! U1 setvar“ device.languages”“ zpl”! U1 setvar“ zpl.label_length”“ 100”

© www.soinside.com 2019 - 2024. All rights reserved.