处理秤断开自动重连
This commit is contained in:
@@ -76,12 +76,31 @@ App({
|
|||||||
|
|
||||||
initPpScale() {
|
initPpScale() {
|
||||||
this.globalData.ppScale.plugin = requirePlugin('ppScale-plugin');
|
this.globalData.ppScale.plugin = requirePlugin('ppScale-plugin');
|
||||||
const plugin = this.globalData.ppScale.plugin;
|
|
||||||
|
|
||||||
plugin.bus.subscribe("connectState", (res) => {
|
this.globalData.ppScale.plugin.bus.subscribe("connectState", (res) => {
|
||||||
console.log("app.js ===> connectState", res);
|
console.log("app.js ===> connectState", res);
|
||||||
|
|
||||||
|
// 连接失败则重新连接
|
||||||
|
if (res == this.globalData.ppScale.plugin.BLUE_STATE.CONNECTFAILED) {
|
||||||
|
this.reconnectDevice()
|
||||||
|
}
|
||||||
wx.hideLoading();
|
wx.hideLoading();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.globalData.ppScale.plugin.bus.subscribe("deviceWillDisconnect", (res) => {
|
||||||
|
console.log("app.js ===> deviceWillDisconnect", res);
|
||||||
|
|
||||||
|
this.reconnectDevice();
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
reconnectDevice() {
|
||||||
|
this.globalData.ppScale.plugin.Blue.disconnect((disres) => {
|
||||||
|
if (disres.errCode == 0) {
|
||||||
|
this.globalData.ppScale.plugin.Blue.startBluetoothDevicesDiscovery();
|
||||||
|
} else {
|
||||||
|
this.reconnectDevice();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user