Cannot write large byte array to a BLE device using UWP APIs - e.g. Write value as Async










0















I am using Windows 10 build 14393.2156. Bluetooth adapter LMP version is 6.X (Bluetooth version 4.0). I cannot write byte array data with length 350. However, I can write byte array data with length around 60 and get the expected data from the BLE device. When i write byte array of large length e.g. 350, I get windows exception: "Exception: The specified server cannot perform the requested operation. (Exception from HRESULT: 0x8007003A)". Following is the code:



private async Task CoreWrite(byte data)

var writeBuffer = CryptographicBuffer.CreateFromByteArray(data);
var result = await _txCharacteristic.WriteValueAsync(writeBuffer);
if (result != GattCommunicationStatus.Success)

throw new IOException($"Failed to write to bluetooth device. Status: nameof(result)");




Please note that the device is already paired. Is there any payload limit which can possibly affect limiting of payload length in Bluetooth 4.0 versus 4.2 specification. Or you suggest a higher Windows 10 builds with more recent Bluetooth LMP 8.X should help fix the issue. Appreciate any advice or help.



Many thanks.










share|improve this question
























  • see how handling a large byte array can be handled here: stackoverflow.com/questions/583970/…

    – JohnB
    Nov 15 '18 at 5:50












  • Does the peripheral support writes of Long values?

    – Emil
    Nov 15 '18 at 8:17











  • Thanks Emil. Yes the peripheral does support writing of large values. We can write the same value from Android system using Bluetooth 5.0 specification.

    – smondal
    Nov 16 '18 at 1:23











  • Your os version is old, and the new version of windows has support a lot feature about bluetooth 5.0, please try this in lastest version.

    – CoCaIceDew
    Nov 22 '18 at 2:44















0















I am using Windows 10 build 14393.2156. Bluetooth adapter LMP version is 6.X (Bluetooth version 4.0). I cannot write byte array data with length 350. However, I can write byte array data with length around 60 and get the expected data from the BLE device. When i write byte array of large length e.g. 350, I get windows exception: "Exception: The specified server cannot perform the requested operation. (Exception from HRESULT: 0x8007003A)". Following is the code:



private async Task CoreWrite(byte data)

var writeBuffer = CryptographicBuffer.CreateFromByteArray(data);
var result = await _txCharacteristic.WriteValueAsync(writeBuffer);
if (result != GattCommunicationStatus.Success)

throw new IOException($"Failed to write to bluetooth device. Status: nameof(result)");




Please note that the device is already paired. Is there any payload limit which can possibly affect limiting of payload length in Bluetooth 4.0 versus 4.2 specification. Or you suggest a higher Windows 10 builds with more recent Bluetooth LMP 8.X should help fix the issue. Appreciate any advice or help.



Many thanks.










share|improve this question
























  • see how handling a large byte array can be handled here: stackoverflow.com/questions/583970/…

    – JohnB
    Nov 15 '18 at 5:50












  • Does the peripheral support writes of Long values?

    – Emil
    Nov 15 '18 at 8:17











  • Thanks Emil. Yes the peripheral does support writing of large values. We can write the same value from Android system using Bluetooth 5.0 specification.

    – smondal
    Nov 16 '18 at 1:23











  • Your os version is old, and the new version of windows has support a lot feature about bluetooth 5.0, please try this in lastest version.

    – CoCaIceDew
    Nov 22 '18 at 2:44













0












0








0








I am using Windows 10 build 14393.2156. Bluetooth adapter LMP version is 6.X (Bluetooth version 4.0). I cannot write byte array data with length 350. However, I can write byte array data with length around 60 and get the expected data from the BLE device. When i write byte array of large length e.g. 350, I get windows exception: "Exception: The specified server cannot perform the requested operation. (Exception from HRESULT: 0x8007003A)". Following is the code:



private async Task CoreWrite(byte data)

var writeBuffer = CryptographicBuffer.CreateFromByteArray(data);
var result = await _txCharacteristic.WriteValueAsync(writeBuffer);
if (result != GattCommunicationStatus.Success)

throw new IOException($"Failed to write to bluetooth device. Status: nameof(result)");




Please note that the device is already paired. Is there any payload limit which can possibly affect limiting of payload length in Bluetooth 4.0 versus 4.2 specification. Or you suggest a higher Windows 10 builds with more recent Bluetooth LMP 8.X should help fix the issue. Appreciate any advice or help.



Many thanks.










share|improve this question
















I am using Windows 10 build 14393.2156. Bluetooth adapter LMP version is 6.X (Bluetooth version 4.0). I cannot write byte array data with length 350. However, I can write byte array data with length around 60 and get the expected data from the BLE device. When i write byte array of large length e.g. 350, I get windows exception: "Exception: The specified server cannot perform the requested operation. (Exception from HRESULT: 0x8007003A)". Following is the code:



private async Task CoreWrite(byte data)

var writeBuffer = CryptographicBuffer.CreateFromByteArray(data);
var result = await _txCharacteristic.WriteValueAsync(writeBuffer);
if (result != GattCommunicationStatus.Success)

throw new IOException($"Failed to write to bluetooth device. Status: nameof(result)");




Please note that the device is already paired. Is there any payload limit which can possibly affect limiting of payload length in Bluetooth 4.0 versus 4.2 specification. Or you suggest a higher Windows 10 builds with more recent Bluetooth LMP 8.X should help fix the issue. Appreciate any advice or help.



Many thanks.







c# arrays uwp bluetooth-lowenergy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 6:07









JohnB

1,94511320




1,94511320










asked Nov 15 '18 at 5:42









smondalsmondal

13




13












  • see how handling a large byte array can be handled here: stackoverflow.com/questions/583970/…

    – JohnB
    Nov 15 '18 at 5:50












  • Does the peripheral support writes of Long values?

    – Emil
    Nov 15 '18 at 8:17











  • Thanks Emil. Yes the peripheral does support writing of large values. We can write the same value from Android system using Bluetooth 5.0 specification.

    – smondal
    Nov 16 '18 at 1:23











  • Your os version is old, and the new version of windows has support a lot feature about bluetooth 5.0, please try this in lastest version.

    – CoCaIceDew
    Nov 22 '18 at 2:44

















  • see how handling a large byte array can be handled here: stackoverflow.com/questions/583970/…

    – JohnB
    Nov 15 '18 at 5:50












  • Does the peripheral support writes of Long values?

    – Emil
    Nov 15 '18 at 8:17











  • Thanks Emil. Yes the peripheral does support writing of large values. We can write the same value from Android system using Bluetooth 5.0 specification.

    – smondal
    Nov 16 '18 at 1:23











  • Your os version is old, and the new version of windows has support a lot feature about bluetooth 5.0, please try this in lastest version.

    – CoCaIceDew
    Nov 22 '18 at 2:44
















see how handling a large byte array can be handled here: stackoverflow.com/questions/583970/…

– JohnB
Nov 15 '18 at 5:50






see how handling a large byte array can be handled here: stackoverflow.com/questions/583970/…

– JohnB
Nov 15 '18 at 5:50














Does the peripheral support writes of Long values?

– Emil
Nov 15 '18 at 8:17





Does the peripheral support writes of Long values?

– Emil
Nov 15 '18 at 8:17













Thanks Emil. Yes the peripheral does support writing of large values. We can write the same value from Android system using Bluetooth 5.0 specification.

– smondal
Nov 16 '18 at 1:23





Thanks Emil. Yes the peripheral does support writing of large values. We can write the same value from Android system using Bluetooth 5.0 specification.

– smondal
Nov 16 '18 at 1:23













Your os version is old, and the new version of windows has support a lot feature about bluetooth 5.0, please try this in lastest version.

– CoCaIceDew
Nov 22 '18 at 2:44





Your os version is old, and the new version of windows has support a lot feature about bluetooth 5.0, please try this in lastest version.

– CoCaIceDew
Nov 22 '18 at 2:44












1 Answer
1






active

oldest

votes


















0














Surprisingly, we found that Attribute Data Length of the characteristic was limited at 244 bytes. Hence, I was not able to write any data more than 244 bytes. However, performing multiple writes with 244 bytes at a time does resolve this issue. I could see the expected response from the BLE device.



Example:



int offset = 0;
int AttributeDataLen = 244;
while (offset < data.Length)

int length = data.Length - offset;
if (length > AttributeDataLen)

length = AttributeDataLen;


byte subset = new byte[length];

Array.Copy(data, offset, subset, 0, length);
offset += length;

var writeBuffer = CryptographicBuffer.CreateFromByteArray(subset);
var result = await _txCharacteristic.WriteValueAsync(writeBuffer);
if (result != GattCommunicationStatus.Success)

throw new IOException(
$"Failed to write to bluetooth device. Status: nameof(result)");







share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313117%2fcannot-write-large-byte-array-to-a-ble-device-using-uwp-apis-e-g-write-value%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Surprisingly, we found that Attribute Data Length of the characteristic was limited at 244 bytes. Hence, I was not able to write any data more than 244 bytes. However, performing multiple writes with 244 bytes at a time does resolve this issue. I could see the expected response from the BLE device.



    Example:



    int offset = 0;
    int AttributeDataLen = 244;
    while (offset < data.Length)

    int length = data.Length - offset;
    if (length > AttributeDataLen)

    length = AttributeDataLen;


    byte subset = new byte[length];

    Array.Copy(data, offset, subset, 0, length);
    offset += length;

    var writeBuffer = CryptographicBuffer.CreateFromByteArray(subset);
    var result = await _txCharacteristic.WriteValueAsync(writeBuffer);
    if (result != GattCommunicationStatus.Success)

    throw new IOException(
    $"Failed to write to bluetooth device. Status: nameof(result)");







    share|improve this answer





























      0














      Surprisingly, we found that Attribute Data Length of the characteristic was limited at 244 bytes. Hence, I was not able to write any data more than 244 bytes. However, performing multiple writes with 244 bytes at a time does resolve this issue. I could see the expected response from the BLE device.



      Example:



      int offset = 0;
      int AttributeDataLen = 244;
      while (offset < data.Length)

      int length = data.Length - offset;
      if (length > AttributeDataLen)

      length = AttributeDataLen;


      byte subset = new byte[length];

      Array.Copy(data, offset, subset, 0, length);
      offset += length;

      var writeBuffer = CryptographicBuffer.CreateFromByteArray(subset);
      var result = await _txCharacteristic.WriteValueAsync(writeBuffer);
      if (result != GattCommunicationStatus.Success)

      throw new IOException(
      $"Failed to write to bluetooth device. Status: nameof(result)");







      share|improve this answer



























        0












        0








        0







        Surprisingly, we found that Attribute Data Length of the characteristic was limited at 244 bytes. Hence, I was not able to write any data more than 244 bytes. However, performing multiple writes with 244 bytes at a time does resolve this issue. I could see the expected response from the BLE device.



        Example:



        int offset = 0;
        int AttributeDataLen = 244;
        while (offset < data.Length)

        int length = data.Length - offset;
        if (length > AttributeDataLen)

        length = AttributeDataLen;


        byte subset = new byte[length];

        Array.Copy(data, offset, subset, 0, length);
        offset += length;

        var writeBuffer = CryptographicBuffer.CreateFromByteArray(subset);
        var result = await _txCharacteristic.WriteValueAsync(writeBuffer);
        if (result != GattCommunicationStatus.Success)

        throw new IOException(
        $"Failed to write to bluetooth device. Status: nameof(result)");







        share|improve this answer















        Surprisingly, we found that Attribute Data Length of the characteristic was limited at 244 bytes. Hence, I was not able to write any data more than 244 bytes. However, performing multiple writes with 244 bytes at a time does resolve this issue. I could see the expected response from the BLE device.



        Example:



        int offset = 0;
        int AttributeDataLen = 244;
        while (offset < data.Length)

        int length = data.Length - offset;
        if (length > AttributeDataLen)

        length = AttributeDataLen;


        byte subset = new byte[length];

        Array.Copy(data, offset, subset, 0, length);
        offset += length;

        var writeBuffer = CryptographicBuffer.CreateFromByteArray(subset);
        var result = await _txCharacteristic.WriteValueAsync(writeBuffer);
        if (result != GattCommunicationStatus.Success)

        throw new IOException(
        $"Failed to write to bluetooth device. Status: nameof(result)");








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 5 '18 at 9:25









        CoCaIceDew

        636




        636










        answered Dec 2 '18 at 23:03









        smondalsmondal

        13




        13





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313117%2fcannot-write-large-byte-array-to-a-ble-device-using-uwp-apis-e-g-write-value%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo