Quantcast
Channel: MultiTech Developer Resources » All Posts
Viewing all articles
Browse latest Browse all 7111

Reply To: xDot with Universal Windows Apps (UWP)

$
0
0

I was able to solve this problem in the end. It might be a problem with the .Net Core, or maybe I am missing something, but it seems that .Net Core does not realize when the device has sent all the bytes. It happened the same with other AT devices, not just the xDot.
The solution is this:

 public async Task<string> ReadStringInBatchAsync(int timeoutMilliseconds)
        {
            
            readCancellationTokenSource = new CancellationTokenSource();
            readCancellationTokenSource.CancelAfter(timeoutMilliseconds);

            Task<UInt32> loadAsyncTask;

            dataReader.InputStreamOptions = InputStreamOptions.Partial;
            UInt32 bytesRead = 0;
            string response = string.Empty;
            try
            {
                do
                {
                    loadAsyncTask = dataReader.LoadAsync(1).AsTask(readCancellationTokenSource.Token);
                    bytesRead = await loadAsyncTask;
                    response += dataReader.ReadString(bytesRead);
                } while (bytesRead > 0);
            }
            catch (Exception) { }
            readCancellationTokenSource.Dispose();

            return response;

        }

I have to read 1 byte at a time. The token is used to take me out of the loop when there are no more bytes to read. Otherwise the application hangs forever.

I hope this will help someone :)


Viewing all articles
Browse latest Browse all 7111

Trending Articles