Your code assumes that the write() calls are blocking. This is not the case in Qt. The write() calls queue data to be sent, but it will not actually be sent until the program returns to the event loop. Some time later the data will have been sent and a result (possibly) received. The other end will probably receive your two commands immediately after each other: how it handles that depends on their software. This is why I suggested some sort of state machine. The complexity involved depends on how flexible the script of commands must be and how fault tolerant you need to be.
Bookmarks