-
Notifications
You must be signed in to change notification settings - Fork 7.6k
HardwareSerial: No way to wait for data in queue. #5472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Some additionals: I mean sleep on some sync primitive like mutex or semaphore.
But it is not I want. |
Why don't you do size_t readBlocking(HardwareSerial* serial) {
while (!serial->available()) {
delay();
}
return serial->available();
}
|
@bertmelis , actually this is not solution. This is dirty hack. If delay() will very short, It will just usual busy loop. just curious, esp32-hal-uart.c which is used as back-end for HardwareSerial is using xQueueReceive() for reading from uart buffer, which CAN sleep while no data, but this queue is used in non-blocking mode. I think it couldn't be a problem to do sleeping on no-data. |
Yes it will be a problem because it will be a MAJOR breaking change. It might not be a problem for you but it will for numerous other users, including me. If the suggested solution doesn't work for you, you might want to switch to ESP-IDF or a completely different platform. Besides, what do you think the processor is doing when there is nothing specific to be done? |
Would the Arduino serialEvent be a solution? It's not blocking, but it is called only when there is some data to be read on Serial Port. It could trigger some action or task. serialEvent is implemented in the PR #5549 |
@dibalavs Any updates or can I consider this as solved? |
A potential solution is being implemented. As soon as any data arrives UART RX, |
Hardware:
Board: ESP32
Core Installation version: framework-arduinoespressif32 3.10006.210326 (1.0.6)
IDE name: Platform.io
Flash Frequency: 40Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10
Description:
I have worker task, which should sleep while no incoming data on uart and wake on data and process it.
I found that HardwareSerial::available() and HardwareSerial::read()
are non-blocking. So i have busyloop in task which is not good for CPU resource optimization.
Sketch:
The text was updated successfully, but these errors were encountered: