System.IO.Ports.SerialPort.GetPortNames return wrog names above CO

G

Guest

Hello all!

MY CASE:

I'm using VB.net 2005 express on a Dell Laptop with an USB Bluetooth key.
I'm trying to send data to a pocketPC.
COM numbers changes each time i've got a new bluetooh "connection" with my
PDA.
I need 2 ports, one for ingoing data, one for outgoing data (that's how
serial port profile in bluetooth is made)
Sometime it's COM 5 and 6, some time 11 and 12.

I'm using this code to get the port names, display them in a combobox to let
the user choosing the right one:
in the Form load event:
Dim ports As String() = System.IO.Ports.SerialPort.GetPortNames
Dim port As String
For Each port In ports
PortIn_List.Add(port)
PortOut_List.Add(port)
Next port
'CMB_xxxx are combobox
CMB_PortNumIn.DataSource = PortIn_List
CMB_PortNumOut.DataSource = PortOut_List

In the OK button:
SerialPortIn.PortName = CMB_PortNumIn.Text
SerialPortOut.PortName = CMB_PortNumOut.Text

MY PROBLEM:

with all COM numbers under 10, no problem, but with COM number above 9 (11
and 12 in my case), getportnames return "COM11c" and "COM12c"!
Is anybody can "duplicate" this error? Is it a bug?
 
D

Dick Grier

Hi Sam,
"COM11c" and "COM12c"!
<<

When you use these values to set the port, do they work, or is there an
error? I don't have any BT hardware to test right now, but I don't see this
with some other virtual serial port drivers for hardware that I do have
installed.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004.
See www.hardandsoftware.net for details and contact information.
 
G

Guest

No, it doesn't work with those names. I have to write "COM11" and "COM12" in
the comboboxes!
Are you able to test this function with a high numbuer next to COM?
 
G

Guest

Hello Dick, i have download VSterm from your pages and the problem is the same!
I can email you a capture of my screen with "COM14c" and "COM13c" in your
settings form of VSTerm! When I select them, no problem, but when I try to
open it, nothing happen, and the port open item in the menu is not checked!

It seems that when I move my usb dongle from Usb port to Usb Hub, COM number
change, that's why today, number are 13 and 14.
My Usb dongle is a "Top suxess" one, The chipset came from CSR, the driver
from Microsoft, V 5.1.2600.2180
 
Joined
May 9, 2008
Messages
1
Reaction score
0
I was able to work around this problem by cutting off the last character, when the number part of the name is longer than two characters.
Here's an extract of my C# code:

Code:
[size=2][color=#2b91af]List[/color][/size][size=2]<[/size][size=2][color=#0000ff]string[/color][/size][size=2]> ports = [/size][size=2][color=#0000ff]new [/color][/size][size=2][color=#2b91af]List[/color][/size][size=2]<[/size][size=2][color=#0000ff]string[/color][/size][size=2]>();
[/size][size=2][color=#0000ff]foreach[/color][/size][size=2] ([/size][size=2][color=#0000ff]string[/color][/size][size=2] name [/size][size=2][color=#0000ff]in[/color][/size][size=2] System.IO.Ports.[/size][size=2][color=#2b91af]SerialPort[/color][/size][size=2].GetPortNames())
{
[/size][size=2][color=#008000]	// Protection against clobbered names like "COM12c".
[/color][/size][size=2][color=#008000]	// Only "COM12" is valid in such case, so chomp the last char then.
[/color][/size][size=2][color=#008000]	// The highest port can be "COM99", so this shouldn't be a problem. (?)
[/color][/size][size=2][color=#0000ff]	if[/color][/size][size=2] ((name.Substring(0, 3) == [/size][size=2][color=#a31515]"COM"[/color][/size][size=2]) && (name.Substring(3).Length > 2))
		name = name.Substring(0, 5);
	ports.Add(name);
}[/size]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top