I got a first NewSoftSerial ser object, whose following code below tests availability of freshly arrived new data.
void loop()
{
ser.available(); //To activate the device when you've several NewSoftSerial objects
ser.flush();
delay(500);
if (ser.available()>0) Serial.println("Data arrived at most 500ms ago");
else Serial.println("No Data arrived at most 500ms ago");
delay(2000);
}
This works fine.
I've got a more complicated sketch with several NewSoftSerial objects. There, the above snippet put somewhere inside the code doesn't work anymore: it nevers sees data. I tried to do a loop with 100 tests for availability, but it doesn't help.
Does someone see from where the problem could come ?
It does support multiple instances, see the dedicated paragraph on the official page: NewSoftSerial | Arduiniana. You simply can use only once at a time, which is what I do, as said Graynomad.
Unfortunately, the code is quite enormous and split between several files.
The relevant part is:
...
lcd.print("Hello"); //First NSS object
delay(4000);
ser.available(); //To activate the device when you've several NewSoftSerial objects
ser.flush();
delay(500);
if (ser.available()>0) Serial.println("Data arrived at most 500ms ago");
else Serial.println("No Data arrived at most 500ms ago"); //always returns that!
delay(2000);
...
It seems that I respect demands from NewSoftSerial to use multiple instances, doesn't I ? The first available call is rightly to set the active object to ser.
I've got a more complicated sketch with several NewSoftSerial objects. There, the above snippet put somewhere inside the code doesn't work anymore: it nevers sees data. I tried to do a loop with 100 tests for availability, but it doesn't help.
Can you explain "doesn't work anymore" ?
What does it do?
What did you expect?
Is the code reachable?
Can you minimize your code to a smaller sketch that still shows this behavior?
What are the datarates of the (how many) serial ports?
Many questions to get a better sight in this serial fog