@@ -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;
@@ -3226,7 +3226,7 @@ SARA_R5_error_t SARA_R5::waitForResponse(const char *expectedResponse, const cha
32263226
32273227 while ((!found) && ((timeIn + timeout) > millis ()))
32283228 {
3229- if (hwAvailable ())
3229+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
32303230 {
32313231 char c = readChar ();
32323232 if (_printDebug == true ) _debugPort->print ((String)c);
@@ -3292,7 +3292,7 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse(
32923292
32933293 while ((!found) && ((timeIn + commandTimeout) > millis ()))
32943294 {
3295- if (hwAvailable ())
3295+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
32963296 {
32973297 char c = readChar ();
32983298 if (_printDebug == true ) _debugPort->print ((String)c);
@@ -3346,11 +3346,11 @@ int SARA_R5::sendCommand(const char *command, boolean at)
33463346 int backlogIndex = strlen (saraResponseBacklog);
33473347
33483348 unsigned long timeIn = micros ();
3349- if (hwAvailable ())
3349+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
33503350 {
33513351 while (micros ()-timeIn < rxWindowUS && backlogIndex < RXBuffSize) // May need to escape on newline?
33523352 {
3353- if (hwAvailable ())
3353+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
33543354 {
33553355 char c = readChar ();
33563356 saraResponseBacklog[backlogIndex++] = c;
@@ -3529,7 +3529,7 @@ int SARA_R5::readAvailable(char *inString)
35293529 if (_printDebug == true ) _debugPort->println (inString);
35303530 }
35313531#ifdef SARA_R5_SOFTWARE_SERIAL_ENABLED
3532- if (_softSerial != NULL )
3532+ else if (_softSerial != NULL )
35333533 {
35343534 while (_softSerial->available ())
35353535 {
0 commit comments