Poll
Question: how can i read 1 byte at a time in xbee
xbee - 0 (0%)
serial read - 1 (100%)
1 byte - 0 (0%)
Total Voters: 1

Pages: [1]   Go Down
Author Topic: serial read xbee  (Read 454 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)



thanks
Logged

0
Offline Offline
Full Member
***
Karma: 5
Posts: 241
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,

wade

Code:
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();
         }
         return(Serial.read());
    }
    // If you have gotten here you have an error so
    // return a value that signifies an error
  }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One thread per problem is the limit!
Logged

Pages: [1]   Go Up
Jump to: