Article View: borland.public.cppbuilder.nativeapi
Article #521Re: Detecting virtual comports
From: Anton
Date: Sat, 26 Jan 2008 10:32
Date: Sat, 26 Jan 2008 10:32
90 lines
3558 bytes
3558 bytes
Hello Giuliano,
Let me explain:
I installed a bluetooth dongle and became 9 serial blue tooth ports, some
are only for reading, others just for writing.
I'm not quite sure how everyhing works, the menuitmes are in Chinese and
that's a little diificult for me.
But in contrast with a 'normal' usb to serial plug, those ports dont's
disappear after the dongle is unplugged
They are visible in the hardware-view and in the windows register.
So the software thinks the ports are present, tries to open them and maybe
that's the reason it takes such a long time.
But even if the dongle is plugged in it takes some time to detect which
ports are in use.
In fact I'm using then API232 functions like sio_open, but the results are
the same.
Regards,
Anton
"Giuliano" <nonfracassatelepalline@non_fracassate_le_pall.ine> schreef in
bericht news:vegkp3hhb89k52eol1c49492gc46k3iedv@4ax.com...
> Il Fri, 25 Jan 2008 14:26:01 +0100, "Anton" <acvoosten@zeelandnet.nl> ha
> scritto:
>
> [snip]
>>With a few of those existing virtual ports which are not really active, it
>>takes more then 10 seconds to open them and that's just the thing I want
>>to
>>avoid.
>>Maybe there's a timeout you can set or something else?
> [snip]
>
> Hi Anton
>
> ten seconds? Uhm... I never seen a such behaviour when opening a com
> port.
> For example, AFAIK, if the USB of a virtual COM port is unplugged, the
> port simply
> disappears. However, I use the following code to detect if a comport
> exists and if it's
> available. The fn returns true if the com exists and set the 2nd parameter
> to true
> if it's busy.
>
> bool IsComPortAvailable( int PortNumber, bool& InUse )
> {
> AnsiString const ComName = AnsiString( "\\\\.\\COM" ) + PortNumber;
>
> HANDLE const hComm =
> CreateFile(
> ComName.c_str(),
> GENERIC_READ | GENERIC_WRITE,
> 0,
> 0,
> OPEN_EXISTING,
> 0,
> 0
> );
>
> if ( hComm == INVALID_HANDLE_VALUE ) {
> DWORD const dwError = GetLastError();
> if ( dwError == 5 ) // Port exists, but cannot be opened
> InUse = true;
> else if ( dwError == 2 ) // Port does not exist
> return false;
> }
> else {
> CloseHandle( hComm );
> InUse = false;
> }
>
> return true;
> }
>
> Regards
>
> Giuliano
>
Technical Details
Message-ID:
<479b0c39@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4799cc68$1@newsgroups.borland.com> <njkjp3d5feaailo8p568elmqhntg8br1ku@4ax.com> <4799e374$1@newsgroups.borland.com> <vegkp3hhb89k52eol1c49492gc46k3iedv@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,1645444b8ff69f0e X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Anton" <acvoosten@zeelandnet.nl> Newsgroups: borland.public.cppbuilder.nativeapi References: <4799cc68$1@newsgroups.borland.com> <njkjp3d5feaailo8p568elmqhntg8br1ku@4ax.com> <4799e374$1@newsgroups.borland.com> <vegkp3hhb89k52eol1c49492gc46k3iedv@4ax.com> Subject: Re: Detecting virtual comports Date: Sat, 26 Jan 2008 11:32:08 +0100 Lines: 92 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 86.87.46.231 Message-ID: <479b0c39@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1201343545 86.87.46.231 (26 Jan 2008 02:32:25 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail