2020年12月4日 作者 zeroheart

小程序连接打印

1.wx.openBluetoothAdapter要在这个之后,操作蓝牙的接口,才能有效果

2.向打印机写数据,需要serviceId: this._serviceId,官方demo写的是deviceId,不知道什么情况

wx.writeBLECharacteristicValue({
deviceId: this._deviceId,
serviceId: this._serviceId,
characteristicId: this._characteristicId,
value: buffer,
success: function (res) {
console.log('writeBLECharacteristicValue success', res)
},
fail:function(err){
console.log(err)
},
complete() {
self.closeBluetoothAdapter();
}
})

3.具体的设置,看打印机支持的指令集,然后设置对应的参数,微信官方建议每次最多写20个字节,所以要分包写。

具体的可以参考这个项目,在此感谢项目作者!!

https://gitee.com/tremble/GprinterSDK