Skip to content

Stream.find() functions don't find bytes as of 0x80 from HardwareSerial/SoftwareSerial #9452

Open
@baer61

Description

@baer61

HardwareSerial/SoftwareSerial::read() return a byte where the functions are defined to return an int. The implicit conversion from "unsigned char/uint8_t" to int returns 0xFFAA (= -86) for the received byte 0xAA.
The function Stream::findMulti() then tests the integer returned by Stream::timedRead() with "c < 0" instead of "c == -1" to distinguish between a received byte and -1 for still nothing available on the stream.
Therefore the function Stream.find() comes back with -1 after timeout, although read() received the byte 0xAA.
It took a lot of time to find out the reason why I didn't found the start byte 0xAA on the stream from my MP3 module response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CoreRelated to the code for the standard Arduino APIPrint and Stream classThe Arduino core library's Print and Stream classesType: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions