I think you have to wait for the hardware to complete command 1 before you send command 2.
If the hardware gives no feedback on its status then you can just put a sleep-line between this two lines to wait for some time before sending the second command.
But this depends on the hardware, maybe you have to read some hardware documentation when it is safe to send a new command.