Thread View: borland.public.cppbuilder.nativeapi
9 messages
9 total messages
Started by Anton
Fri, 25 Jan 2008 11:47
Detecting virtual comports
Author: Anton
Date: Fri, 25 Jan 2008 11:47
Date: Fri, 25 Jan 2008 11:47
17 lines
1318 bytes
1318 bytes
Hello all,
Using CreateFile("COM...".) it's easy to detect a serial port that's
physical present in the computer. (COM1 etc)
However when I try to open the USB-to Serial Port (COM11 etc) from my GPS
CreateFile fails.
Does somone knows another way how I can detect those virtual ports?
Thank's a lot!
Regards,
Anton
Re: Detecting virtual comports
Author: Giuliano
Date: Fri, 25 Jan 2008 12:17
Date: Fri, 25 Jan 2008 12:17
12 lines
1175 bytes
1175 bytes
Il Fri, 25 Jan 2008 12:47:43 +0100, "Anton" <acvoosten@zeelandnet.nl> ha scritto: [snip] >However when I try to open the USB-to Serial Port (COM11 etc) from my GPS >CreateFile fails. [snip] You have to put the prefix \\.\ in front of the COM[n] string. For example: "\\\\.\\COM11". Regards
Re: Detecting virtual comports
Author: Anton
Date: Fri, 25 Jan 2008 13:26
Date: Fri, 25 Jan 2008 13:26
32 lines
1774 bytes
1774 bytes
Thank you very much, how simple can it be. But,...... 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? Thanks again, Regards Anton "Giuliano" <nonfracassatelepalline@non_fracassate_le_pall.ine> schreef in bericht news:njkjp3d5feaailo8p568elmqhntg8br1ku@4ax.com... > Il Fri, 25 Jan 2008 12:47:43 +0100, "Anton" <acvoosten@zeelandnet.nl> ha > scritto: > > [snip] >>However when I try to open the USB-to Serial Port (COM11 etc) from my GPS >>CreateFile fails. > [snip] > > You have to put the prefix \\.\ in front of the COM[n] string. > > For example: "\\\\.\\COM11". > > Regards
Re: Detecting virtual comports
Author: Giuliano
Date: Fri, 25 Jan 2008 20:22
Date: Fri, 25 Jan 2008 20:22
50 lines
2493 bytes
2493 bytes
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
Re: Detecting virtual comports
Author: Remy Lebeau (TeamB)
Date: Fri, 25 Jan 2008 20:54
Date: Fri, 25 Jan 2008 20:54
21 lines
1762 bytes
1762 bytes
"Giuliano" <nonfracassatelepalline@non_fracassate_le_pall.ine> wrote in
message news:vegkp3hhb89k52eol1c49492gc46k3iedv@4ax.com...
> if ( dwError == 5 ) // Port exists, but cannot be opened
> InUse = true;
> else if ( dwError == 2 ) // Port does not exist
> return false;
Rather than checking for numeric literals, you should use the predefined
constants in winerror.h instead, so you can see what the code is actually
checking for, ie:
if ( dwError == ERROR_ACCESS_DENIED ) // Port exists, but cannot be
opened
InUse = true;
else if ( dwError == ERROR_FILE_NOT_FOUND ) // Port does not exist
return false;
Gambit
Re: Detecting virtual comports
Author: 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
>
Re: Detecting virtual comports
Author: Giuliano
Date: Sun, 27 Jan 2008 16:15
Date: Sun, 27 Jan 2008 16:15
35 lines
2331 bytes
2331 bytes
Il Sat, 26 Jan 2008 11:32:08 +0100, "Anton" <acvoosten@zeelandnet.nl> ha scritto:
>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.
Hi Anton
it seems a problem caused by a bad design of the BT serial port. Have you tried
to contact the manufacturer to ask for explanations? In my opinion, you don't have many
chances to resolve the problem with the standard API. If the supplier can furnish you the
access to a deepest layer, for example with a specific DLL, maybe you can have more
control upon the process to open a port.
Regards
Giuliano
Re: Detecting virtual comports
Author: Oliver Rutsch
Date: Mon, 28 Jan 2008 07:34
Date: Mon, 28 Jan 2008 07:34
29 lines
2249 bytes
2249 bytes
Hi Anton, > > 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. > I also have a COM-port detecting function and I discovered this kind of problem on some Laptops with virtual Bluetooth ports. I know that nobody wants to disable these virtual ports just to start our software. So the only way to solve this was to start a own thread for every port and to kill the thread (the hard way) if it took too long to respond. Not very nice but it works reliable. Bye, -- Dipl. Ing. Oliver Rutsch EMail: orutsch@sympatec.com Sympatec GmbH
Re: Detecting virtual comports
Author: Anton
Date: Mon, 28 Jan 2008 22:08
Date: Mon, 28 Jan 2008 22:08
58 lines
2817 bytes
2817 bytes
Thank you all for your tips. I discovered the problem is caused by the software. I've downloaded other software and the serial ports are detected immediately even when I unplug the dongle. But that's just a solution for me, cause in fact I make the program for other, unknown people and when they don't use the correct software they may have the same problems and blame it to my program. So the idea to start a thread to detect the comm-ports does not seem so bad to me. I'll think about it. Thanks and regards, Anton "Oliver Rutsch" <orutsch@sympatec.com> schreef in bericht news:479d85db$1@newsgroups.borland.com... > Hi Anton, > >> >> 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. >> > > I also have a COM-port detecting function and I discovered this kind of > problem on some Laptops with virtual Bluetooth ports. I know that nobody > wants to disable these virtual ports just to start our software. > So the only way to solve this was to start a own thread for every port and > to kill the thread (the hard way) if it took too long to respond. > Not very nice but it works reliable. > > Bye, > > -- > Dipl. Ing. Oliver Rutsch > EMail: orutsch@sympatec.com > Sympatec GmbH
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads