Skip to content

Q: while((ch=Monitor.read()) != -1) {} will hang #320

@KurtE

Description

@KurtE

Describe the bug
It appears like Monitor.read() does not return -1 when the q is empty;

This hangs:

  int ch;
  if ((ch = Monitor.available()) > 0) {
    Monitor.print("Serial available:");
    Monitor.println(ch);
    uint8_t new_rototation = 0;
    while ((ch = Monitor.read()) != -1) {
      //Monitor.write(ch);
      if ((ch >= '0') && (ch <= '9')) {
        new_rototation = ch - '0';
      }
    }

This does not:

  int ch;
  if ((ch = Monitor.available()) > 0) {
    Monitor.print("Serial available:");
    Monitor.println(ch);
    uint8_t new_rototation = 0;
    while (Monitor.available()) {
      ch = Monitor.read();
      //Monitor.write(ch);
      if ((ch >= '0') && (ch <= '9')) {
        new_rototation = ch - '0';
      }
    }

Target board + cli verbose compilation output
Arduino UNO Q

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions