GPS Erroring when using the Windows Mobile 6 SDK

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rb0135
    New Member
    • Jan 2010
    • 20

    GPS Erroring when using the Windows Mobile 6 SDK

    Hi all (and Mark).

    As I have posted a few times the last few weeks about my GPS application, I have got to the point of adding the GPS stuff in. I am using the Windows Mobile 6 SDk and used the Microsoft.Windo wsMobile.Sample s.Location project code for my project.

    Now, the problem is I am getting an error, sometimes straight away (once the GPS is initialised) or during the use of it.

    I get an "unexpected " error occuring and the only other information is ArgumentExcepti on Parameter Name chars.

    Here are the full details of the Exception:
    ArgumentExcepti on
    ArgumentExcepti on
    Parameter name: chars

    at System.Text.UTF 8Encoding.GetBy tes(Char* chars, Int32 charIndex, Int32 charCount, Byte[] bytes, Int32 byteIndex, UTF8Encoder encoder)
    at System.Text.UTF 8Encoding.GetBy tes(Char[] chars, Int32 charIndex, Int32 charCount, Byte[] bytes, Int32 byteIndex, UTF8Encoder encoder)
    at System.Text.UTF 8Encoding.UTF8E ncoder.GetBytes (Char[] chars, Int32 charIndex, Int32 charCount, Byte[] bytes, Int32 byteIndex, Boolean flush)
    at System.IO.Strea mWriter.Flush(B oolean flushStream, Boolean flushEncoder)
    at System.IO.Strea mWriter.Dispose (Boolean disposing)
    at System.IO.TextW riter.Dispose()
    at Microsoft.Windo wsMobile.Sample s.Location.Gps. GetPosition(Tim eSpan maxAge)
    at Microsoft.Windo wsMobile.Sample s.Location.Gps. GetPosition()
    at Microsoft.Windo wsMobile.Sample s.Location.Gps. WaitForGpsEvent s()

    Now, I know it isnt coming from my software as when I am debugging it (not emulator but connected the the WM6 device) it states the symbols cannot be loaded for debug. I am presuming it is something in the included DLL (the Microsoft.Windo wsMobile.Sample s.Location.dll) from theWindows Mobile 6 SDK.

    When I am debugging, I can get the Gps.cs SDK file to show itself (different reason) and it states the DLL it is using compared to the cs file is different. I havent recompiled anything, but wondering if the DLL I am using is NOT the correct one and this error is fixed in a different DLL (Just thinking out loud here and trying to supply all information).

    I have seen someone ask the same question in MSDN forums, but he was ignored.

    Has anyone (Mark?) had the same error when using the SDK's DLL?

    What is strange as it seems the Location Sample works fine. However, I am using the exact same code, in a class, within my application.

    Please... Any ideas?

    Thanks,
    Rob
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    You can build and run the sample without any problems? You should compare your project files and see if you have some missing settings that the sample project does not.

    Comment

    • rb0135
      New Member
      • Jan 2010
      • 20

      #3
      Hi Redson,

      Thanks for the reply, but I have exactly the same code as per the example. It is very simple code as most of the work is done by the DLL. (I have double checked).

      I have also created a new simple app, with the code from the example and I get the same error. The app doesnt display the values as per the sample (thats the only difference). I just load up a variable with the information, then display it when I push a button.

      I actually found all the source in the SDK folder that created the DLL, so I have recompiled the DLL and will test with this DLL.

      Rob

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        Right, if it's simple and most of the work is done in the dll but you are having problems. Then the problem is likely in your project setup not your code.

        Comment

        • rb0135
          New Member
          • Jan 2010
          • 20

          #5
          But, the DLL seems to be throwing the error in the routine when it is getting the information after the GPS event has fired. Would you say that is true (going by the error information provided)???

          The app doesnt need to do anything other than call the gps.Open command, so I cant understand why anything in the app could cause this issue.

          I will go over my stuff again.

          Thanks,
          Rob

          Comment

          • rb0135
            New Member
            • Jan 2010
            • 20

            #6
            Ok, I think I might have found the issue, but as the error occurs randomly (usually within the first 5 minutes of operation), I have my fingers crossed as it has been running for a hour so far.

            I found another sample using the same code. The original code (which I thought was from the SDK example, wasnt), had one of the routines (gps_LocationCh anged) as public void. Thi other sample I found buried in the SDK folders had the same routine as protected void. I change my definition to protected and as mentioned, it didnt fall over within the first 5-10 minutes.

            Here's hoping this was the issue.

            Comment

            • RedSon
              Recognized Expert Expert
              • Jan 2007
              • 4980

              #7
              Oh strange, sometimes you run into those errors that just don't make any sense. Well I'm glad you found it.

              Comment

              • rb0135
                New Member
                • Jan 2010
                • 20

                #8
                Yep, your right... I still cant see why they would make that much a difference, but I am no expert on this.

                It seem to go OK with the test so far...I am not trusting it just yet until I have used the app a fair few more times, but so far, so good.

                Thanks,
                Rob

                Comment

                • rb0135
                  New Member
                  • Jan 2010
                  • 20

                  #9
                  Ok.. spoke too soon..

                  Tried it twice today and it failed the second time.

                  Tried the MS sample and it fails (just takes longer).

                  So, it isnt my code after all that (by the looks of it)...

                  Any ideas to check?

                  Thanks,
                  Rob

                  Comment

                  • RedSon
                    Recognized Expert Expert
                    • Jan 2007
                    • 4980

                    #10
                    Time to post your code....

                    Use [CODE] tags, or make a zip file, or use a paste bin.

                    Comment

                    • rb0135
                      New Member
                      • Jan 2010
                      • 20

                      #11
                      Redson,

                      Thanks for trying to help, and it would be easy if your saw the code, but are you following that ALL the code, and where the error is occuring is in the MS SDK Sample Code.

                      All I do is:

                      Code:
                      using Microsoft.WindowsMobile.Samples.Location;
                      
                      .....
                      
                      Gps mygps = new Gps();
                      I then setup the handlers and open the GPS as per the MS example

                      Code:
                                      
                      mygps.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);
                      mygpsLocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
                      mygps.Open();
                      The handlers are coded as such (I update some variables in these routines)

                      Code:
                              
                      public void gps_DeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
                              {
                                  GpsDeviceState device = args.DeviceState;
                      
                                  _GPSStatus = device.DeviceState.ToString();
                                  _GPSDeviceName = device.FriendlyName;
                                  _GPSDeviceState = device.DeviceState.ToString();
                                  _GPSServiceState = device.ServiceState.ToString();
                              }
                      
                      public void gps_LocationChanged(object sender, LocationChangedEventArgs args)
                              {
                                  GpsPosition position = args.Position;
                      
                                  if (position.LatitudeValid)
                                      _CurrentLatitude = position.Latitude;
                                  if (position.LongitudeValid)
                                      _CurrentLongitude = position.Longitude;
                                  if (position.HeadingValid)
                                      _CurrentHeading = position.Heading;
                                  if (position.SatellitesInViewCountValid)
                                      _Satellites = position.SatellitesInViewCount;
                      
                              } // End gps_LocationChanged

                      Thats all I do.

                      Regards,
                      Rob

                      Comment

                      • tgderekw
                        New Member
                        • Sep 2010
                        • 1

                        #12
                        SDK Error

                        I have experienced the SDK device error (null exception) that happens at randomn intervals. I think this may be when no satellites are visible. In GetSatellitesIn Solution() it does a for loop which references inViewSatellite s.Length but if inViewSatellite s is null then this would go bang. So I have wrapped this in a null check and so far so good.

                        I saw this in the code on http://gpstracka.codeplex.com/

                        Hope this helps...

                        Code
                        ====
                        public Satellite[] GetSatellitesIn Solution()
                        {
                        Satellite[] inViewSatellite s = GetSatellitesIn View();
                        ArrayList list = new ArrayList();
                        for (int index = 0; index < dwSatelliteCoun t; index++)
                        {
                        Satellite found = null;
                        //check whether any satellites were inView
                        if (inViewSatellit es != null)
                        {
                        for (int viewIndex = 0; viewIndex < inViewSatellite s.Length && found == null; viewIndex++)
                        {
                        if (rgdwSatellites UsedPRNs[index] == inViewSatellite s[viewIndex].Id)
                        {
                        found = inViewSatellite s[viewIndex];
                        list.Add(found) ;
                        }
                        }
                        }
                        }

                        return (Satellite[])list.ToArray(t ypeof(Satellite ));
                        }

                        Comment

                        Working...