小程序连接和写入打印机的过程都ok,可是打印机就是没有相应!求解

代码贴出:

// 初始化蓝牙适配器  

initializeBluetooth: function () {

var that = this;

if (!wx.openBluetoothAdapter) {

console.log('蓝牙适配器打开失败,请检查微信版本或手机是否支持小程序蓝牙模块!')

} else {

wx.openBluetoothAdapter({

success: function (res) {

that.setData({

msg: "初始化蓝牙适配器成功!"

})

wx.getBluetoothAdapterState({//获取本机蓝牙适配器状态

success: function (res) {

console.log('本机蓝牙适配器状态:')

console.log(res)

}

})

}

})

}

},


//搜索获取已发现设备  

searchBluetooth: function () {

var that = this;

wx.startBluetoothDevicesDiscovery({//开始搜寻附近的蓝牙外围设备

success: function (res) {

console.log('开始搜索周边蓝牙设备')

console.log(res)

wx.getBluetoothDevices({//sucess返回uuid 对应的的已连接设备列表,Array类型

success: function (res) {

//是否有已连接设备

wx.getConnectedBluetoothDevices({////根据 uuid 获取处于已连接状态的设备

success: function (res) {

console.log('已连接的蓝牙设备:')

console.log(JSON.stringify(res.devices));

that.setData({

connectedDeviceId: res.deviceId

})

}

})

that.setData({

devices: res.devices,

})

}

})

}

})

},


//连接设备  

connectTO: function (e) {

var that = this;

wx.stopBluetoothDevicesDiscovery({ //先停止搜索周边设备

success: function (res) {

console.log('连接设备前,先停止搜索周边设备:')

console.log(res)

}

})

wx.showLoading({

title: '连接蓝牙设备中...',

})

wx.createBLEConnection({//若小程序在之前已有搜索过某个蓝牙设备,并成功建立链接,可直接传入之前搜索获取的deviceId直接尝试连接该设备,无需进行搜索操作。

deviceId: e.currentTarget.id,

success: function (res) {

console.log('连接成功:')

console.log(res)

wx.hideLoading()

that.setData({

connectedDeviceId: e.currentTarget.id,    //currentTarget: 事件绑定的元素

msg: "已连接" + e.currentTarget.id,

})

that.getServices();

that.startBletNotify();

that.receiveMessages();

},

fail: function () {

console.log("调用失败");

},

complete: function () {

console.log('已连接设备ID:' + that.data.connectedDeviceId);

console.log("调用结束");

}

})

},


// 获取连接设备的service服务  

getServices: function () {

var that = this;

wx.getBLEDeviceServices({//获取在小程序蓝牙模块生效期间所有已发现的蓝牙设备,包括已经和本机处于连接状态的设备

展开全部
收起
10回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
  • Ethan

    20人对此回答表示赞同

    展开
    20
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • Mia

    19人对此回答表示赞同

    你的打印指令都没有,你怎么打印?

    展开
    19
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • 卡夫卡夫卡夫卡

    18人对此回答表示赞同

    你的打印机是什么牌子的?我的只有两个characteristics,一个是write,一个是notify

    展开
    18
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • Sadie

    17人对此回答表示赞同

    需要低功耗蓝牙的打印机看看这个:https://developers.weixin.qq.com/blogdetail?action=get_post_info&docid=7e85fa4514a56b7928646f96dd4bcabe&highline=%E8%93%9D%E7%89%99%E6%89%93%E5%8D%B0%E6%9C%BA

    展开
    17
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • 恨钢不成铁

    9人对此回答表示赞同

    大兄弟,有没有demo啊,需要学习

    展开
    9
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • 泯灭人性

    6人对此回答表示赞同

    你的安卓能连接上吗

    展开
    6
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • baby爱我多一次

    6人对此回答表示赞同

    现在解决了吗,怎么解决的

    展开
    6
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • Alice

    4人对此回答表示赞同

    还没有用安卓试呢,主要是暂时没有机子

    展开
    4
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • Valentina

    2人对此回答表示赞同

    飞鹅FP-58AWG有2个serviceId,每个只有一个characteristics,第一个全支持,第二个只支持read

    展开
    2
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • 刘思杰

    1人对此回答表示赞同

    我看了文档好像只需要支持writhe,可是就是没有反应!!

    展开
    1
    0回复
    发布于 6年前

    评论(0)

    收起评论

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部