locked
Windows store bluetooth rfcomm app reader issue

    Question

  • Iam communicating with embedded device through bluetooth RFcomm profile.am able to establish connection using StramSocket.ConnectAsync().My readResponse block is like this,

                                                            

    public int iReadResponse()
            {

                DataReader reader = new DataReader(socket.InputStream);
                reader.InputStreamOptions = InputStreamOptions.Partial;

                try 
                {
                    var task = Task.Run(async () =>
                    {

                        var bytesAvailable = await reader.LoadAsync(1000);
                        var byteArray = new byte[bytesAvailable];
                        reader.ReadBytes(byteArray);


                        reader.DetachStream();
                    });
                    task.Wait();
                    return 0;
                }
                catch 
                {
                    return -1;
                }
            }so when there is any data even 1 byte to read block will execute properly.but when there is no data to read it wil get stuck in LoadAsync line as i have declared inputstreamoptions as Partial.is there any way to handle this case, i have tried other inputstreamoptions none and Readahead with out any luck. 

    i tried putting Unconsumedbufferlength!=0 condition before loadasync but that unconsumed bufferlength is always zero only.and if try to read byte by byte control is simply skipping through the line no data it is reading.Any help greatly appreciated.Thanks in Advance.


    • Edited by D Mahesh Thursday, January 8, 2015 5:32 PM
    Thursday, January 8, 2015 5:31 PM

All replies

  • What happens if you don't run it async? I mean, remove this:

       var task = Task.Run(async () =>
                    {


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, January 8, 2015 8:23 PM
    Moderator