The trick here is to use hardware handshaking or the acknowledge mechanism. On all serial devices you need to know if the message you send as been received and understood and you do not want to send another message whilst the first one is being processed.
Setting up a hardware handshake is tricky and so the BV4626 has an ACK mechanism that is switched off by default. The command to switch it on is <esc>nE where n is the byte you want the BV4626 to send back when it’s done.
If you set n to say 6 then all you need to do is send out the command and read the serial input until 6 is received. When it is another command can be sent.
A point to note also when automating is that the automatic Baud rate detection takes about ½ second, so when you send out byte13 (printf(“\r”)) as the first bit of communication, wait ½ second or wait for byte 42 (0x2a) to be received which is always sent after the Baud rate is established.