Serial.readBytesUntil() with SoftwareSerial???

With hardware serial port Serial, there's a command Serial.readBytesUntil(), so I can get data and react when I get the termination command, or when I have xx bytes.

I don't see the equivalent with the SoftwareSerial library.

I want to read data from Softserial, and write to an LCD. I works if there's "//n", but if the data I'm getting has none, it wait forever.

I want in chucks to send to an LCD, so if it has a terminator it goes to next line on LCD, if it has none, every 20 chars, go to next line on LCD.

Here's the code that fails with unterminated data. Suggestions for a better way?

  /*  while data has been recieved at serial port: */
  while (SoftwareSerial.available() > 0)
  {
    char received = SoftwareSerial.read();
    inData += received;
    if (received == '\n')
    {
      display.setCursor(0, cursor_y);
      display.print(inData);
      display.display();
      inData = ""; // Clear received buffer
      cursor_y = cursor_y + 10;
    }
  }

You might add an OR to the below line to also check to see if the length of inData > 19.

    if (received == '\n')

Well I now see the downside of doing it this way is that if it got unterminated data that was less than 20 characters, it would never write anything to the LCD

Have a look at the examples in serial input basics. They do not block the Arduino while waiting for data to arrive - and they will work with SoftwareSerial with minor modifications.

...R

You might be able to count the characters inside the receiving loop and send to the display when a certain number is displayed or when no more characters are in the serial buffer.

You might be able to count the characters inside the receiving loop and send to the display when a certain number is displayed or when no more characters are in the serial buffer.

Or, look at how readBytesUntil() is implemented, and implement your function the same way. That's the great thing about open source. No one is trying to keep anything from you.

When I'm handling serial commands, if i've got data that I've been reading from the uart while looking for a command, I start a timer when I get the first character of a possible command. If I don't get a newline in 10 seconds, I discard the incomplete command and write a newline or error message.