【发布时间】:2016-10-24 20:59:58
【问题描述】:
我遇到了来自 Windows 10 蓝牙低功耗 (BLE) API 的 BluetoothLEAdvertisementDataSection.BluetoothLEAdvertisementDataSection class 问题。
如果我使用此代码检查IBuffer 成员Data 的长度:
var myDataSection = new BluetoothLEAdvertisementDataSection();
Debug.WriteLine($"Data Capacity: {myDataSection.Data.Capacity}"); //Looks like SO needs to update for C# 6.0
我得到了预期的输出:
数据容量:29
有关 BLE 数据包的更多信息,我建议访问 this great blog post。
现在假设我声明了一个名为 myPayload 的 byte[],它有 29 个字节长。以下代码抛出异常:
DataWriter writer = new DataWriter();
writer.WriteBytes(myPayload);
myDataSection.Data = writer.DetachBuffer(); //throws ArgumentException
ArgumentException 很有帮助的建议
“值不在预期范围内。”
事实上,myPayload 的任何大小 20+ 字节 都会导致相同的错误。但是,如果我将其设为 19 字节 长,则不会出错。
是的,当this answer 没有帮助时,我非常沮丧。
【问题讨论】:
标签: c# windows bluetooth-lowenergy