plus.android.importClass(device)
var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid)
plus.android.importClass(bluetoothSocket)
if (!bluetoothSocket.isConnected()) {
bluetoothSocket.connect()
}
if (bluetoothSocket.isConnected()) {
以下代码在2.9.8之前版本正常执行,可与蓝牙打印机通信
3.0.5版本 不可以执行
var outputStream = bluetoothSocket.getOutputStream()
plus.android.importClass(outputStream)
var weightUnit = tag.weight + tag.unit
var health = tag.healthA + "/" + tag.healthC
var mfd = moment(tag.mfd).format('YYYY-MM-DD')
outputStream.write([0x1b, 0x40]) //reset
outputStream.write([0x1b, 0x57, 0x01]) //字体正常大小
outputStream.write([0x1b, 0x61, 0x00]) //左对齐
outputStream.write([0x1F, 0x55, 0x35, 0x01]) //加粗
var printMsg1 = "\r\n" + this.printTwoData("物料编号:", tag.materialNo)
var bytes1 = plus.android.invoke(printMsg1, 'getBytes', 'gbk')
outputStream.write(bytes1)
outputStream.write([0x1b, 0x57, 0x01]) //字体正常大小
outputStream.write([0x1F, 0x55, 0x35, 0x00]) //取消加粗
var printText =
"\r\n" + this.printTwoData("批次编号:", tag.batchNo) +
"\r\n" + this.printTwoData("生产日期:", mfd) +
"\r\n" + this.printTwoData("包装数量:", weightUnit) +
"\r\n" + this.printTwoData("健康(急性/慢性):", health) +
"\r\n" + this.printTwoData("易燃性:" + tag.inflammability)+
"\r\n" + this.printTwoData("反应性:" + tag.reactiveness) +
"\r\n" + this.printTwoData("人员防护:", tag.protective) +
"\r\n" + this.printTwoData("流水识别码:", tag.code) +
"\r\n";
var bytes = plus.android.invoke(printText, 'getBytes', 'gbk')
outputStream.write(bytes)
1 个回复
DCloud_Android_ST
用HX3.0.7版本试下