if(Serial.available()>2)
{
x = Serial.available();
char vitread[x-2];
//Serial.println(x);
for (i = 0; i <= x-2; i++)
{
vitread[i] = Serial.read();
}
So, if there are two bytes, and the first one is 33, read 31 of the remaining bytes. How's that going to work. Here's a hint. Not well at all.
Serial.flush();
Why is this here? If you are using 0023 or earlier, then you want to throw away random amounts of unread data. There won't be any because you've just tried to read more than were there, most likely. Even if there was unread data, why would you want to throw it away?
If you are using 1.0 or later, flush() simply blocks until all unsent data is sent. I can't imagine why that would be important here.
Unless you've got a really good explanation for using this function, quit doing it. If you do, I'd really like to hear it.