Go Down

### Topic: Serial Available confuse.. (Read 1 time)previous topic - next topic

#### creativen

##### Jan 23, 2013, 08:52 am
what is the difference between
if (Serial.available())
and
if (Serial.available() > 0)
and
if (Serial.available() > 18)
and
if (Serial.available() <10)
and
if (Serial.available() == 3)

#### nickgammon

#1
##### Jan 23, 2013, 08:53 am
http://arduino.cc/en/Serial/Available
Please post technical questions on the forum, not by personal message. Thanks!

#### AWOL

#2
##### Jan 23, 2013, 08:54 am
Quote
if (Serial.available())
and
if (Serial.available() > 0)

No practical difference at all.
Serial.available does not return negative values, so any non-zero value means data is available to read.

I'll leave you to figure out the rest.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### creativen

#3
##### Jan 23, 2013, 08:56 am
I have read that link but it is not complete to explain every possibility between 0,18,< or > or == ...

I have read a book that code like this:

Code: [Select]
`if (Serial.available() > 18) {char led = Serial.read();if (led == 'S'){temp1 = Serial.read();temp2 = Serial.read();temp3 = Serial.read();temp4 = Serial.read();temp5 = Serial.read();temp6 = Serial.read();temp7 = Serial.read();temp8 = Serial.read();temp9 = Serial.read();}}`

what its purpose to put 18 there?

#### Grumpy_Mike

#4
##### Jan 23, 2013, 08:59 am
None what so ever. The code waits untilat least 19 bytes are in the buffer and then reads ten of them.
However in the contex of the whole program it might make sense.

#### AWOL

#5
##### Jan 23, 2013, 08:59 am
Quote
I have read that link but it is not complete to explain every possibility

Given that the serial buffer can contain up to 64 characters, all possibilities would take too much page space to enumerate, so they probably listed a few, and left the reader to figure out the rest.

Quote
what its purpose to put 18 there?