I can make two suggestions:
1. Your line 140 has no delay on CS,DS or CD. If the status of those lines is not correct when you open the com port, you will get a timeout error. Setting each to a delay of 1sec may do the trick.
2. As, presumably, you wrote the program, how about putting in a...