Your idea of a heartbeat message sounds right to me, but there are a
few simple things you might want to include also.
If this is serial, you can "invent" your own protocol hopefully. This
would not be hard, just set up 2 or 3 different messages you would
need.
I would suggest the following 2 messages in addition to normal use
messages, use whatever numbers or data you want to for the messages,
but lay these out before you start coding.
1. A Reset Notice message. Sent only after powerup of either device,
because you really don't know if someone reset either computer, or we
just got disconnected. This will let the system know someone was
reset, and it needs to reinitalize.
2. A Heartbeat message. Some people prefer a challenge response type,
and others just use
1 simple message. A challenge respose would be
something like MSG:Are you there Pump, and the Pump responds with an
answer that is different than the message you sent (so you don't
mistake your own message for the response). This allows both sides to
know if the other accidentally got disconnected. As a general rule,
make your timeout for hearing the heartbeat at least 2 times the
normal repitition rate (meaning you need to miss 2 heartbeats)
3. The rest of the message activity can be status messages (busy,
running, cancel current operation) which are really up to you