hfs-bluetooth-adapter
v1.9.6
Published
海富思科技对外提供的蓝牙设备LLSyncSDK
Readme
Hfs-LLSync-Bluetooth-Adapter
由海富思提供给客户的蓝牙设备LLSyncSDK
SDK使用说明
初始化蓝牙模块
初始化蓝牙模块 会判断用户手机蓝牙状态
import BluetoothAdapter from "hfs-bluetooth-adapter"
const blueAdapter = new BluetoothAdapter() //实例化蓝牙适配器
blueAdapter.initBluetooth().then(res=>{}).catch(err=>{}) //初始化蓝牙设配器搜索蓝牙设备
在初始化后进行
//传入一个配置项 onSearch为搜索到设备时的回调函数
blueAdapter.startSearch({
onSearch(res){
//返回附近设备列表
console.log(res);
},
onError(err){
console.log(err);
}
})停止搜索蓝牙设备
blueAdapter.stopSearch()连接蓝牙设备
传入一个设备对象 startSearch的onSearch回调函数返回的设备对象 返回一个连接成功后蓝牙设备对应的设备适配器
const deviceAdapter = await blueAdapter.connectDevice(device)绑定设备
通过设备适配器进行绑定设备
const deviceAdapter = await bluetoothAdapter.connectDevice(device)
deviceAdapter.bindDevice().then(res=>{
console.log(res.deviceName) //返回设备名称
})搜索单个蓝牙设备
传入设备名称
const device = await bluetoothAdapter.searchDevice({
deviceName
})断开蓝牙设备连接
deviceAdapter.disconnectDevice()添加指纹密码
deviceAdapter.addFP({
name
start_effective_time//有效起始时间 传空为永久有效 需要进行特殊处理 具体看demo
end_effective_time//有效结束时间 传空为永久有效
},(res)=>{
//res返回添加指纹状态 result:0添加失败 1-4指纹采集次数 5添加成功 B移开手指 C指纹模块错误 D指纹已满 E锁端退出添加指纹
Toast.loading({
message: res.msg,
forbidClick: true,
duration: 0,
})
if(res.result == 5){
Toast("添加指纹用户成功")
}
})添加密码
deviceAdapter.addPwd({
name
password
start_effective_time
end_effective_time
}).then(res=>{
//result 1成功 0失败
if(res.result == 1){
Toast("添加密码用户成功")
}
})添加卡片密码
deviceAdapter.addRfCard({
name
start_effective_time
end_effective_time
},(res)=>{
//1 用户已刷卡 0为未刷卡
if(res.result == 1){
Toast("添加卡片用户成功")
}
})删除密码
deviceAdapter.deletePwd({
pwdIdGroup:[1,2,3] //密码Id的数组 可以进行批量删除
}).then(res=>{
//result 1成功 0失败
console.log(res.result);
})获取密码列表
deviceAdapter.getAllPwd().then(res=>{
//密码列表
console.log(res.result);
})获取开锁日志
deviceAdapter.getHistory({
start_effective_time //开始日期
end_effective_time //结束日期 时间戳是秒级
}).then(res=>{
//日志数组
console.log(res.result);
})解绑设备
解绑后 该设备会重新被startSearch函数搜索到
deviceAdapter.unbindDevice().then(res=>{
//result 1成功 0失败
console.log(res.result);
})