Re: enumerate existing comm ports

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Your code is flawed.
On Error Resume Next
For x = 1 to 10
mscomm1.comPort = x
mscomm1.portOpen = true
if err <> 0 then
When the port is already opened then
mscomm1.comPort = x
generates error (Port in Use)
but
mscomm1.portOpen = true
will not generate the error, thus the statement:
if err<>0
is not correct.
Jack

"DanS" <t.h.i.s.n.t.h.a.t@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:Xns986BBFC4A9201thisnthatadelphianet@xxxxxxxxxxxxxxxxx
"Jack" <notreplyto@it> wrote in news:upFHDN7#GHA.4388
@TK2MSFTNGP02.phx.gbl:

How to enumerate existing comm ports?
Jack




An easy way is to just try to open com1 thru 10 (or whatever) and trap
for errors.

On Error Resume Next
For x = 1 to 10
mscomm1.comPort = x
mscomm1.portOpen = true
if err <> 0 then
'Check for error type here
err.Clear
else
mscomm1.portOpen = false
end if
next

There will be 2 main errors, either InvalidPort or PortInUse. If there's
no error the port number is valid and available, PortInUse error means
the post is there but in use (obviously), and if you get back
InvalidPort, there is no port.

I'm sure there are other ways to do this, but in a pinch, I've always
used this.




.



Relevant Pages