This commit is contained in:
aihe 2024-06-23 14:49:21 +08:00
parent 39a47d3a76
commit ba0625f368
2 changed files with 13 additions and 7 deletions

View File

@ -301,10 +301,15 @@ var blueToothTool = {
return false; return false;
} }
try { try {
invoke(btSocket, "connect"); if(!btSocket.isConnected()) {
this.readData(); //读数据 console.log("检测到设备未连接,尝试连接======")
this.shortToast("连接成功"); invoke(btSocket, "connect");
callback(true) this.readData(); //读数据
}
let bl = btSocket.isConnected()
console.log("btSocket.isConnected =======", bl)
bl && this.shortToast("连接成功")
callback(bl)
} catch(e) { } catch(e) {
console.error("connDevice error:========!", e); console.error("connDevice error:========!", e);
this.shortToast("连接失败"); this.shortToast("连接失败");
@ -400,7 +405,7 @@ var blueToothTool = {
try { try {
btOutStream.write([0b00]); btOutStream.write([0b00]);
} catch(e) { } catch(e) {
console.log("===connExceptionCallback===", e) console.log("===蓝牙连接异常 connExceptionCallback===", e)
this.state.readThreadState = false; this.state.readThreadState = false;
this.options.connExceptionCallback && this.options.connExceptionCallback(e); this.options.connExceptionCallback && this.options.connExceptionCallback(e);
} }

View File

@ -140,7 +140,7 @@ export default {
}, },
discoveryDeviceCallback: _this.onDiscoverDevice.bind(_this), discoveryDeviceCallback: _this.onDiscoverDevice.bind(_this),
discoveryFinishedCallback: function() { discoveryFinishedCallback: function() {
_this.msg = "搜索完成"; // 搜索完成
}, },
readDataCallback: function(dataByteArr) { readDataCallback: function(dataByteArr) {
// 读取蓝牙返回的数据 // 读取蓝牙返回的数据
@ -150,7 +150,8 @@ export default {
_this.receiveDataArr.push.apply(_this.receiveDataArr, dataByteArr); */ _this.receiveDataArr.push.apply(_this.receiveDataArr, dataByteArr); */
}, },
connExceptionCallback: function(e) { connExceptionCallback: function(e) {
_this.msg = "设备连接失败"; _this.showToast("蓝牙设备连接中断,请检查")
// 设备连接失败
} }
}); });
}) })