Autodiscover, GPS and HTC P3300, VS8

Last post 04-18-2008 5:41 by inov. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 07-03-2007 4:43

    Autodiscover, GPS and HTC P3300, VS8

    WaitCommEvent seems to never set the event flags to RXCHAR but NONE, and thus no data will be read/handled even if GPS data arrives to the COM port. This is an incompatibility problem with .NET CF and HTC P3300.

    So what if we ignore the flag checking and read whatever it comes available? Inside Port.cs, function CommEventThread(), commenting off the following line will actually make GPS respond with valid data:

    // check for RXCHAR
    //if((eventFlags & CommEventFlags.RXCHAR) != 0)

    Another thing, if this one line is not commented off, then in Open() function of Port.cs, the priority of eventThread must be set to lower than BelowNormal (including), or the program hangs, device's connection to PC breaks, and the device has to be rebooted. It can also make AcitveSync blind... With this line commented off, the rest code can stay intact.

    Hope this will spare a couple of hours for someone who's having the same problem as I did.

    Bonnie
  • 07-03-2007 17:16 In reply to

    • Neil
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-30-2007
    • North Wales
    • Posts 1,136

    Re: Autodiscover, GPS and HTC P3300, VS8

    For the record, I changed the title of this topic since it has absolutely nothing to do with Smart Device Framework 2.0 as the OP had suggested.

    Neil Cowburn
    Principal Partner
    OpenNETCF Consulting, LLC

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 04-15-2008 13:42 In reply to

    Re: Autodiscover, GPS and HTC P3300, VS8

    Thanks!!! I still can't use GPS class on my HTC3300 (.NET 3.5) but finally I can read all NMEA statements on COM4  :D 

  • 04-18-2008 3:02 In reply to

    • inov
    • Top 500 Contributor
    • Joined on 04-18-2008
    • Posts 2

    Re: Autodiscover, GPS and HTC P3300, VS8

    Hi im'newbite,

    How to work with the GPS of the P3300?
     
    by class serial OpenNETCF ?
    by GPSID ? if yes have you a sample code ? or advises ?
     
    Hard difficult to work with the GPS P3300.
     
    thanks
  • 04-18-2008 5:24 In reply to

    Re: Autodiscover, GPS and HTC P3300, VS8

    1. Download OpenNETCF.IO.Serial

    2. Unzip and open it in VS2005/8. Change code in Port.cs (see above)

    3. Compile it.

    4. Create new project. Copy OpenNETCF.IO.Serial.dll file to your new project folder

    5. Add reference to OpenNETCF.IO.Serial.dll in new project.

    6. I can't (I don't know how?) use GPS class in OpenNetCF - we create new one -  add new class called htcgps.cs . Copy and paste code:

    using System;

    using System.Collections.Generic;

    using System.Text;

    using OpenNETCF.IO.Serial;

    namespace GKCRMMobile

    {

    public class htcgps

    {

    private Port serialPort; private string NMEA="";

    private string status = "closed";

    public string GetGPSStatus

    {

    get { return status; }

    }

    public string GetNMEAString

    {

    get

    {

    return NMEA;

    }

    }

    public void Open()

    {

    this.serialPort.Open();this.status = "opening";

    }

    public void Close()

    {

    this.serialPort.Close();

    this.status = "closed";

    }

    public string GPSLat

    {

    get {

    string slat = "";

    if (status != "closed" && !string.IsNullOrEmpty(NMEA))

    {

     

    string[] todecode = NMEA.Split(',');if (!string.IsNullOrEmpty(todecode[2]))

    {

    status = "valid";

    double lat = Convert.ToDouble(todecode[2], System.Globalization.CultureInfo.InvariantCulture);

    lat = lat / 100;

    double deg = Math.Floor(lat);double minutes = (lat - System.Math.Floor(lat)) * 100;

    deg = deg + (minutes / 60);

    slat = todecode[3] + deg.ToString(
    "#.00000", System.Globalization.CultureInfo.InvariantCulture);

     

    }

     

    }

    return slat;

    }

    }

    public string GPSLong

    {

    get {

    string slong = "";

    if (status != "closed" && !string.IsNullOrEmpty(NMEA))

    {

    string[] todecode = NMEA.Split(',');if (!string.IsNullOrEmpty(todecode[4]))

    {

    status = "valid";

    double dlong = Convert.ToDouble(todecode[4],System.Globalization.CultureInfo.InvariantCulture);

    dlong = dlong / 100;

    double deg = Math.Floor(dlong);double minutes = (dlong - System.Math.Floor(dlong)) * 100;

    deg = deg + (minutes / 60);

    slong = todecode[5] + deg.ToString(
    "#.00000", System.Globalization.CultureInfo.InvariantCulture);

    }

     

    }

    return slong;

     

    }

    }

     

    public htcgps(string PortName)

    {

    serialPort =
    new Port(PortName, new HandshakeNone());serialPort.Settings.BaudRate = BaudRates.CBR_4800;

    serialPort.RThreshold = 1;

    serialPort.InputLen = 1;

    serialPort.DataReceived +=

    new OpenNETCF.IO.Serial.Port.CommEvent(serialPort_DataReceived);

     

    }

    private void serialPort_DataReceived()

    {

    byte[] inputData = new byte[1];

    string s = String.Empty;

    while (serialPort.InBufferCount > 0)

    {

    inputData = serialPort.Input;

    if (inputData[0] != '\r') s += Encoding.ASCII.GetString(inputData, 0, inputData.Length);

    else

    {

    if (s.Contains("GPGGA")) NMEA = s;s = string.Empty;

    }

    }

    }

    //koniec ciała klasy

    }

    }

    // end code

    That's all. Now you can create and use new instance of htcgps in your applications - it's very simply, just run Open() method and get GPSLong and GPSLat properties to read your position. 

     

    Filed under:
  • 04-18-2008 5:24 In reply to

    Re: Autodiscover, GPS and HTC P3300, VS8

    1. Download OpenNETCF.IO.Serial

    2. Unzip and open it in VS2005/8. Change code in Port.cs (see above)

    3. Compile it.

    4. Create new project. Copy OpenNETCF.IO.Serial.dll file to your new project folder

    5. Add reference to OpenNETCF.IO.Serial.dll in new project.

    6. I can't (I don't know how?) use GPS class in OpenNetCF - we create new one -  add new class called htcgps.cs . Copy and paste code:

    using System;

    using System.Collections.Generic;

    using System.Text;

    using OpenNETCF.IO.Serial;

    namespace GKCRMMobile

    {

    public class htcgps

    {

    private Port serialPort;

    private string NMEA="";

    private string status = "closed";public string GetGPSStatus

    {

    get { return status; }

    }

    public string GetNMEAString

    {

    get

    {

    return NMEA;

    }

    }

    public void Open()

    {

    this.serialPort.Open();this.status = "opening";

    }

    public void Close()

    {

    this.serialPort.Close();

    this.status = "closed";

    }

    public string GPSLat

    {

    get {

    string slat = "";

    if (status != "closed" && !string.IsNullOrEmpty(NMEA))

    {

     

    string[] todecode = NMEA.Split(',');if (!string.IsNullOrEmpty(todecode[2]))

    {

    status = "valid";

    double lat = Convert.ToDouble(todecode[2], System.Globalization.CultureInfo.InvariantCulture);

    lat = lat / 100;

    double deg = Math.Floor(lat);double minutes = (lat - System.Math.Floor(lat)) * 100;

    deg = deg + (minutes / 60);

    slat = todecode[3] + deg.ToString(
    "#.00000", System.Globalization.CultureInfo.InvariantCulture);

     

    }

     

    }

    return slat;

    }

    }

    public string GPSLong

    {

    get {

    string slong = "";

    if (status != "closed" && !string.IsNullOrEmpty(NMEA))

    {

    string[] todecode = NMEA.Split(',');if (!string.IsNullOrEmpty(todecode[4]))

    {

    status = "valid";

    double dlong = Convert.ToDouble(todecode[4],System.Globalization.CultureInfo.InvariantCulture);

    dlong = dlong / 100;

    double deg = Math.Floor(dlong);double minutes = (dlong - System.Math.Floor(dlong)) * 100;

    deg = deg + (minutes / 60);

    slong = todecode[5] + deg.ToString(
    "#.00000", System.Globalization.CultureInfo.InvariantCulture);

    }

     

    }

    return slong;

     

    }

    }

     

    public htcgps(string PortName)

    {

    serialPort =
    new Port(PortName, new HandshakeNone());serialPort.Settings.BaudRate = BaudRates.CBR_4800;

    serialPort.RThreshold = 1;

    serialPort.InputLen = 1;

    serialPort.DataReceived +=

    new OpenNETCF.IO.Serial.Port.CommEvent(serialPort_DataReceived);

     

    }

    private void serialPort_DataReceived()

    {

    byte[] inputData = new byte[1];

    string s = String.Empty;

    while (serialPort.InBufferCount > 0)

    {

    inputData = serialPort.Input;

    if (inputData[0] != '\r') s += Encoding.ASCII.GetString(inputData, 0, inputData.Length);

    else

    {

    if (s.Contains("GPGGA")) NMEA = s;s = string.Empty;

    }

    }

    }

    //koniec ciała klasy

    }

    }

    // end code

    That's all. Now you can create and use new instance of htcgps in your applications - it's very simply, just run Open() method and get GPSLong and GPSLat properties to read your position. 

     

    Filed under:
  • 04-18-2008 5:41 In reply to

    • inov
    • Top 500 Contributor
    • Joined on 04-18-2008
    • Posts 2

    Re: Autodiscover, GPS and HTC P3300, VS8

    Thanks you very much pandrzej :) :) :)

    I m looking and testing your sample.

     

     

Page 1 of 1 (7 items)