@@ -98,11 +98,11 @@ boolean SARA_R5::bufferedPoll(void)
9898 memset (saraResponseBacklog, 0 , RXBuffSize);
9999 }
100100
101- if (hwAvailable () || backlogLen > 0 ) // If either new data is available, or backlog had data.
101+ if (hwAvailable () > 0 || backlogLen > 0 ) // If either new data is available, or backlog had data.
102102 {
103103 while (micros () - timeIn < rxWindowUS && avail < RXBuffSize)
104104 {
105- if (hwAvailable ())
105+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
106106 {
107107 c = readChar ();
108108 saraRXBuffer[avail++] = c;
@@ -198,11 +198,11 @@ boolean SARA_R5::poll(void)
198198
199199 memset (saraRXBuffer, 0 , RXBuffSize);
200200
201- if (hwAvailable ())
201+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
202202 {
203203 while (c != ' \n ' )
204204 {
205- if (hwAvailable ())
205+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
206206 {
207207 c = readChar ();
208208 saraRXBuffer[avail++] = c;
@@ -3239,7 +3239,7 @@ SARA_R5_error_t SARA_R5::waitForResponse(const char *expectedResponse, const cha
32393239
32403240 while ((!found) && ((timeIn + timeout) > millis ()))
32413241 {
3242- if (hwAvailable ())
3242+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
32433243 {
32443244 char c = readChar ();
32453245 if (_printDebug == true ) _debugPort->print ((String)c);
@@ -3305,7 +3305,7 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse(
33053305
33063306 while ((!found) && ((timeIn + commandTimeout) > millis ()))
33073307 {
3308- if (hwAvailable ())
3308+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
33093309 {
33103310 char c = readChar ();
33113311 if (_printDebug == true ) _debugPort->print ((String)c);
@@ -3352,11 +3352,11 @@ int SARA_R5::sendCommand(const char *command, boolean at)
33523352 int backlogIndex = strlen (saraResponseBacklog);
33533353
33543354 unsigned long timeIn = micros ();
3355- if (hwAvailable ())
3355+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
33563356 {
33573357 while (micros ()-timeIn < rxWindowUS && backlogIndex < RXBuffSize) // May need to escape on newline?
33583358 {
3359- if (hwAvailable ())
3359+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
33603360 {
33613361 char c = readChar ();
33623362 saraResponseBacklog[backlogIndex++] = c;
@@ -3535,7 +3535,7 @@ int SARA_R5::readAvailable(char *inString)
35353535 if (_printDebug == true ) _debugPort->println (inString);
35363536 }
35373537#ifdef SARA_R5_SOFTWARE_SERIAL_ENABLED
3538- if (_softSerial != NULL )
3538+ else if (_softSerial != NULL )
35393539 {
35403540 while (_softSerial->available ())
35413541 {
0 commit comments