uu
This commit is contained in:
parent
2e18b1bcd9
commit
bcd4de21cb
@ -420,6 +420,9 @@ var blueToothTool = {
|
|||||||
}
|
}
|
||||||
}, 40);
|
}, 40);
|
||||||
},
|
},
|
||||||
|
getBtOutStream(){
|
||||||
|
return btOutStream
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* 发送数据
|
* 发送数据
|
||||||
* @param {String} dataStr
|
* @param {String} dataStr
|
||||||
|
|||||||
@ -214,10 +214,6 @@ export default {
|
|||||||
},
|
},
|
||||||
getConData() {
|
getConData() {
|
||||||
return { deviceId: this.deviceId, }
|
return { deviceId: this.deviceId, }
|
||||||
},
|
|
||||||
sendByteData(data) {
|
|
||||||
let bl = bluetoothTool.sendByteData(data)
|
|
||||||
return bl
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
components/tpx-bluetooth-print/nativePrint/print.js
Normal file
14
components/tpx-bluetooth-print/nativePrint/print.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import nativeBlueTooth from "@/components/tpx-bluetooth-native/nativeBlueTooth"
|
||||||
|
|
||||||
|
const module = {
|
||||||
|
print(data){
|
||||||
|
let outputStream = nativeBlueTooth.getBtOutStream()
|
||||||
|
outputStream.write([0x1b, 0x40]) //打印复位
|
||||||
|
outputStream.flush()
|
||||||
|
nativeBlueTooth.sendByteData(data)
|
||||||
|
},
|
||||||
|
sendByteData: nativeBlueTooth.sendByteData,
|
||||||
|
sendData: nativeBlueTooth.sendData
|
||||||
|
}
|
||||||
|
|
||||||
|
export default module
|
||||||
@ -6,64 +6,6 @@
|
|||||||
//蓝牙打印机一次接收的二级制数据有限制,不同的系统不同的蓝牙设备限制可能不同,微信建议一次20个字节,需做递归分包发送
|
//蓝牙打印机一次接收的二级制数据有限制,不同的系统不同的蓝牙设备限制可能不同,微信建议一次20个字节,需做递归分包发送
|
||||||
//发送完要打印的内容后,一定要发送一个打印的指令才能顺利打印 (有些指令就不需要)
|
//发送完要打印的内容后,一定要发送一个打印的指令才能顺利打印 (有些指令就不需要)
|
||||||
|
|
||||||
export function senBlData(uint8Array) {
|
|
||||||
let that = this
|
|
||||||
var uint8Buf = Array.from(uint8Array);
|
|
||||||
|
|
||||||
function split_array(datas, size) {
|
|
||||||
var result = {};
|
|
||||||
var j = 0
|
|
||||||
for (var i = 0; i < datas.length; i += size) {
|
|
||||||
result[j] = datas.slice(i, i + size)
|
|
||||||
j++
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
var sendloop = split_array(uint8Buf, 20);
|
|
||||||
|
|
||||||
function realWriteData(sendloop, i) {
|
|
||||||
var data = sendloop[i]
|
|
||||||
if (typeof(data) == "undefined") {
|
|
||||||
|
|
||||||
uni.showLoading({
|
|
||||||
title: '数据发送完毕,准备打印',
|
|
||||||
icon: 'loading',
|
|
||||||
})
|
|
||||||
setTimeout(function() {
|
|
||||||
uni.hideLoading()
|
|
||||||
}, 1000);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// console.log("第【" + i + "】次写数据"+data)
|
|
||||||
var buffer = new ArrayBuffer(data.length)
|
|
||||||
var dataView = new DataView(buffer)
|
|
||||||
for (var j = 0; j < data.length; j++) {
|
|
||||||
dataView.setUint8(j, data[j]);
|
|
||||||
}
|
|
||||||
uni.writeBLECharacteristicValue({
|
|
||||||
deviceId: that.deviceId,
|
|
||||||
serviceId: that.writeServiceId,
|
|
||||||
characteristicId: that.writeCharaterId,
|
|
||||||
value: buffer,
|
|
||||||
success(res) {
|
|
||||||
realWriteData(sendloop, i + 1);
|
|
||||||
},
|
|
||||||
fail() {
|
|
||||||
uni.showLoading({
|
|
||||||
title: '发送数据失败',
|
|
||||||
icon: 'loading',
|
|
||||||
})
|
|
||||||
setTimeout(function() {
|
|
||||||
uni.hideLoading()
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
var i = 0;
|
|
||||||
realWriteData(sendloop, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发送数据(递归分包发送)
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|||||||
@ -25,8 +25,8 @@
|
|||||||
<script>
|
<script>
|
||||||
import { showLoading, showToast, hideLoading, canvasGetImageData, getImageInfo, promiseTimeout } from "@/common/untool"
|
import { showLoading, showToast, hideLoading, canvasGetImageData, getImageInfo, promiseTimeout } from "@/common/untool"
|
||||||
import * as canvasUtil from "@/common/canvasUtil"
|
import * as canvasUtil from "@/common/canvasUtil"
|
||||||
import tanexPrinterUniSdk from './print/tanexPrinterUniSdk'
|
import tanexPrinterUniSdk from './nativePrint/tanexPrinterUniSdk'
|
||||||
import * as printModule from './print/print'
|
import printModule from './nativePrint/print'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props:{
|
props:{
|
||||||
@ -70,7 +70,7 @@ export default {
|
|||||||
prtInstance.setPagePrint()
|
prtInstance.setPagePrint()
|
||||||
let commond = prtInstance.getPrintCmd()
|
let commond = prtInstance.getPrintCmd()
|
||||||
console.log("打印命令组装完成,开始打印=====", commond)
|
console.log("打印命令组装完成,开始打印=====", commond)
|
||||||
printModule.print(deviceId, commond, true)
|
printModule.print(commond)
|
||||||
// printModule.printTestSimple(deviceId)
|
// printModule.printTestSimple(deviceId)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user