Hi gbulmer, sorry busy week!
I've only posted an edited down version of the sketch as there was alot of other stuff that isnt relevant.
I basically just added an else clause to my if (someByte == 'V') to check whether it was in time or not. If its not a V that I'm recieving before my loop then I've either lost or gained a char. I send it back to processing to notify me. The odd thing is that if one packet in the series (as I'll explain below) is out of synch, then I should be receiving at least several responses on every scan sent through. Not just one bad char every second scan or so.
I'm basically sending a series of 5 bytes: V int char char char (without spaces of course). I am doing this 26 times per send, each of the 26 times is basically captured by maple and the last three chars are fed into an array but stored as an int value. int r= Serial2.read();
V - to verify that the order of the bytes is correct.
int - Introduced after this post was originally written. An integer identifying what number in the array the chars should be assigned to (i could use a counter but I want to be certain the array is assigned correctly. This is sent from processing as a char by using char(i) in a loop. I add 10 to avoid any problems with char(0) through to 10 (char(0) is NULL which sounds bodgy to me!!).
char char char - I read these as ints although they are sent out as chars. Chars are just a convenient way for me to send values between 0 and 255. I'm basically sending an RGB value in for each array item.
I send this format through 26 times per ip frame. Doesn't seem to matter if I send each of the 26 seperatly or in one ip packet frame as a String.
At the trailing end I send another char ('Q') which, when added to the if (someByte = 'V') clause will trigger another char ? to be sent back to processing to tell it to send the next line. I've ended up ditching this now and just flushing the Serial buffer entirely which seems to have improved data speeds. Q also triggers another function that shifts the array out into my shiftbrite leds (which you've helped me with before).
What I really don't understand with WiFly is how it talks through UART. Before I had to send my string through twice before recieving a '?' response back from maple, which means either:
- WiFly isn't sending the data through the UART until the buffer is full
- My data has corrupted and 'Q' never made it through.
I've reduced the flush size to around 150 and I only need to send the string once to get processing to automatically resend each 26 lines.
Anyway, RTS/CTS is a little confusing and their documentation doesn't help. Its confusing as I'm not sure what side of the wifly I am controlling:
- Is it controlling when to send / receive from serial uart to wifly
- Is it telling when wifly should send / receive to the host connection (my laptop running processing in this case).
Hope this makes sense. perhaps I should just post up my code...