Go Down

Topic: serial read xbee (Read 630 times) previous topic - next topic


i have xbee i receive a packet with 18 bytes .

how can i read only 1 bytes at a time after i find my start of the packet which is 7E  how can i read only the  12th byte of my packet fram which is contains 18 bytes . ??

if (Serial.read()==0x7E)



The code below should give you a start.  I have not tested it but it is the way I have done it a number of times.

Hope it helps,


Code: [Select]
byte get_myByte();
int n_bytes;
byte discard, myByte
// I am assuming you have the packet coming into the receiving XBee and you have started Serial()

while(Serial.available() > 0)
  n_bytes = Serial.available();
  if(n_bytes >= 18)
    if(Serial.read() == 0x7e)
         for(int i = 1; i < 11; i++)
              discard = Serial.read();
    // If you have gotten here you have an error so
    // return a value that signifies an error


i tried it but it didnt work

so in this program it will discard the values from 1 to my 11th byte

then read the rest for 12th to 16th for every 7E


One thread per problem is the limit!

Go Up