/// <summary> /// - Creates an async task that reads from the SerialDevice InputStream continuously /// </summary> public async Task StartSerialPortListener() { string outputString; try { if (serialPort != null) { dataReaderObject = new DataReader(serialPort.InputStream); //connect to input stream // keep reading the serial input while (true) { outputString = await ss.ReadAsync(dataReaderObject, ReadCancellationTokenSource.Token); //read in a string //outputString = await ReadAsync(ReadCancellationTokenSource.Token); //read in string ReadOutputFunction(outputString); //pass the string to user given read output handler funciton } } } catch (TaskCanceledException tce) { //status.Text = "Reading task was cancelled, closing device and cleaning up"; closeDevice(); } catch (Exception ex) { //status.Text = ex.Message; } finally { // Cleanup once complete if (dataReaderObject != null) { dataReaderObject.DetachStream(); //disconnect from input stream dataReaderObject = null; } } }