Reputation: 468
I would like to connect a ZEBRA printer in bluetooth insecure mode. I followed the documentation but I cant write
.
The firts thing I did was import all .jar
libraries needed:
In my ticket.component.ts
first of all:
declare var com: any
Now, I can access to the .jar
, so I try this for print:
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()
})
}
But I get this error:
JS: Error: Cannot convert array to Ljava/io/InputStream; at index 0
Apparently works if I convert bytestv2
with this lines:
var byteArr = Array.create("byte", bytesv2.length)
let contador = 0
bytesv2.forEach(x => {
byteArr[contador] = x
contador++
})
Found in nativescript docs
But the printer only feed paper.
Upvotes: 0
Views: 372
Reputation: 81
Add the LF and CR to the end of ZPL string to ensure the proper ending
let str = "^XA^FO20,20^A0N,25,25^FD Works! ZPL^FS^XZ\r\n"
If you only see the paper feed but not the actual print, make sure that printer language is set to ZPL and the media length is set enough to cover the height of the print.
! U1 setvar "device.languages" "zpl"
! U1 setvar "zpl.label_length" "100"
Upvotes: 1