Reading GPS data from Serial Port

Last post 09-26-2007 11:13 by sfranchi. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 03-16-2006 11:43

    Reading GPS data from Serial Port

    Hello all,

    I am trying to create a Smart Mobile/GPS application using .Net 2003 framework. In addition for the GPS support I am using OpenNETCF SDK 1.4 library. I am having problems reading in data from the GPS . The following is my code snippet:

    private void button1_Click(object sender, System.EventArgs e)
    {
    gps.BaudRate = OpenNETCF.IO.Serial.BaudRates.CBR_9600;
    gps.ComPort = "COM1:";
    textBox1.Text = gps.ToString() + "\n";
    gps.GpsSentence += new OpenNETCF.IO.Serial.GPS.GPS.GpsSentenceEventHandler(gps_GpsSentence);
    gps.GpsCommState += new OpenNETCF.IO.Serial.GPS.GPS.GpsCommStateEventHandler(gps_GpsCommState);


    gps.Start();

    }

    private void gps_GpsSentence(object sender,GpsSentenceEventArgs e)
    {
    MessageBox.Show("calling");
    textBox1.Text += "calling" ;
    textBox1.Text += e.Sentence + " ";

    }

    private void gps_GpsCommState(object sender,GpsCommStateEventArgs e)
    {
    switch(e.State)
    {
    case OpenNETCF.IO.Serial.GPS.States.Running:
    textBox1.Text += "GPS Started";
    break;
    case OpenNETCF.IO.Serial.GPS.States.Stopped:
    textBox1.Text += "GPS Stop";
    break;

    }
    }

    When I run the code using a pocket PC emulator , the code fires gps_GpsCommState event (it always shows the message GPS started even when its not connected) , and more importantly it does not fire the gps_GpsSentence event ever. What is the problem?? Could anyone help me out with this. I would be greatly obliged. If you of any other way to read in data pls lemme know. Also let me know what is the problem with the code.

  • 04-06-2006 10:13 In reply to

    Re: Reading GPS data from Serial Port

    Hi,
    I am also starting using GPS library.
    I would like to know if you have solved your problem?
    Could you give me a simple sample to read the GPS data?

    Thank you a lot.


    ^'_"^
  • 04-07-2006 11:23 In reply to

    Re: Reading GPS data from Serial Port

    Hi there,
    Which port are u using now? I try on port com 7 and it fires the setence events.
    Mine PPC is HP 6515 with built-in GPS

    Cheers
    HAV

    ^'_"^
  • 04-07-2006 12:13 In reply to

    Re: Reading GPS data from Serial Port

    Hi, where should I find the more detail documentation on usage, methods for OpenNETCF? The online API doesnt tell much about each class.

    Thank you.

    ^'_"^
  • 04-29-2006 11:35 In reply to

    Re: Reading GPS data from Serial Port

    Hi,

    I am also working with ipaq 6515. I set gps.port="COM7:", and gps. BaudRate=4800. However, when the program execute gps.start(), an error message box shows that: could not open com port com7:

    What is the problem?

    Thanks.
  • 05-01-2006 22:10 In reply to

    Re: Reading GPS data from Serial Port

    I was also having the problem of finding out which Com port I am suposed to be using.
    I am also using HP 6515. How do I know what the GPS comm port is?
  • 05-23-2006 10:28 In reply to

    Re: Reading GPS data from Serial Port

    Hi,

    I have encountered same problem using OpenNETCF SDK 1.4 library. After analyzing a bit the code (i downloaded sources for OpenNETCF SDK 1.4) i have found something really interesting.

    Well, GPS class uses Port class for serial communication. Both classes use threading for processing messages. Good for Port class but not sure why that is needed for GPS class as its thread does nothing but Sleep()-ing almost all the time (well, to be honest, with few code to detect status, instantiate Port object based on status, etc. ). So, application already has two threads started when GPS.Start() exists with success. So far so "good", Port class creates thread with priority:

    eventThread.Priority = ThreadPriority.Highest;

    Highest priority possible (!!!???).

    After importing GPS and Port classes (raw sources with a bit of workaround) in my solution and:

    1. Making GPS not using threading at all.
    2. Making Port's thread priority, e.g.
    eventThread.Priority = ThreadPriority.BelowNormal;

    hanging has gone. Events are fired, which is good, and, most important, Form (which i use in my solution) has enough CPU time to catch events, draw what is necessary and refresh itself.

    I have a spv C500 phone with an ARM 200Mhz CPU. Not the best performing CPU, so 'ThreadPriority.Highest' is a kind of killer.

    Hope this helps.

    ahhrrrr ... problems again!
  • 05-24-2006 7:02 In reply to

    Re: Reading GPS data from Serial Port

    Can you possible post what it was you changed?
  • 05-25-2006 2:20 In reply to

    Re: Reading GPS data from Serial Port

    First, you need to download OpenNETCF SDK 1.4 sources.
    I will point on the most important fixes here. Others, like cutting threading approach from GPS.cs, is to be decided individually, by the particular needs of the project.

    1. So, in Port.cs, there is a method:
    - public bool Open()

    Inside it, there is the following code:
    eventThread = new Thread(new ThreadStart(CommEventThread));
    eventThread.Priority = ThreadPriority.Highest;
    eventThread.Start();

    Change it to be:
    eventThread = new Thread(new ThreadStart(CommEventThread));
    //eventThread.Priority = ThreadPriority.Highest;
    eventThread.Priority = ThreadPriority.BelowNormal;
    eventThread.Start();

    2. In the same Port.cs, there is another method:
    - private void CommEventThread()

    Inside it, there is the following code
    if(e == (int)APIErrors.ERROR_INVALID_HANDLE)
    {
    ...
    }

    Extend conditions of the IF statement be look loke:
    if((e == (int)APIErrors.ERROR_INVALID_HANDLE) ||
    (e == 31)|| (e == 7007))

    e == 31 – I found somewhere here in the forums.
    e == 7007 – I depicted as a return value on spv C500 when stopping GPS communication.

    This is pretty much all.

    It is important do decide where to apply these changes:
    - Directly to downloaded 'OpenNETCF SDK 1.4' sources and recompile whole OpenNETCF solution. This will create CAB files but not for SmartPhone armv4, which is required for spv c500.

    -Import Port.cs and GPS.cs sources to the own solution and apply changes there. Unfortunately, this will require importing a major part of the satellites classes of the OpenNETCF.IO.Serial namespace, most important are:
    - CommAPI.cs
    - DCB.cs
    which have many classes declared as internal.


    ahhrrrr ... problems again!
  • 07-01-2006 3:06 In reply to

    Re: Reading GPS data from Serial Port

    OK I finally got around to doing something about this. I ended up only having to set the priorities to Normal. Nothing else.

    Andrew
  • 09-25-2007 6:23 In reply to

    • sfranchi
    • Top 75 Contributor
    • Joined on 09-21-2007
    • Olivos, Buenos Aires - Argentina
    • Posts 5

    Re: Reading GPS data from Serial Port

    I had to do the same than andrewharris in my app (to raise the ThreadPriority to .Normal) in order to have data reception and events fired, any other approach for this? Actually I don't understand why the ThreadPriority causes the Serial object to stop receiving data.

    Thanks,

    Sandro.
  • 09-26-2007 11:13 In reply to

    • sfranchi
    • Top 75 Contributor
    • Joined on 09-21-2007
    • Olivos, Buenos Aires - Argentina
    • Posts 5

    Re: Reading GPS data from Serial Port

    I don't know if someone else did try this before, but changing the thread priority after it did start (into the run method) allows to change the thread priority and the data continues arriving and the events continue being rised, what I did is this:


    ...
    ...
    Thread.CurrentThread.Priority = ThreadPriority.Lowest; // Just added this line to the existing code
    while (state==States.Running)
    {
    Thread.Sleep(10);
    }
    ...
    ...


    The library continues working just fine, giving the chance to other processes to run better, not producing any problem to the NMEA processing objective of the thread.

    Best regards,


    Sandro.
Page 1 of 1 (12 items)