if (serial.available() > 0)

friends i have very simple question, as i am new in arduino so need little help…
in some video i saw a coding like this (picture), my question is what this line means in my serial communication??
*video was in some french :stuck_out_tongue:

Not downloading your picture. Pictures of code are pretty worthless when you can just copy and paste the line of code into a post.

If you mean a line like this:

if(serial.available() > 0){

available returns the number of characters that have been received and are ready to be read. Probably inside this if statement is some code to read those characters from the serial stream. This line is making sure that you don't run that bit of code unless there is actually some serial data there that is ready to read.

Have a look here: Follow the links on the right hand side for more info on each command. Also see @Robin2's Serial Input Basics thread. It's very informative.

you got me :) thanks for the link :) if (serial.available() > 0) { in = (byte) serial.read & (0x20)....... } this (ox20) is confusing me... i want to recieve data on labview for HMI via serial port actually, problem is that i am working with multiple sensors.. if you have any better option then refer the link please :)

0x20 is just a number. The 0x means that it is written in hexadecimal. 0x20 written in decimal numbers would be 32. You could substitute 32 for 0x20 and it wouldn't change anything.

The & is a bitwise and. See this page for more information on that. What they are doing is only taking the 6th bit of the number coming from the serial read and zeroing all the other bits.

Delta_G: 0x20 is just a number. The 0x means that it is written in hexadecimal. 0x20 written in decimal numbers would be 32. You could substitute 32 for 0x20 and it wouldn't change anything.

The & is a bitwise and. See this page for more information on that. What they are doing is only taking the 6th bit of the number coming from the serial read and zeroing all the other bits.

ohh it is usefull then... let me know you, there was another sign after "&" i am not able to type it :( it looks like curve this "-" what is its significance??

Tilde. If you have an american keyboard it is to the left of the 1 key on top. That symbol means bitwise NOT. It inverts the bits in a number. So now they wouldn't be clearing all the bits but the 6th, they'd just be clearing the 6th bit.

By the way, this is where I am getting all these pages I'm sending you to. It would do you well to spend some time there looking at all the different things. You could find this for yourself instead of having to ask.

https://www.arduino.cc/en/Reference/HomePage

You can also reach it by clicking on Learning up at the top of this page and then Reference. There is also a link to it in the IDE.

thanks for this link, it is useful :) last question, why is he doing this in serial?? it must have some link while recieving the data on labview, but question is, what is the logic behind?? clearing some of the bits etc??

Delta_G: Tilde. If you have an american keyboard it is to the left of the 1 key on top. That symbol means bitwise NOT. It inverts the bits in a number. So now they wouldn't be clearing all the bits but the 6th, they'd just be clearing the 6th bit.

By the way, this is where I am getting all these pages I'm sending you to. It would do you well to spend some time there looking at all the different things. You could find this for yourself instead of having to ask.

https://www.arduino.cc/en/Reference/HomePage

You can also reach it by clicking on Learning up at the top of this page and then Reference. There is also a link to it in the IDE.

thanks for this link, it is useful :) last question, why is he doing this in serial?? it must have some link while recieving the data on labview, but question is, what is the logic behind?? clearing some of the bits etc??

I don't know why he is clearing that bit. I have no idea where this code came from or what it is meant to do. I can only explain the lines you show me.

umerchamp:
last question, why is he doing this in serial?? it must have some link while recieving the data on labview, but question is, what is the logic behind?? clearing some of the bits etc??

in = (byte)Serial.read() & ~ (0x20);

Logic AND with bitwise NOT (0x20) will change all the input character to upper case.

*** EXAMPLE 7:  Turn any ASCII letter into upper case.

    This is the reverse of the above process that makes a lower-case
    letter by turning "on" the 20h bit.  If we "turn off" the 20h bit
    in a letter, the letter becomes upper-case.  (If the letter was
    already upper-case, the 20h bit is already off; turning it off makes
    no difference.)

    To turn off that 20h bit, we want to create a bit mask that allows
    all the other bits to remain on but that sets that one 20h bit to
    zero, i.e. we want a mask that is the opposite (bitwise NOT) of 20h.
    The mask must be "0" where 20h is "1".  We appply the bitwise NOT
    to 20h to do this:
    
    Take 00100000 = 20h -> apply NOT (bit flip) -> 11011111 = DFh.

    Let's try the mask on a sample ASCII lower-case letter 'a'.
    (ASCII 'a' has value 61h = 01100001.)  Any letter would work.

	       01100001 = 61h = ASCII lower-case letter 'a'
	   AND 11011111 = DFh  <-- this is the bitwise NOT (bit-flip) of 20h
	       --------
	EQUALS 01000001 = 41h = ASCII upper-case letter 'A'

BillHo: in = (byte)Serial.read() & ~ (0x20);

Logic AND with bitwise NOT (0x20) will change all the input character to upper case.

Learn something new every day. I always just used toupper. It's safer because it only does it to letters that actually have an upper case. If you do this to a number or other character what happens?

this logic has no use for me i guess.... but i learnt on this forum today is very helpful as i am new :) Thanks Guys thanks alot :)