port_close waits for the port to be idle before it closes,
and I think thats the problem...

Try changing the port_close step to this...
Code:
...
    }
    port_close(hPort);
    while(proc_status(port_close))   wait(1);	
    //
    //
    sys_exit("");
}

Let me know how it goes... any changes in behaviour.
Then if its fixed I'll explain what was happening...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial