Answered GPS intermediate driver - C# WinMO 5.0 .NET CF 3.5

  • Wednesday, August 12, 2009 11:27 AM
     
      Has Code
    Hi
    i have a few problem with this all GPS thing....
    1st
    If in the device the gps module wasn`t used before (mean cold start if i know well) the Sample Application don`t can`t determine the coordinates, but if i used before for example IGO will read (i guess have a buffer or something like that, cuz get gata where absoulutley no have gps signal....)
    2nd
    Sometimes i got null reference exception in the GPS sample what i found in (..Windows Mobile 6 SDK\Samples\PocketPC\CS\GPS) in GpsPositon.cs at 
    for (int viewIndex = 0; viewIndex < inViewSatellites.Length && found == null; viewIndex++) line, the inViewSateliites is null
    I guess i did something wrong because i would like to use the sample class in a static class.... i post my code, pls somebody help me

    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.WindowsMobile.Samples.Location;
    using System.Windows.Forms;
    
    namespace TecTracWM.gps
    {
        public static class GPSProvider
        {
            private static GpsDeviceState device = null;
            private static GpsPosition position = null;
            private static int x = 0;
            private static Gps modul = null;
            public static string longitude = "0";
            public static string latitude = "0";
            public static string time = "00:00:00";
            public static string satCount = "0";
            public static string modulName = "Pls use Init cmd";
    
    
            public static void init()
            {
                if (modul == null)
                {
                    x = 0;
                    modul = new Gps();
                    modul.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);
                    modul.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
                }
    
               if (!modul.Opened)
                    modul.Open();
            }
    
            public static void close()
            {
                if (modul != null)
                {
                    if (modul.Opened)
                    {
                        modul.Close();
                        device = null;
                        position = null;
                        longitude = "";
                        latitude = "";
                        time = "";
                        satCount = "";
                        modulName = "Pls use Init cmd";
                        //modul = null;
                    }
                }
            }
    
    
            private static void gps_LocationChanged(object sender, LocationChangedEventArgs args)
            {
                position = args.Position;
                UpdateData();
    
            }
    
            private static void gps_DeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
            {
                device = args.DeviceState;
                UpdateData();
            }
    
    
    
            private static void UpdateData()
            {
                if (modul.Opened)
                {
                    string str = "";
                    if (device != null)
                    {
                        x++;
                      
                        modulName = device.FriendlyName + " " + device.ServiceState + ", " + device.DeviceState + "Count: " + x + "\r\n";
                    }
    
                    if (position != null)
                    {
    
                        if (position.LatitudeValid)
                        {
                            latitude = position.Latitude.ToString("00.0000");
                         
                        }
    
                        if (position.LongitudeValid)
                        {
                            longitude = position.Longitude.ToString("00.000");
                          
                        }
    
    
                        if (position.SatellitesInSolutionValid &&
                            position.SatellitesInViewValid &&
                            position.SatelliteCountValid)
                        {
                           
                            satCount =  position.GetSatellitesInSolution().Length + "/" +
                                position.GetSatellitesInView().Length + " (" +
                                position.SatelliteCount + ")\r\n";
                        }
    
                        if (position.TimeValid)
                        {
                            time = position.Time.ToString();
                        }
                    }
    
                }
            }
    
    
        }
    }
    


    So my questions again :
    1. Why cant get any coordinates if i just start my application and wait for getting satellites... (who i can warm up the gps, or something like that)
    2. why i got null reference exception if i use like this way... (i guess the thread dont stop, or who know....)

    Thx for the answers
    • Edited by sannyo Wednesday, August 12, 2009 11:30 AM
    •  

Answers

  • Wednesday, August 12, 2009 1:17 PM
     
     Answered
    Hi,

    What you are seeing is common with GPS receivers. There will be a period of time after getting a fix that when moved out of view of the satellites that data will be received, after a while the data should stop being received or if you stop and start the GPS sample while out of view of the satellites then you will not get any data being received, only until you move back into view of the satellites.

    Hope this helps.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    • Marked As Answer by sannyo Thursday, October 15, 2009 6:24 AM
    •  

All Replies

  • Wednesday, August 12, 2009 12:08 PM
     
     
    Hi,

    You may want to read the following regarding the different types of starts a GPS receiver goes through :-

    http://www.ikegps.com/downloads/TTFFstartup.pdf

    Your device might have an option to download the satellite data as a file which will speed up the TTFF.

    I got the same exception when running the GPS sample yesterday, I would recommend debugging through the code to find where the Null Reference Exception is occuring.

    Hope this helps.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
  • Wednesday, August 12, 2009 12:56 PM
     
     
    Thx for the link,i read it....
    I figured out if i don`t want to know  how many satellites i connected then no have exception.....
    Another interesting thing.... when now have GPS signal (mean inside the house, verified with IGO) the sample still get GPS data (i bet from the intermediate driver, cuz if i restart the phone (htc touch diamond) then at start dont get any data inside the house....) somebody know why is that ? or it is the problem of the sample too ?
  • Wednesday, August 12, 2009 1:17 PM
     
     Answered
    Hi,

    What you are seeing is common with GPS receivers. There will be a period of time after getting a fix that when moved out of view of the satellites that data will be received, after a while the data should stop being received or if you stop and start the GPS sample while out of view of the satellites then you will not get any data being received, only until you move back into view of the satellites.

    Hope this helps.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    • Marked As Answer by sannyo Thursday, October 15, 2009 6:24 AM
    •  
  • Wednesday, August 12, 2009 9:05 PM
     
     
    Hi,
    i understand what you wrote, my problem is i got data if i restart the application (mean my app where i use the library) and no have GPS signal.....
    so i dont know where, or what i did wrong...
    try to use other timespan instead of TimeSpan.Zero but it don`t helped......
    maybe posted code is wrong ???? cuz no have idea what i screwed up....

  • Monday, January 09, 2012 1:08 PM
     
     
    I know you're a long time trying to solve the problem with the GPS signal and is having trouble starting it, because I am having the same problem, I wonder if you had any progress, I'm just asking you because in all forums I see her struggle to solve the problem and I am also experiencing this problem can you help me?
    If you still alive, because this forum was write in 2009, pls responde to me in:
    gbarizon@gmail.com
    Thanks in Advance!!!

    • Edited by gbarizon Monday, January 09, 2012 5:33 PM
    •