How to create a safe UART communication protocol?
I think you should define longer commands including probably checksum or CRC and wait for an ACK / NACK or error condition.

You can take examples from easy protocols like TFTP (RFC 1350)