收藏
回答

ios系统中,接受蓝牙数据绘制折线图会卡死,安卓就不会?

const startNotice = (notify, serviceId) => {

                uni.notifyBLECharacteristicValueChange({

                        characteristicId: notify,

                        deviceId: props.id,

                        serviceId: serviceId,

                        state: true,

                        success(res) {

                                console.log('返回', res);

                                // 监听低功耗蓝牙设备的特征值变化

                                uni.onBLECharacteristicValueChange(result => {

                                        if (result.value) {

                                                console.log('返回数据', result.value)

                                                let view = new Uint16Array(result.value)

                                                if (result.value.byteLength == 200) {

                                                        for (let i = 0; i <view.length; i++) {

                                                                state.alllistTwoYuan.push(view[i])

                                                                state.id = state.id + 1

                                                                state.xdataList.push(state.id)

                                                                state.alllist.push(view[i])

                                                        }

                                                        console.log('返回数据', state.alllistTwoYuan)

                                                        if (state.alllistTwoYuan.length == 2000) {

                                                                state.alllistTwoYuan.splice(0, 100)

                                                                state.xdataList.splice(0, 100)

                                                        }

                                                        // chart.value.init(echarts, chart => {

                                                                state.option.series[0].data = state.alllistTwoYuan

                                                                chart.value.setOption(state.option)

                                                        // });

                                                        emit('goData', {

                                                                voltage: state.alllist,

                                                                alllistTwoYuan: state.alllistTwoYuan,

                                                                time: state.xdataList.length - 1,

                                                        })

                                                }

                                        }

                                })

                        }

                });

        };

以上代码就是通过蓝牙传输过来的数据进行绘制实时折线图,

回答关注问题邀请回答
收藏

1 个回答

  • 0
    0
    08-27

    uni社区问问

    08-27
    有用
    回复
登录 后发表内容