I have two arduino's transmitting serial strings my pc wirelessly.
Each arduino sends codes like this:
Serial.print('T'); //signifies a start of a new string
Serial.print(1); //Id for the aruino, the other arduino would be number 2
Serial.print(byte1);
Serial.print(byte2);
Serial.print(byte3);
If I send this from one Arduino while the other Arduino is also sending a block of 5 bytes how do I make sure that they are received in order by the pc reading from both of them?
Does the xbee already take care of this in hardware?
I want to make sure that the data does not get intereaved.
I guess one obvious solution is to form a string and send that instead of individual byte?
No, putting the data into a string wont make it all go at once, the same things that could sneak in between the print calls could sneak in while the string is being written to the Serial port...
This is the manual for the XBee modules, Look at Page 10, from that page it sounds like you can set "RO" to 1 second to not worry about the data interleaving since the whole message will fit inside a packet.
This system needs to be as fast as possible so I can't wait for the DI buffer timeout.
Possible solutions:
Use one of the frame based API modes (probably mode 2 so that I can send raw byte data values)
2.I can change my network topology to p2p. I can have arduino#2 communicate only to arduino#1 and then arduino#1 communicates to the PC. In this way arduino#1 is regulating the data flow and can keep bytes in order.
Solution #2 is easy to implement but I think may be a poor solution from a programming and scalabiltiy point of view (i.e. what if I want more than two arduinos in the future?)
However I do not understand the API modes right away and it will take some further reading and experimenting to make sure that I "get it".