简体   繁体   English

Windows Mobile设备可以检测到何时对接吗?

[英]Can the Windows Mobile device detect when it's docked?

我有一个应用程序,我需要知道运行它的Windows移动设备何时停靠,有什么主意该怎么做?

In addition to Thorsten's suggestions, you can also look for the NOTIFICATION_EVENT_RS232_DETECTED notification. 除了Thorsten的建议外,您还可以查找NOTIFICATION_EVENT_RS232_DETECTED通知。 The event name is legacy from back when USB was rare so ignore the fact that it says RS232, even with USB, the RS232 event occurs. 当USB很少见时,该事件的名称是从后开始的,因此忽略它说RS232的事实,即使使用USB,也会发生RS232事件。

You can use CeRunAppAtEvent to hook the notification. 您可以使用CeRunAppAtEvent挂接通知。 Again, ignore what the name of the API implies - you can also use it to set a system event which you can WaitForSingleObject on. 同样,忽略API名称的含义-您也可以使用它来设置系统事件,可以在该事件上使用WaitForSingleObject。

See the answer to this question for details and implementation. 有关详细信息和实现, 请参见此问题的答案

A Windows Mobile device is docked when you can resolve the PPP_PEER machine name, which can be used for TCP communication between the device and the host it is docked to. 当您可以解析PPP_PEER计算机名称时,Windows Mobile设备将被对接,该名称可用于该设备与其所连接的主机之间的TCP通信。 This is, however, only true when the cradle is actually connected to the PC. 但是,仅当底座实际连接到PC时,这才成立。

public static bool ActiveSyncConnected
{
    get
    {
        try
        {
            IPHostEntry entry = Dns.GetHostEntry("PPP_PEER");
            return true;
        }
        catch
        {
            return false;
        }
    }
}

Another solution (at least for industrial devices) would be to check the AC line state, ie whether it is currently connected to the power adapter. 另一个解决方案(至少对于工业设备而言)是检查AC线路状态,即当前是否连接到电源适配器。 This is true when the device is cradled, no matter whether connected to a PC or not. 不论设备是否连接到PC,都必须将其固定好。

public bool CurrentlyConnectedToACLine
{
    get
    {
        SYSTEM_POWER_STATUS_EX status = new SYSTEM_POWER_STATUS_EX();
        if (GetSystemPowerStatusEx(status, true))
            return status.ACLineStatus != 0;
        else
            return false;
    }
}

[StructLayout(LayoutKind.Sequential)]
internal class SYSTEM_POWER_STATUS_EX
{
    public byte ACLineStatus = 0;
    public byte BatteryFlag = 0;
    public byte BatteryLifePercent = 0;
    public byte Reserved1 = 0;
    public uint BatteryLifeTime = 0;
    public uint BatteryFullLifeTime = 0;
    public byte Reserved2 = 0;
    public byte BackupBatteryFlag = 0;
    public byte BackupBatteryLifePercent = 0;
    public byte Reserved3 = 0;
    public uint BackupBatteryLifeTime = 0;
    public uint BackupBatteryFullLifeTime = 0;
}

[DllImport("coredll.dll")]
private static extern bool GetSystemPowerStatusEx(SYSTEM_POWER_STATUS_EX lpSystemPowerStatus, bool fUpdate);

All above answers are right but use different approaches. 以上所有答案都是正确的,但使用不同的方法。 The question is, why your app needs to know if the device is docked. 问题是,为什么您的应用程序需要知道设备是否已对接。

If for using a PC ActiveSync Paasthru TCP/IP connection, then using the PPP_PEER solution is best. 如果要使用PC ActiveSync Paasthru TCP / IP连接,则最好使用PPP_PEER解决方案。

If you need just to know, if the device is externally powered, then using PowerstatusEx and AC_LINE is best. 如果您只想知道设备是否由外部供电,则最好使用PowerstatusEx和AC_LINE。 This can also be used via a power notification queue, so that the app does not need to poll for the status (see also the NOTIFICATION_EVENT_RS232_DETECTED approach). 也可以通过电源通知队列来使用它,因此应用程序无需轮询状态(另请参阅NOTIFICATION_EVENT_RS232_DETECTED方法)。

If you need just to know, that the device has been cradled, NOTIFICATION_EVENT_RS232_DETECTED approach is best. 如果您只想知道设备已被固定,则最好使用NOTIFICATION_EVENT_RS232_DETECTED方法。 For example if you have a vehicle dock and want to start communicating with a vehicle blackbox connected to the dock. 例如,如果您有一个车辆底座,并想开始与连接到该底座的车辆黑匣子进行通信。

You see, although all solutions look more or less the same at first look, they have different intentions. 您会看到,尽管所有解决方案乍一看都差不多,但它们的意图是不同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检测何时将Pocket PC停靠在Windows Mobile 2003的通讯座中 - Detecting when a Pocket PC is docked in a cradle in Windows Mobile 2003 在Windows Mobile设备上检测软重置 - Detect soft reset on Windows Mobile device 如何检测Windows Mobile设备是否具有摄像头? C# - how to detect if windows mobile device has camera ? c# 如何检测Windows Mobile 5设备序列号? (.NET CF 3.5) - How to detect Windows Mobile 5 Device Serial Number? (.NET CF 3.5) 如何在Windows Forms应用程序中检测连接到USB的移动设备(Iphone)? - How to detect mobile device(Iphone) connected to USB in windows forms application? 检测移动设备最小化 - Detect mobile device minimizing 如何检测用户何时单击Windows Mobile(.NET CF 3.5)中的通知图标 - How can you detect when the user clicks on the notification icon in Windows Mobile (.NET CF 3.5) 如何刷新到整个设备的屏幕(Windows Mobile)? - How to refresh to entire device's screen (Windows Mobile)? 使用JavaScript和Razor检测移动设备 - Detect Mobile Device with JavaScript and Razor 在Windows Phone 8.1中重新启动或启动设备时进行检测 - Detect when device Rebooting or Starting in Windows Phone 8.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM