Serial Port Opening Problem


M

mkoseoglu

Hello all,
I am trying to connect to my GPS receiver through a serial port using
compact framework 2.0 on a Pocket PC 2003. The GPS receiver is plugged
into the SD card drive. When I list the available serial ports on the
device using the SerialPort.GetPortNames() method, it gives me a list
of eight ports COM1-COM9 except COM7. As I know from another GPS
receiver, the SD card port is COM6. However, when I want to open the
ports named COM2-COM9 using SerialPort.Open() method, I got an error
saying that the port does not exists. I can open the port COM1
successfully.
I think this problem is related with virtual serial ports. I guess only
the COM1 port is a real serial port and the others are virtual. So is
there a way to connect the other ports in Compact Framework 2.0?

Thanks in advance,

Mehmet
 
Ad

Advertisements

P

Peter Foot [MVP]

Can you post a code snippet?

Also check that you don't have any other software running which may be using
the port.

Peter
 
G

Guest

And just because one vendor's device shows up as COM6 doesn't mean they all
will.

-Chris
 
M

mkoseoglu

Hello,
First, thank you for your replies.
In the meantime I was able read some data from the GPS card. So, the
problem does not occur always and is not related with virtual ports. I
am sorry for the wrong description. However, sometimes I still get the
error. I think when the port is not closed properly when exitting the
program, it may give this error in the next run. You can use the
following simple code segment to check which ports give that "the port
does not exist message". I believe for some of the ports you will get
the same error.

string[] ports = SerialPort.GetPortNames();

SerialPort gpsPort = new SerialPort(ports[0]);

try
{
gpsPort.Open();
}
catch (IOException exc)
{
MessageBox.Show(exc.ToString());
}

Mehmet
 
D

DickGrier

Hi,

A "rule-of-thumb" is that your program must close and dispose resources that
are used before exiting. This is especially important for resources (such
as System.IO.Ports), that use threading.

Dick

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

Chris Tacke, eMVP

Are you closing the port when you exit your app? Are you closing the port
before stopping debug? Failure to do either will leave the port in an
"in-use" state and therefore not openable until you restart.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
Ad

Advertisements

G

Graham McKechnie

Mehmet,

See my message, SerialPort.Close, if you think your port is not being close
properly.

Graham
 

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