'create a loop that opens comm 1 to comm 255 in turn
re = 1 ' This sets up the return from the error trap
o = 1 ' Set this to 1. If it's not open then it sets this to 0
CLOSE 1 ' Make sure port is closed before we try to open it
OPEN "COM" + port$
+ ":9600,N,8,1,BIN,CS0,DS0" FOR RANDOM AS #1 ' try and open the port ps%(i) = o ' Set ps%(i) to 1 for openable or 0 if not
' Display which ones are openable
PRINT "The following ports are openable"
' Catch the error
fault:
' why re = 1
' Well, at a point later in the main program I open the comm port again.
' That time re will be 0 so it won't go to the RESUME NEXT,
' it will go to a second IF (errnum = 68) THEN error call
o = 0
PRINT " FATAL PROGRAMME ERROR!!"