0

尝试使用以下方法从手机写入设备。我们要传输三个数据包。第一个数据包传输,然后我们的手机因错误而断开连接Response Characteristic Error: Error: Device disconnected

谁能阐明如何解决此响应特征错误?我们正在使用 react-native-ble-plx 库。

   writeToDevice = async (fullMessage, machineID) => {
      let subMessagesToSend = [];
      let subMessagesToSendCounter = 0;
      let i, j;
      let maxBytes = 19;
      for (i = 0, j = fullMessage.length; i < j; i += maxBytes) {
        subMessagesToSend.push(fullMessage.slice(i, i + maxBytes));
      }
      const sequenceNum = Buffer.alloc(1);
      sequenceNum.writeUInt8(subMessagesToSendCounter, 0);
      const subMessage = subMessagesToSend[0];
      const buffer = Buffer(subMessage, 'utf8');
      const fullBuffer = Buffer.concat([sequenceNum, buffer]);
      const message = fullBuffer.toString('base64');
      ble.writeCharacteristicWithResponseForDevice(
        machineID, 
        hUUID,
        rxUUID, 
        message)
        });
      subMessagesToSendCounter++; 
    }
4

1 回答 1

0

好吧, writeCharacteristic 调用不在 for 循环内,所以它不会发送超过 1 条消息......

不知道为什么它会断开连接,但它可能只是一个超时......

于 2019-02-24T09:48:58.900 回答