标签:BluetoothLEAdvertisementDataSection(ArgumentException)
作者:互联网
我正在尝试播发Eddystone信标,但是我的代码在带有ArgumentException的advertDataData.Data上失败:
Value does not fall within the expected range.
有什么想法吗?
// ...
using (var memoryStream = new MemoryStream())
{
byte messageLengthByte = Convert.ToByte(message.Length);
memoryStream.WriteByte(messageLengthByte);
memoryStream.Write(message, 0, message.Length);
fullMessage = memoryStream.ToArray();
}
while (fullMessage.Length < 32)
{
byte[] newArray = new byte[fullMessage.Length + 1];
fullMessage.CopyTo(newArray, 0);
newArray[fullMessage.Length] = 0x00;
fullMessage = newArray;
}
var writer = new DataWriter();
writer.WriteBytes(fullMessage);
var advertisementData = new BluetoothLEAdvertisementDataSection();
advertisementData.Data = writer.DetachBuffer(); // Error!
publisher.Advertisement.DataSections.Add(advertisementData);
publisher.Start();
解决方法:
最有可能您尝试容纳的字节数超出BLE数据包允许的字节数.最大大小为32个字节,但这包括:
> 3个字节用于“标志”数据部分,我认为这是必需的,并且可能由Windows 10 BLE API自动设置
>对于每个附加节,节的长度为1个字节,节的类型为1个字节
如果仅广播单个部分,则该部分的实际有效负载将剩下27个字节.
标签:win-universal-app,eddystone,c 来源: https://codeday.me/bug/20191119/2033156.html