xDot with Universal Windows Apps (UWP)

Home Forums mDot/xDot xDot with Universal Windows Apps (UWP)

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #19504
    Alex Albu
    Participant

    I am trying to send AT commands to a XDot device (Eu1-A00) using a UWP application (.Net Core). My app is working only after I connect with Putty to the XDot and send a simple “AT” command.

    Here are the steps:

    1. I plug the xDot in a usb port on my PC
    2. I run my app that sends “AT” to the device but I get no answer back. At the second click I get the error “WinRT information: The operation identifier is not valid.” (this I think it is because the operation at the first click did not finish… but not entirely sure)
    3. I connect with putty to the device, send AT, get the OK, close Putty
    4. Open my application again, send the command, get the answer. After this all the other commands work as well.

    It seems like the Putty on my PC is “waking up” the XDot(?).
    Any idea why this behavior?

    On my Raspberry Pi (with Windows 10 IoT Core 15063) I get the same behavior as in step 2 above.
    I cannot connect with Putty to my Raspberry Pi so I cannot say if it will “wake up” the XDot there also..

    #19675
    Alex Albu
    Participant

    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 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.