STM32GENERIC icon indicating copy to clipboard operation
STM32GENERIC copied to clipboard

Serial.available() not working properly

Open VitorBoss opened this issue 6 years ago • 3 comments

Looking on SerialUART.cpp the function is returning a bool condition instead os number of available bytes, a lot of libs use that like Nexion. This is the current code:

int HardwareSerial::available() {
    return rxEnd != rxStart;
}

This is the fix:

int HardwareSerial::available() {
    //return rxEnd != rxStart;
    int size = (rxEnd % BUFFER_SIZE) - (rxStart % BUFFER_SIZE);
    if (size < 0) size += BUFFER_SIZE;
    return size;
}

Tested and working properly now.

VitorBoss avatar Mar 29 '18 14:03 VitorBoss

Updated code, now working with Nextion

VitorBoss avatar May 14 '18 21:05 VitorBoss

Hi, The current version does not have this fix yet. Manually adding the this code to the core works fine! I had problems with a project and this little thing. Can you please add the fix to the master branch?

Tjeerdie avatar Jul 25 '18 18:07 Tjeerdie

int HardwareSerial::available() { if (rxEnd >= rxStart) return (rxEnd - rxStart); return BUFFER_SIZE + rxEnd - rxStart; }

That work better

VitorBoss avatar Jul 26 '18 00:07 VitorBoss