.Net CF 2.0 SerialPort DataReceived

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

Hi all,

I'm writing a PocketPC / CE application which communicates with a
Bluetooth GPS reciever that is paired to a serial port but I'm
experiencing odd behaviour from the CF 2.0 SerialPort class.

Everything is fine first time around, but if I quit my application and
restart a few times, pretty soon (usuaully the second or third
restart) the DataReceived event stops firing on the SerialPort object.

I'm connecting with this code:-

_comPort = new SerialPort(comPortName, comBaud, comParity,
comDataBits, comStopBits);

_comPort.Encoding = Encoding.ASCII;
_comPort.Handshake = comHandshake;
_comPort.ReceivedBytesThreshold = 1;
_comPort.DataReceived += new
SerialDataReceivedEventHandler(DataReceived);
_comPort.Open();

My DataReceived handler contains the following code:-

string newData = _comPort.ReadExisting();

When the app exits, I'm disconnecting / closing with:-

if (_comPort != null)
{
if (_comPort.IsOpen) _comPort.Close();

_comPort.Dispose();
_comPort = null;
}

Everything works fine on the first run, but after a couple of restarts
DataReceived stops firing. Any ideas?

Many TIA,



Simon
 
hi Simon,

sorry. it is not about the topic but do you have any gps data parser
written in c#?
 
Hi,

I also have one written in C# in my book (see below) -- it isn't quite free,
but there is other code that you might find to be useful, too.

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, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
Dick Grier said:
Hi,

I also have one written in C# in my book (see below) -- it isn't quite free,
but there is other code that you might find to be useful, too.

Dick


Hi Dick,

did in your book are some code for Compactframwork ?
bye
Rainer
 
In this business I'd say the price of a book is free or even net positive,
as you gain way more than $50 if you learn much of anything from it.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
Hi,

Yes, Chapter 9 covers serial communications using the Compact Framework.

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, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
hi Simon,

sorry. it is not about the topic but do you have any gps data parser
written in c#?

I do, yes, but parsing the NMEA data is the interesting bit. Unless
you're *really* pushed for time, forget copy/paste development and
roll your own. There's pretty much everything you need on the
following page:-

http://www.kh-gps.de/nmea-faq.htm
 
Back
Top