About NewSoftSerial -> nss.available()

Hello,

i'm a bit confuse with the NewSoftSerial library...
i use rfid module from netronix (hitag) and had to send and receive frame of 7 to 10 bytes...
i can send my frame but i'm not sure to understand how to read byte from the rfid serial...
cause it seems i can't use an while (rfid.available()>1) instruction...

some help will be great
regards

What kind of behaviour do you want?

This will hold code until there is one byte in the Serial buffer:

while (rfid.available()<1){ ; }

This will let the loop continue to execute, but this if will trigger when there are 7 bytes in the serial buffer:

if (rfidl.available()>=7){ /*do code*/ }

Mikal write here:NewSoftSerial | Arduiniana

An important point here is that object.available() always returns 0 unless object is already active. This means that you can't write code like this:

void loop()
{
if (device1.available() > 0)
{
int c = device1.read();
...
}
if (device2.available() > 0)
{
int c = device2.read();
...
}
}

there i'm asking if we can use again the while loop :-/

regards

eric

Eric,

The while loop AlphaBeta proposes will work fine. The only time you might have trouble is if your code flits rapidly back and forth between two devices. NewSoftSerial can only use one device at a given time.

Mikal

Thanx for your advice AlphaBeta and Mikal.

i'll try again and verify my plug.
I receive a bad answer format :-[

regards

eric