For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > February 2005 > How to find COM Port Availability using API









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to find COM Port Availability using API
Wyne

2005-02-25, 3:56 pm

Hello,

I'm building a VB App. This app needs to list all available Serial Ports to
the user. Currently I do it by using a MSCOMM component to enumarate COM 1 ~
COM 16. (Setting its ComPort = 1, 2, ... 16 and check whether Error issued).
When a port is a Virtual port (on network), this procedure takes long time.

I wonder whether there is an API I can use to check (1) a specified COM Port
exists. (2) If it does exist, tell me whether it is occupied by other
application.

Thanks in advance

Wyne
Johan van Hespen

2005-02-26, 3:55 am

I guess this will help:

http://vbnet.mvps.org/code/system/comtestmscomm.htm


"Wyne" <Wyne@discussions.microsoft.com> wrote in message
news:96B2F5C1-E54F-4DA4-9E9D-047BAF83C53B@microsoft.com...
> Hello,
>
> I'm building a VB App. This app needs to list all available Serial Ports
> to
> the user. Currently I do it by using a MSCOMM component to enumarate COM
> 1 ~
> COM 16. (Setting its ComPort = 1, 2, ... 16 and check whether Error
> issued).
> When a port is a Virtual port (on network), this procedure takes long
> time.
>
> I wonder whether there is an API I can use to check (1) a specified COM
> Port
> exists. (2) If it does exist, tell me whether it is occupied by other
> application.
>
> Thanks in advance
>
> Wyne



J French

2005-02-26, 8:55 am

On Fri, 25 Feb 2005 10:49:08 -0800, "=?Utf-8?B?V3luZQ==?="
<Wyne@discussions.microsoft.com> wrote:

>Hello,
>
>I'm building a VB App. This app needs to list all available Serial Ports to
>the user. Currently I do it by using a MSCOMM component to enumarate COM 1 ~
>COM 16. (Setting its ComPort = 1, 2, ... 16 and check whether Error issued).
>When a port is a Virtual port (on network), this procedure takes long time.
>
>I wonder whether there is an API I can use to check (1) a specified COM Port
>exists. (2) If it does exist, tell me whether it is occupied by other
>application.


You normally use CreateFile to Open the COM port
- if it fails then it is in use or does not exist
Dick Grier

2005-02-26, 3:55 pm

Hi,

Yes, as another reply mentioned, Randy Birch has enumeration code on
mvps.org. However, these enumerations may err because they show installed
hardware -- some of which my be unavailable (but not uninstalled). For most
things, it is fine to continue to do what you are currently doing (IMO).

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com