Detecting com ports ?

Windows specific questions.
Post Reply
softfoot
Posts: 34
Joined: Aug 31, 2020 3:45

Detecting com ports ?

Post by softfoot »

I have code that tests for the existance of any com ports :

For idx = 1 To 255 Step 1
sComNum="COM" + Trim(Str(idx),Any Chr(32)) ' Convert idx to string and trim off leading and trailing spaces (32)
sComInit=sComNum+proto
Open Com (sComInit) For Random As chan + 1
' state = err
If Err=0 Then
Print "Found port "; sComNum
Else
Goto nextport
End If
chan += 1
portname(chan) = sComNum
nextport:
Print "Trying next port "; idx
Next idx

This used to work until I upgraded to the latest version (I was quite a way behind) ... Now it is OK if the port exists but aborts the program if it does not exist and never reaches the test on Err.

COM1 exists but COM2 doesn't so it never scans further than 2 and there are several up around 10.

Has something changed or am I missing something fundamental ?

Puzzled,
Dave
softfoot
Posts: 34
Joined: Aug 31, 2020 3:45

Re: Detecting com ports ?

Post by softfoot »

OK Fixed it.

The later version of the compiler GUI I am using has -exx specified. Adding "On Error Goto nextport" solved it.

Dave
Post Reply