MainPage.xaml.cs
/// <summary>
/// - Create a DataReader object
/// - Create an async task to read from the SerialDevice InputStream
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
Create a DataReader object
Create an async task to read from the SerialDevice InputStream
Create a DataReader object Create an async task to read from the SerialDevice InputStream
private async void Listen()
        {
            try
            {
                if (serialPort != null)
                {
                    dataReaderObject = new DataReader(serialPort.InputStream);
                    while (true)
                    {
                        await ReadAsync(ReadCancellationTokenSource.Token);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType().Name == "TaskCanceledException")
                {
                    CloseDevice();
                }
                else
                {
                }
            }
            finally
            {
                if (dataReaderObject != null)
                {
                    dataReaderObject.DetachStream();
                    dataReaderObject = null;
                }
            }
        }
private async void Listen ( ) { try { if ( serialPort != null ) { dataReaderObject = new DataReader ( serialPort . InputStream ) ; while ( true ) { await ReadAsync ( ReadCancellationTokenSource . Token ) ; } } } catch ( Exception ex ) { if ( ex . GetType ( ) . Name == " " ) { CloseDevice ( ) ; } else { } } finally { if ( dataReaderObject != null ) { dataReaderObject . DetachStream ( ) ; dataReaderObject = null ; } } }
Create a DataReader object
 Create an async task to read from the SerialDevice InputStream
Create a DataReader object Create an async task to read from the SerialDevice InputStream
// keep reading the serial input //status.Text = "Reading task was cancelled, closing device and cleaning up"; //status.Text = ex.Message; //loi frame // Cleanup once complete
sender
None
e
None