It looks like you're new here. If you want to get involved, click one of these buttons!
I'm pulling my hair out with the buggy serial library in Processing. I'll try and explain without pasting reams of code here.
In my setup, I'm sending a node discovery command to an XBee co-ordinator (AT command ND), running in API mode. In my serialEvent, I used to wait for the Xbee delimiter (7E) using bufferUntil(0x7E), then do a port.read() to get the LSB of the packet length, then another port.read() for the MSB. I would then do a loop of [LSB] iterations to read in the packet.
port.buffer(1) must be set, btw, otherwise all kinds of weird behaviour results. Using different values truncated the packets, which are of varying length, naturally, so you have to trigger on each seperate byte arrival.
The XBee replies (in my two device setup) with two packets, one containing the name of the co-ordinator, and one containing the name of the end device. However, it became apparent that bufferUntil(0x7E) would produce the delimiter first time, and the 00 of the MSB the next, skipping the 7E. Why?
After trying numerous workarounds, I gave up, and started writing a ring buffer. Initially, I could watch the two XBee packets hit it, totalling the correct length, so I went back to the Arduino code that I'm using to send data to Processing.
The data packets are hitting the ring buffer, which is now filling up nicely. However, NOW, if I stop the Processing sketch, and let the Arduino continue to send packets, THEN stop the Arduino sketch, THEN start the Processing sketch, I get 130 bytes, always 130 bytes, sitting in the buffer, even though it's inside a class, and I'm instantiating it in my setup. Obviously, the serialEvent is firing when the sketch is started, and all attempts to clear it down are failing miserably.
I've tried port.clear(), a loop of port.read() inside a while(port.available() > 0), and nothing is working. Obviously, I need everything to be initialised when I stop and then run the Processing sketch, as eventually, data will be coming in from numerous devices, and I have to have a zero'd ring buffer, from which to start extracting valid packets.
If the bufferUntil() method wasn't so flaky, I wouldn't need to be faffing around with a ring buffer anyway. I hope I've explained this clearly. Before anybody says 'post some code snippets', you have to realise that all my workaround stuff is relevant, and has been cut and replaced with numerous different attempts at curing this issue.
I could do with some help here, before I un-install Processing and look for a more robust piece of s/w for my project. I simply cannot be the only person experiencing these issues.