From ba0625f368185c3089c6e22031599415d128a649 Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Sun, 23 Jun 2024 14:49:21 +0800 Subject: [PATCH] uub --- .../tpx-bluetooth-native/nativeBlueTooth.js | 15 ++++++++++----- .../tpx-bluetooth-native/tpx-bluetooth-native.vue | 5 +++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/components/tpx-bluetooth-native/nativeBlueTooth.js b/components/tpx-bluetooth-native/nativeBlueTooth.js index 0855187..f251390 100644 --- a/components/tpx-bluetooth-native/nativeBlueTooth.js +++ b/components/tpx-bluetooth-native/nativeBlueTooth.js @@ -301,10 +301,15 @@ var blueToothTool = { return false; } try { - invoke(btSocket, "connect"); - this.readData(); //读数据 - this.shortToast("连接成功"); - callback(true) + if(!btSocket.isConnected()) { + console.log("检测到设备未连接,尝试连接======") + invoke(btSocket, "connect"); + this.readData(); //读数据 + } + let bl = btSocket.isConnected() + console.log("btSocket.isConnected =======", bl) + bl && this.shortToast("连接成功") + callback(bl) } catch(e) { console.error("connDevice error:========!", e); this.shortToast("连接失败"); @@ -400,7 +405,7 @@ var blueToothTool = { try { btOutStream.write([0b00]); } catch(e) { - console.log("===connExceptionCallback===", e) + console.log("===蓝牙连接异常 connExceptionCallback===", e) this.state.readThreadState = false; this.options.connExceptionCallback && this.options.connExceptionCallback(e); } diff --git a/components/tpx-bluetooth-native/tpx-bluetooth-native.vue b/components/tpx-bluetooth-native/tpx-bluetooth-native.vue index 76643c9..1305c24 100644 --- a/components/tpx-bluetooth-native/tpx-bluetooth-native.vue +++ b/components/tpx-bluetooth-native/tpx-bluetooth-native.vue @@ -140,7 +140,7 @@ export default { }, discoveryDeviceCallback: _this.onDiscoverDevice.bind(_this), discoveryFinishedCallback: function() { - _this.msg = "搜索完成"; + // 搜索完成 }, readDataCallback: function(dataByteArr) { // 读取蓝牙返回的数据 @@ -150,7 +150,8 @@ export default { _this.receiveDataArr.push.apply(_this.receiveDataArr, dataByteArr); */ }, connExceptionCallback: function(e) { - _this.msg = "设备连接失败"; + _this.showToast("蓝牙设备连接中断,请检查") + // 设备连接失败 } }); })