469,326 Members | 1,478 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

GPS Erroring when using the Windows Mobile 6 SDK

20
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.WindowsMobile.Samples.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 ArgumentException Parameter Name chars.

Here are the full details of the Exception:
ArgumentException
ArgumentException
Parameter name: chars

at System.Text.UTF8Encoding.GetBytes(Char* chars, Int32 charIndex, Int32 charCount, Byte[] bytes, Int32 byteIndex, UTF8Encoder encoder)
at System.Text.UTF8Encoding.GetBytes(Char[] chars, Int32 charIndex, Int32 charCount, Byte[] bytes, Int32 byteIndex, UTF8Encoder encoder)
at System.Text.UTF8Encoding.UTF8Encoder.GetBytes(Char[] chars, Int32 charIndex, Int32 charCount, Byte[] bytes, Int32 byteIndex, Boolean flush)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Dispose(Boolean disposing)
at System.IO.TextWriter.Dispose()
at Microsoft.WindowsMobile.Samples.Location.Gps.GetPo sition(TimeSpan maxAge)
at Microsoft.WindowsMobile.Samples.Location.Gps.GetPo sition()
at Microsoft.WindowsMobile.Samples.Location.Gps.WaitF orGpsEvents()

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.WindowsMobile.Samples.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
Jan 25 '10 #1
11 4265
RedSon
5,000 Expert 4TB
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.
Jan 25 '10 #2
rb0135
20
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
Jan 25 '10 #3
RedSon
5,000 Expert 4TB
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.
Jan 25 '10 #4
rb0135
20
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
Jan 25 '10 #5
rb0135
20
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_LocationChanged) 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.
Jan 26 '10 #6
RedSon
5,000 Expert 4TB
Oh strange, sometimes you run into those errors that just don't make any sense. Well I'm glad you found it.
Jan 26 '10 #7
rb0135
20
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
Jan 26 '10 #8
rb0135
20
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
Jan 29 '10 #9
RedSon
5,000 Expert 4TB
Time to post your code....

Use [code] tags, or make a zip file, or use a paste bin.
Jan 29 '10 #10
rb0135
20
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:

Expand|Select|Wrap|Line Numbers
  1. using Microsoft.WindowsMobile.Samples.Location;
  2.  
  3. .....
  4.  
  5. Gps mygps = new Gps();
  6.  
  7.  
I then setup the handlers and open the GPS as per the MS example

Expand|Select|Wrap|Line Numbers
  1.  
  2. mygps.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);
  3. mygpsLocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
  4. mygps.Open();
  5.  
The handlers are coded as such (I update some variables in these routines)

Expand|Select|Wrap|Line Numbers
  1.  
  2. public void gps_DeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
  3.         {
  4.             GpsDeviceState device = args.DeviceState;
  5.  
  6.             _GPSStatus = device.DeviceState.ToString();
  7.             _GPSDeviceName = device.FriendlyName;
  8.             _GPSDeviceState = device.DeviceState.ToString();
  9.             _GPSServiceState = device.ServiceState.ToString();
  10.         }
  11.  
  12. public void gps_LocationChanged(object sender, LocationChangedEventArgs args)
  13.         {
  14.             GpsPosition position = args.Position;
  15.  
  16.             if (position.LatitudeValid)
  17.                 _CurrentLatitude = position.Latitude;
  18.             if (position.LongitudeValid)
  19.                 _CurrentLongitude = position.Longitude;
  20.             if (position.HeadingValid)
  21.                 _CurrentHeading = position.Heading;
  22.             if (position.SatellitesInViewCountValid)
  23.                 _Satellites = position.SatellitesInViewCount;
  24.  
  25.         } // End gps_LocationChanged
  26.  
  27.  

Thats all I do.

Regards,
Rob
Feb 4 '10 #11
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 GetSatellitesInSolution() it does a for loop which references inViewSatellites.Length but if inViewSatellites 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[] GetSatellitesInSolution()
{
Satellite[] inViewSatellites = GetSatellitesInView();
ArrayList list = new ArrayList();
for (int index = 0; index < dwSatelliteCount; index++)
{
Satellite found = null;
//check whether any satellites were inView
if (inViewSatellites != null)
{
for (int viewIndex = 0; viewIndex < inViewSatellites.Length && found == null; viewIndex++)
{
if (rgdwSatellitesUsedPRNs[index] == inViewSatellites[viewIndex].Id)
{
found = inViewSatellites[viewIndex];
list.Add(found);
}
}
}
}

return (Satellite[])list.ToArray(typeof(Satellite));
}
Sep 10 '10 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Nick White [MSFT] | last post: by
7 posts views Thread by Jarod_24 | last post: by
3 posts views Thread by Ilkka Maatta | last post: by
1 post views Thread by =?Utf-8?B?V29vZGdub21l?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.