Problem with System.IO.Ports.SerialPort.Open

M

Mugunth

Hi,
I've a strange problem with serial port class of .NET Framework 2.0
I use com0com (Null Modem COM Port emulator) to emulate a virtual
port.
This application creates virtual com port pairs with starting with
CNCA0 <-> CNCB0
CNCA1<-> CNCB1
etc.,
When I created a port with this name and try to open it using
SerialPort.Open,
I get a ArgumentException stating "The given port name does not start
with COM/com or does not resolve to a valid serial port."
Where as if I create a virtual serial port pair by name
COM20<->COM21
I can open both the ports and send/receive data between them.
However, HyperTerminal works fine for both the COM Ports.

What could be the problem? Any Help would be appreciated.
How could I circumvent this error?

Regards,
Mugunth
 
C

Chris Dunaway

Hi,
I've a strange problem with serial port class of .NET Framework 2.0
I use com0com (Null Modem COM Port emulator) to emulate a virtual
port.
This application creates virtual com port pairs with starting with
CNCA0 <-> CNCB0
CNCA1<-> CNCB1
etc.,
When I created a port with this name and try to open it using
SerialPort.Open,
I get a ArgumentException stating "The given port name does not start
with COM/com or does not resolve to a valid serial port."
Where as if I create a virtual serial port pair by name
COM20<->COM21
I can open both the ports and send/receive data between them.
However, HyperTerminal works fine for both the COM Ports.

What could be the problem? Any Help would be appreciated.
How could I circumvent this error?

It appears as if the SerialPort class requires that the port name
start with "COM". Here is part of the code that is in the
SerialPort.Open method:

if ((portName == null) || !portName.StartsWith("COM",
StringComparison.OrdinalIgnoreCase))
{
throw new
ArgumentException(SR.GetString("Arg_InvalidSerialPort"), "portName");
}

Can you change the virtual port names used by the emulator?

Chris
 
M

Mugunth

It appears as if the SerialPort class requires that the port name
start with "COM". Here is part of the code that is in the
SerialPort.Open method:

if ((portName == null) || !portName.StartsWith("COM",
StringComparison.OrdinalIgnoreCase))
{
throw new
ArgumentException(SR.GetString("Arg_InvalidSerialPort"), "portName");
}

Can you change the virtual port names used by the emulator?

Chris

Yes,
It is possible to change the Virtual Serial Ports' name...
But my doubt is, why is it that this class alone mandates the name to
start with COM,
when the actual Windows API doesn't?

Regards,
Mugunth
 
C

Chris Dunaway

Yes,
It is possible to change the Virtual Serial Ports' name...
But my doubt is, why is it that this class alone mandates the name to
start with COM,
when the actual Windows API doesn't?

I don't know why they chose to impose that restriction. Seems silly
to me as well.
 

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