Tell the guy who programmed the device that it is evil to make comm protocol exceedingly difficult to parse.
Communication with a device should be client driven e.g. the device
replies only when asked to by the client. If the client wants a
heartbeat, it asks a heartbeat every second. period. </rant>
After each command sent, read the received characters and parse
according to what response formats are expected. Remove heartbeats from
the reply and retry if needed. If you can give few typical strings
received from the device, I could be more specific in my answer.