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:

you got me :slight_smile: thanks for the link :slight_smile:
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 :slight_smile:

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 :frowning: it looks like curve this "-"
what is its significance??

thanks for this link, it is useful :slight_smile:
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.

Arduino - Home

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 :slight_smile:
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??

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'

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