尝试使用以下方法从手机写入设备。我们要传输三个数据包。第一个数据包传输,然后我们的手机因错误而断开连接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++;
}