posted 6 years ago
Sorry. I can't read that stuff. Your code indentation is all over the map, and it's hard to tell what's dependent on what.
It's often the case that communications interfaces get random junk when the device is first powered up. That's usually something that hardware design can help with.
When talking to a PC, though, there can be 2 issues where you have stale data left over from previous connections. First, at the OS level, depending on the TTY characteristics set and what options were applied when the port was opened. And in Java, your choice of what stream/reader you use can further complicate things, because if they are maintaining buffers, those buffers might need to be flushed explictly.
It can be messy and annoying. You might get better results if you use some sort of framing characters around your data and simply discard anything that's not within a frame.
"Disappointing" and "Utterly Horrible" are not equal.