Code: Select all
int uart_read_bytes(uart_port_t uart_num, uint8_t *buf, uint32_t length, TickType_t ticks_to_wait)
or can return as soon length bytes are available (before that ticks_to_wait expire)?
Code: Select all
int uart_read_bytes(uart_port_t uart_num, uint8_t *buf, uint32_t length, TickType_t ticks_to_wait)
kolban wrote:In your original post you asked if we waited or returned immediately when the "length" bytes were available. I think you shouldn't discount a third option which I believe may also exist ... that it returns immediately if LESS than "length" bytes are available but at least 1 byte. For example, if the UART has 5 bytes waiting to be read and you pass in a buffer of 100 bytes into which the data will be stored, my belief is that it will return immediately having populated 5 bytes and telling you that it read those 5 bytes into the buffer. This is not the same as "waiting for 100 bytes to be read".
this^ is exactly what I need,my belief is that it will return immediately having populated 5 bytes and telling you that it read those 5 bytes into the buffer
Code: Select all
uint8_t cmd[4];
//obviously, here i populate *cmd
//then Send
uart_write_bytes(_uartPort, (const char*) cmd, 4); // Send Command (composed by 4 bytes), and i expect 4bytes to read (ACK)
// some other code here
// check for ACK
int rxBytes = uart_read_bytes(_uartPort, data, 4, 20 / portTICK_RATE_MS); // read 4 bytes OR timeout
if (rxBytes > 0) {
// DO SOMETHING
}
else{
// Err :-(
}
with this code uart_read_bytes() will return as soon 4 bytes are ready or will ALWAYS wait for 20ms?
Users browsing this forum: Baidu [Spider], Google [Bot], snutw_ and 90 guests