HarmonyOS 鸿蒙Next关于Ble蓝牙设备连接问题
HarmonyOS 鸿蒙Next关于Ble蓝牙设备连接问题
当我成功扫描到ble蓝牙设备后,通过其mac地址与其连接,然后通过发现服务API进行监听事件,但是返回2900099错误码,文档解释为操作失败;但我每次请求连接都是返回此错误码.通过观察ble设备,连接上之后立马发生断开。请问为何会出现操作失败,具体代码如下所示。 private getServices(code: BusinessError, gattServices: Array<ble.GattService>) { //2900099-Operation failed. LoggerJoy.info('BLEDeviceFind—>: bluetooth code is ’ + code.code) if (code.code == 0) { let services: Array<ble.GattService> = gattServices LoggerJoy.info('BLEDeviceFind—>: bluetooth code is ’ + code.code) LoggerJoy.info('BLEDeviceFind—> :bluetooth services size is ’ + services.length) for (let i = 0; i < services.length; i++) { LoggerJoy.info('BLEDeviceFind—> :bluetooth serviceUuid is ’ + services[i].serviceUuid) } } } /* * 连接蓝牙设备–通过ble Mac地址进行连接 * */ connectBleDevice(deviceId: string){ try { let device: ble.GattClientDevice = ble.createGattClientDevice(deviceId) device.connect() LoggerJoy.info(
BLEDeviceFind---> start connection ble device
) device.getServices(this.getServices) } catch (err) { LoggerJoy.error('errCode: ’ + (err as BusinessError).code + ', errMessage: ’ + (err as BusinessError).message) } }
1 回复