UART Blocking Read

Is there any example of how use the UART Read but have it wait until something is coming?

This was handled before with a Timeout.Infinite, that way the read will block until a response is detected.

Hi… hmm I might be missing the meaning. But the .DataReceived event waits for data to be received.

_UARTController = GHIElectronics.TinyCLR.Devices.Uart.UartController.FromName(STM32F4.UartPort.Usart2);
_UARTController.SetActiveSettings(57600, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None);
// _UARTController.ReadBufferSize = 100;
_UARTController.DataReceived += _UARTController_DataReceived;
_UARTController.ErrorReceived += _UARTController_ErrorReceived;

private void _UARTController_DataReceived(UartController sender, DataReceivedEventArgs e)
{ // Handle data in stream read here

Im not 100% sure, but if the ReadBuffer fills Id say the event is fired. But do you mean like if only 1 character is received? Then I guess a timeout is used to then trigger the event?


What I meant was that there was a method in the serial port called Read()
this method usually read one byte, if the ReadTimeout property of the SerialPort was set to infinite (-1) that read method will block until a byte is received.
That method doesn’t exist in the UART class (neither the property)

1 Like

You could put it in an infinite loop.