Low Power Online Advertising in the Windows 10 API

I am having a problem with the BluetoothLEAdvertisementDataSection.BluetoothLEAdvertisementDataSection class from the Windows 10 Bluetooth Low Energy (BLE) API.

If I check the length of an element IBuffer Datausing this code:

 var myDataSection = new BluetoothLEAdvertisementDataSection();
 Debug.WriteLine($"Data Capacity: {myDataSection.Data.Capacity}"); //Looks like SO needs to update for C# 6.0

I get the expected result:

Data capacity: 29

For more information on BLE packages, I recommend visiting this great blog post .

Now suppose I declared byte[], called a myPayloadlength of 29 bytes. The following code throws an exception:

 DataWriter writer = new DataWriter();
 writer.WriteBytes(myPayload);
 myDataSection.Data = writer.DetachBuffer(); //throws ArgumentException

ArgumentException very helpful suggest that

"The value is not in the expected range."

, myPayload 20+ . 19 , , .

, , .

+4
1

... . 29 . 30 . API.

 static readonly byte[] myPayload =  
{0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF, //8 bytes
 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF, //8 bytes
 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF, //8 bytes
 0x00,0x00,0x00,0x00,0x00}; //5 bytes Total:29 bytes            

... .

+2

Source: https://habr.com/ru/post/1658741/


All Articles