Serial.read problem

hi everyone, my problem may be simple but i cannot figure it out. I am sending 0x01 to arduino using a C# application and arduino reads it as 255 when I use int(incomingByte). It is 255 in every different value. For example I send 0xF2. It is 255 again. I even tried manual conversion from byte to int by multipliying pow(2,bitnumber)*bitRead(incomingByte(bitnumber)) it still reads it as 255. I wrote the value to sd card so that I can remove sd card and look at the value. What might be the problem ?

Serial data is not faulty. Because I send 0xCC to arduino and if the coming data is 0xCC, then arduino sends 0xCC back. I recieve the echo.

What might be the problem ?

It could be hardware or software who knows so post your code and post a schematic.

Grumpy_Mike:
It could be hardware or software who knows so post your code and post a schematic.

I fixed it by using while(!Serial.available()); before Serial.read() function.

That was going to be my guess, that you were reading from an empty buffer.

When reading from an empty buffer, Serial.read() returns the int value -1 (0xFFFF). When you store that in a byte (say, incomingByte) it gets truncated to 0xFF (255). When you cast it back to int it's still 255.