Windows mobile Windows Mobile 6.5 GPS设备-WaitForMultipleObjects返回258(超时)
我为2008-2009年的Windows mobile 6.1创建了一个GPS程序,可以在后台实时跟踪位置。多年来,它在这些设备上运行良好。由于某些原因,相同的代码在Windows Mobile 6.5上从来没有完美地工作过 经过数小时的操作(主要是无人使用设备时),我从函数“WaitForMultipleObjects”收到一个“超时”(代码258): 同样,这可能会持续数小时,突然之间,如果没有: 更新: -重新启动设备(谷歌地图确认没有GPS设备存在!) 这与Windows Mobile进入睡眠状态并减慢线程速度有关 以下是核心代码(改编自Microsoft SDK示例):Windows mobile Windows Mobile 6.5 GPS设备-WaitForMultipleObjects返回258(超时),windows-mobile,gps,compact-framework,Windows Mobile,Gps,Compact Framework,我为2008-2009年的Windows mobile 6.1创建了一个GPS程序,可以在后台实时跟踪位置。多年来,它在这些设备上运行良好。由于某些原因,相同的代码在Windows Mobile 6.5上从来没有完美地工作过 经过数小时的操作(主要是无人使用设备时),我从函数“WaitForMultipleObjects”收到一个“超时”(代码258): 同样,这可能会持续数小时,突然之间,如果没有: 更新: -重新启动设备(谷歌地图确认没有GPS设备存在!) 这与Windows Mobile进
//
///当“WindowsMobile”唤醒程序以检查新位置时
///
私有void OnNextGPSEvent_回调()
{
int SecondsToNextWakeUp=ETL.Mobile.Device.ScheduledCallback.MINIMUM_SecondsToNextWakeUp;
开关(this.SleepingState)
{
案例休眠StateType.SleepingForNext位置:
//获得位置
this.GPSEvent_WaitValue=(WaitForEventThreadResultType)WaitForMultipleObjects(2,this.GPSEvent_句柄,0,45000);
开关(此.GPSEvent\u WaitValue)
{
案例WaitForEventThreadResultType.Event\u位置已更改:
//得到一个新职位
this.FireLocationChanged(this.GetCurrentPosition());
//管理设备关机(节省电池)
如果(此.PositionFrequency>MIN\u SECONDS\u FREQUENCY\u for Device\u SHUTDOWN)
{
//闭合装置
这个.CloseDevice();
SecondsToNextWakeUp=(this.PositionFrequency-GPSDEVICE\u LOAD\u SECONDS\u LOAD\u TIME);
this.SleepingState=SleepingStateType.sleepingbefore设备唤醒;
}
其他的
{
//默认等待时间
this.SleepingState=SleepingStateType.SleepingForNextPosition;
}
打破
案例WaitForEventThreadResultType.Event\u状态已更改:
打破
案例WaitForEventThreadResultType.超时:
案例WaitForEventThreadResultType。失败:
案例WaitForEventThreadResultType.停止:
//>>>>>>>>>>>>>>>>>这就是错误发生的地方Windows Mobile 5/6 SDK附带的C#GPS样本是否存在相同的问题?如果存在,则可能是驱动程序问题,您需要向硬件制造商或OEM咨询
您可以通过轮询GPS驱动程序而不是依赖中间驱动程序接口的位置更改回调来缓解此问题
没有重置GPS硬件的标准方法。当程序使用GPS硬件时,GPS处于“开启”状态,而处于“关闭”状态(或处于极低功率模式)当没有程序在使用它时。如果您的GPS在WWAN芯片上,您可以通过关闭和在WWAN调制解调器上重置它。或者,一些GPS芯片接受ASCII或二进制串行命令来重置GPS本身,但这些是特定于芯片组的。您需要向GPS芯片组制造商查询这些代码
您的GPSID重置代码(我假设是源代码)与强制所有GPSID客户端断开连接相同,这会使GPS处于低功耗状态,但实际上可能不会重置硬件。Windows Mobile 5/6 SDK附带的C#GPS示例是否存在相同的问题?如果存在,则可能是驱动程序问题,您需要与您的硬件制造商或OEM合作
您可以通过轮询GPS驱动程序而不是依赖中间驱动程序接口的位置更改回调来缓解此问题
没有重置GPS硬件的标准方法。当程序使用GPS硬件时,GPS处于“开启”状态,而处于“关闭”状态(或处于极低功率模式)当没有程序在使用它时。如果您的GPS在WWAN芯片上,您可以通过关闭和在WWAN调制解调器上重置它。或者,一些GPS芯片接受ASCII或二进制串行命令来重置GPS本身,但这些是特定于芯片组的。您需要向GPS芯片组制造商查询这些代码
您的GPSID重置代码(我假设是源代码)与强制所有GPSID客户端断开连接相同,这会使GPS处于低功耗状态,但实际上可能不会重置硬件。今天早上我重现了这个问题(这不是那么容易).我认为Google Maps能够重置GPSID,但这不是真的。我尝试过杀死我的程序,但没有任何效果。似乎只有一个选择:重新启动!我怎么能让整个设备的GPS像那样崩溃?我发现社区做了一些重设GPS设备的应用程序。那没有任何作用。我将在下一步检查progr我自己手动重置GPSID服务。只是编写了一个重置GPSID服务的小程序。它也不起作用。代码的位置不够,但这里有一点:IntPtr hGPS=CreateFile(“GPD0:”,GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,IntPtr.Zero,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,IntPtr.Zero);if(hGPS.ToInt32()!=INVALID_HANDLE_VALUE){int Out=0;UInt32 DeviceIOValue=DeviceIoControl(hGPS,ioctlCode,null,0,ref Out,IntPtr.Zero);CloseHandle(hGPS)}今天早上我重现了这个问题(没那么容易).我认为Google Maps能够重置GPSID,但这不是真的。我尝试过杀死我的程序,但没有任何效果。似乎只有一个选择:重新启动!我怎么能让整个设备的GPS像那样崩溃?我发现社区做了一些重设GPS设备的应用程序。那没有任何作用。我将在下一步检查progr我自己手动重置GPSID服务。刚刚编写了一个重置GPSID服务的小程序。它也不起作用。没有足够的地方放代码,但这里有一点
this.GPSEvent_WaitValue = WaitForMultipleObjects(2, this.GPSEvent_Handles, 0, 45000);
/// <summary>
/// When "WindowsMobile" wake up the program to check for a new position
/// </summary>
private void OnNextGPSEvent_Callback()
{
int SecondsToNextWakeUp = ETL.Mobile.Device.ScheduledCallback.MINIMUM_SECONDTONEXTWAKEUP;
switch (this.SleepingState)
{
case SleepingStateType.SleepingForNextPosition:
// Get position
this.GPSEvent_WaitValue = (WaitForEventThreadResultType)WaitForMultipleObjects(2, this.GPSEvent_Handles, 0, 45000);
switch (this.GPSEvent_WaitValue)
{
case WaitForEventThreadResultType.Event_LocationChanged:
// Got a new position
this.FireLocationChanged(this.GetCurrentPosition());
// Manage device shutdown (save battery)
if (this.PositionFrequency > MIN_SECONDS_FREQUENCY_FORDEVICE_SHUTDOWN)
{
// Close device
this.CloseDevice();
SecondsToNextWakeUp = (this.PositionFrequency - GPSDEVICE_LOAD_SECONDS_LOAD_TIME);
this.SleepingState = SleepingStateType.SleepingBeforeDeviceWakeUp;
}
else
{
// Default Wait Time
this.SleepingState = SleepingStateType.SleepingForNextPosition;
}
break;
case WaitForEventThreadResultType.Event_StateChanged:
break;
case WaitForEventThreadResultType.Timeout:
case WaitForEventThreadResultType.Failed:
case WaitForEventThreadResultType.Stop:
// >>>>>>>>>>>>>> This is where the error happens <<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>> This is where the error happens <<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>> This is where the error happens <<<<<<<<<<<<<<<<<<<<<<<<<<<
// Too many errors
this.ConsecutiveErrorReadingDevice++;
if (this.ConsecutiveErrorReadingDevice > MAX_ERRORREADINGDEVICE)
{
this.CloseDevice();
SecondsToNextWakeUp = (this.PositionFrequency - GPSDEVICE_LOAD_SECONDS_LOAD_TIME);
this.SleepingState = SleepingStateType.SleepingBeforeDeviceWakeUp;
}
else
{
// Default Wait Time
this.SleepingState = SleepingStateType.SleepingForNextPosition;
}
break;
}
#endregion
break;
case SleepingStateType.SleepingBeforeDeviceWakeUp:
this.OpenDevice();
SecondsToNextWakeUp = GPSDEVICE_LOAD_SECONDS_LOAD_TIME;
this.SleepingState = SleepingStateType.SleepingForNextPosition;
break;
}
if (this.IsListeningGPSEvent)
{
// Ajustement du prochain rappel
this.NextGPSEvent_Callback.SecondToNextWakeUp = SecondsToNextWakeUp;
this.NextGPSEvent_Callback.RequestWakeUpCallback();
}
}
/// <summary>
///Create Thread
/// </summary>
private void StartListeningThreadForGPSEvent()
{
// We only want to create the thread if we don't have one created already and we have opened the gps device
if (this._GPSEventThread == null)
{
// Create and start thread to listen for GPS events
this._GPSEventThread = new System.Threading.Thread(new System.Threading.ThreadStart(this.ListeningThreadForGPSEvent));
this._GPSEventThread.Start();
}
}
private void ListeningThreadForGPSEvent()
{
this.GPSEvent_WaitValue = WaitForEventThreadResultType.Stop;
this.IsListeningGPSEvent = true;
// Allocate handles worth of memory to pass to WaitForMultipleObjects
this.GPSEvent_Handles = Helpers.LocalAlloc(12);
Marshal.WriteInt32(this.GPSEvent_Handles, 0, this._StopHandle.ToInt32());
Marshal.WriteInt32(this.GPSEvent_Handles, 4, this._NewLocationHandle.ToInt32());
Marshal.WriteInt32(this.GPSEvent_Handles, 8, this._GPSDeviceStateChanged.ToInt32());
this.Start_NextGPSEvent_Timer(this.PositionFrequency);
this.SleepingState = SleepingStateType.SleepingBeforeDeviceWakeUp;
this.OnNextGPSEvent_Callback();
}