The Delphi code is grotesque. In one case that I just found, there is a read of the serial port with a 10 ms timeout that is used to "clear the buffer". Problem is that it takes 50 ms to do one cycle, and the first program goes on, does another command, then it gets back a timeout result from the first read.
It's sprinkled with crap like that.
And there's a difference between seconds and milliseconds.
I just had to add code to my stuff to check for a timeout of less than some minimum and treat it as a special case where you don't want anything to happen. It's ugly.