最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序藍(lán)牙連接小票打印機(jī)實(shí)例代碼詳解

 更新時(shí)間:2019年06月03日 09:28:26   作者:浪子回頭——  
這篇文章主要介紹了微信小程序藍(lán)牙連接小票打印機(jī)實(shí)例代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1.連接藍(lán)牙

(第一次發(fā)表博客)

第一步打開藍(lán)牙并搜索附近打印機(jī)設(shè)備//

startSearch: function() {
var that = this
wx.openBluetoothAdapter({
success: function(res) {
wx.getBluetoothAdapterState({
success: function(res) {
if (res.available) {
if (res.discovering) {
wx.stopBluetoothDevicesDiscovery({
success: function(res) {
console.log(res)
}
})
}
that.checkPemission()
} else {
wx.showModal({
title: '提示',
content: '本機(jī)藍(lán)牙不可用',
})
}
},
})
},
fail: function() {
wx.showModal({
title: '提示',
content: '藍(lán)牙初始化失敗,請(qǐng)打開藍(lán)牙',
})
}
})
}

2.將搜索到的設(shè)備列表綁定點(diǎn)擊事件并連接

bindViewTap: function(e) {
var that = this
wx.stopBluetoothDevicesDiscovery({
success: function(res) {
console.log(res)
},
})
that.setData({
serviceId: 0,
writeCharacter: false,
readCharacter: false,
notifyCharacter: false
})
var shebei = e.currentTarget.dataset.title
wx.setStorageSync('shebei', shebei)
wx.showLoading({
title: '正在連接',
})
wx.createBLEConnection({
deviceId: e.currentTarget.dataset.title,
success: function(res) {
console.log(res)
app.BLEInformation.deviceId = e.currentTarget.dataset.title
console.log(e.currentTarget.dataset.title)
that.getSeviceId()
},
fail: function(e) {
wx.showModal({
title: '提示',
content: '連接失敗',
})
console.log(e)
wx.hideLoading()
},
complete: function(e) {
console.log(e)
}
})
}

3.連接成功后保存連接狀態(tài)

getSeviceId: function() {
var that = this
var platform = app.BLEInformation.platform
console.log(app.BLEInformation.deviceId)
wx.getBLEDeviceServices({
deviceId: app.BLEInformation.deviceId,
success: function(res) {
that.setData({
services: res.services
})
that.getCharacteristics()
},
fail: function(e) {
console.log(e)
},
complete: function(e) {
console.log(e)
}
})
}
getCharacteristics: function() {
var that = this
var list = that.data.services
var num = that.data.serviceId
var write = that.data.writeCharacter
var read = that.data.readCharacter
var notify = that.data.notifyCharacter
wx.getBLEDeviceCharacteristics({
deviceId: app.BLEInformation.deviceId,
serviceId: list[num].uuid,
success: function(res) {
console.log(res)
for (var i = 0; i < res.characteristics.length; ++i) {
var properties = res.characteristics[i].properties
var item = res.characteristics[i].uuid
if (!notify) {
if (properties.notify) {
app.BLEInformation.notifyCharaterId = item
app.BLEInformation.notifyServiceId = list[num].uuid
notify = true
}
}
if (!write) {
if (properties.write) {
app.BLEInformation.writeCharaterId = item
app.BLEInformation.writeServiceId = list[num].uuid
write = true
}
}
if (!read) {
if (properties.read) {
app.BLEInformation.readCharaterId = item
app.BLEInformation.readServiceId = list[num].uuid
read = true
}
}
}
if (!write || !notify || !read) {
num++
that.setData({
writeCharacter: write,
readCharacter: read,
notifyCharacter: notify,
serviceId: num
})
if (num == list.length) {
wx.showModal({
title: '提示',
content: '找不到該讀寫的特征值',
})
} else {
that.getCharacteristics()
}
} else {
that.openControl()
}
},
fail: function(e) {
console.log(e)
},
complete: function(e) {
console.log("write:" + app.BLEInformation.writeCharaterId)
console.log("read:" + app.BLEInformation.readCharaterId)
console.log("notify:" + app.BLEInformation.notifyCharaterId)
}
})
}
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function(options) {
app.BLEInformation.platform = app.getPlatform()
}

 總結(jié)

以上所述是小編給大家介紹的微信小程序藍(lán)牙連接小票打印機(jī)實(shí)例代碼詳解,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

  • JavaScript實(shí)現(xiàn)輸入框與清空按鈕聯(lián)動(dòng)效果

    JavaScript實(shí)現(xiàn)輸入框與清空按鈕聯(lián)動(dòng)效果

    本文給大家分享基于js實(shí)現(xiàn)輸入框與清空框按鈕聯(lián)動(dòng)效果,非常實(shí)用,代碼簡(jiǎn)單易懂,感興趣的朋友一起看看吧
    2016-09-09
  • JS清除文本框內(nèi)容離開在恢復(fù)及鼠標(biāo)離開文本框時(shí)觸發(fā)js的方法

    JS清除文本框內(nèi)容離開在恢復(fù)及鼠標(biāo)離開文本框時(shí)觸發(fā)js的方法

    多網(wǎng)站的需要填寫的文本框在默認(rèn)狀態(tài)下都會(huì)給出一個(gè)默認(rèn)的提示語言,當(dāng)鼠標(biāo)點(diǎn)擊此文本框的時(shí)候能夠?qū)⒗锩娴哪J(rèn)文本清除,當(dāng)刪除輸入的文本且焦點(diǎn)離開文本框的時(shí)候再將默認(rèn)的文本寫入文本框
    2016-01-01
  • JavaScript 應(yīng)用技巧集合[推薦]

    JavaScript 應(yīng)用技巧集合[推薦]

    前段時(shí)間我曾經(jīng)對(duì)JavaScript中的應(yīng)用技巧進(jìn)行了收集和總結(jié)這里我將會(huì)對(duì)這些應(yīng)用技巧進(jìn)行集中描述,如果你覺得遺漏了一些好用的應(yīng)用技巧,也請(qǐng)?jiān)诹粞灾刑岢?,我?huì)及時(shí)更新到這篇文章中的。
    2009-08-08
  • 利用css+原生js制作簡(jiǎn)單的鐘表

    利用css+原生js制作簡(jiǎn)單的鐘表

    這篇文章主要為大家詳細(xì)介紹了如何利用css+原生js制作簡(jiǎn)單的鐘表,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-07-07
  • JavaScript中判斷整字類型最簡(jiǎn)潔的實(shí)現(xiàn)方法

    JavaScript中判斷整字類型最簡(jiǎn)潔的實(shí)現(xiàn)方法

    這篇文章主要介紹了JavaScript中判斷整字類型最簡(jiǎn)潔的實(shí)現(xiàn)方法,本文給出多個(gè)判斷整數(shù)的方法,最后總結(jié)出一個(gè)最短、最簡(jiǎn)潔的實(shí)現(xiàn)方法,需要的朋友可以參考下
    2014-11-11
  • window.event.keyCode兼容IE和Firefox實(shí)現(xiàn)js代碼

    window.event.keyCode兼容IE和Firefox實(shí)現(xiàn)js代碼

    window.event.keyCode兼容IE和Firefox具體實(shí)現(xiàn)代碼如下,感興趣的朋友可以參考下哈
    2013-05-05
  • javascript:;與javascript:void(0)使用介紹

    javascript:;與javascript:void(0)使用介紹

    有時(shí)候我們?cè)诰帉慾s過程中,需要觸發(fā)事件而不需要返回值,那么就可能需要這樣的寫法
    2013-06-06
  • js編碼之encodeURIComponent使用介紹(asp,php)

    js編碼之encodeURIComponent使用介紹(asp,php)

    因此對(duì)于JS腳本又重新研究了一下。在對(duì)新的URL編碼的時(shí)候發(fā)現(xiàn),網(wǎng)頁編碼的格式對(duì)于JS的影響很大,在這里書寫一點(diǎn)
    2012-03-03
  • js如何取消事件冒泡

    js如何取消事件冒泡

    事件冒泡是什么意思這里就不為大家一一贅述了,下面為大家講解的是js中如何取消事件冒泡,感興趣的朋友可以參考下
    2013-09-09
  • js實(shí)現(xiàn)仿Discuz文本框彈出層效果

    js實(shí)現(xiàn)仿Discuz文本框彈出層效果

    這篇文章主要介紹了js實(shí)現(xiàn)仿Discuz文本框彈出層效果的方法,可實(shí)現(xiàn)點(diǎn)擊文本框彈出窗口選擇數(shù)據(jù)的效果,涉及鼠標(biāo)事件及頁面自定義彈出窗口的相關(guān)操作技巧,需要的朋友可以參考下
    2015-08-08

最新評(píng)論

乌什县| 论坛| 义乌市| 综艺| 台安县| 柘城县| 阳高县| 淅川县| 灵川县| 郸城县| 德保县| 通江县| 黄平县| 康马县| 彩票| 安庆市| 本溪市| 闻喜县| 岫岩| 佛学| 大兴区| 河东区| 从江县| 长乐市| 阿拉善右旗| 友谊县| 天台县| 罗源县| 来宾市| 黄龙县| 黄山市| 麦盖提县| 谢通门县| 宜春市| 资中县| 延寿县| 肥城市| 田林县| 商洛市| 保康县| 佛冈县|