简体   繁体   English

如何以编程方式确定Motorola MC55 MC65 MC67在通讯座中

[英]How to Programmatically Determine that a Motorola MC55 MC65 MC67 Is in the Cradle

We need to be able to determine within the application running on the handheld device that the device has been returned to the cradle. 我们需要能够在手持设备上运行的应用程序中确定该设备已返回到通讯座。

While one method might be to observe if the battery charge level increases, this approach is really a workaround and will fail if the battery is at 100% charge. 虽然一种方法可能是观察电池电量是否增加,但是这种方法确实是一种解决方法,如果电池100%充电会失败。

We've unsuccessfully searched the EMD help files. 我们未能搜索EMD帮助文件。

The approach i take is to P/Invoke and check the PowerStatus of the device so i created a class called PowerStatus : 我采用的方法是P / Invoke并检查设备的PowerStatus,因此我创建了一个称为PowerStatus的类:

public enum ACLineStatus { Offline = 0, Online = 1, Unknown = 255 }
[Flags]
public enum BatteryStatus { High = 1, Low = 2, Critical = 4, Charging = 8, NoSystemBattery = 128, Unknown =-1 }

public class PowerStatus
{
    private struct _SYSTEM_POWER_STATUS_EX
    {
        public byte ACLineStatus;
        public byte BatteryFlag;
        public byte BatteryLifePercent;
        public byte Reserved1;
        public uint BatteryLifeTime;
        public uint BatteryFullLifeTime;
        public byte Reserved2;
        public byte BackupBatteryFlag;
        public byte BackupBatteryLifePercent;
        public byte Reserved3;
        public uint BackupBatteryLifeTime;
        public uint BackupBatteryFullLifeTime;
    }

    [DllImport("coredll")]
    private static extern uint GetSystemPowerStatusEx(ref _SYSTEM_POWER_STATUS_EX lpSystemPowerStatus,
        bool fUpdate);

    public ACLineStatus ACLineStatus { get; set; }
    public BatteryStatus BatteryStatus { get; set; }
    public byte? BatteryLifePercent { get; set; }
    public TimeSpan? BatteryLifeTime { get; set; }
    public TimeSpan? BatteryFullLifeTime { get; set; }
    public BatteryStatus BackupBatteryStatus { get; set; }
    public byte? BackupBatteryLifePercent { get; set; }
    public TimeSpan? BackupBatteryLifeTime { get; set; }
    public TimeSpan? BackupBatteryFullLifeTime { get; set; }

    private PowerStatus()
    {

    }

    public static PowerStatus GetCurrent()
    {
        _SYSTEM_POWER_STATUS_EX powerStatus = new _SYSTEM_POWER_STATUS_EX();
        GetSystemPowerStatusEx(ref powerStatus, true);

        return new PowerStatus
        {
            ACLineStatus = (ACLineStatus)powerStatus.ACLineStatus,
            BatteryStatus = (BatteryStatus)powerStatus.BatteryFlag,
            BatteryLifePercent = powerStatus.BatteryLifePercent.Between((byte)0, (byte)100) ? (byte?)powerStatus.BatteryLifePercent : null,
            BatteryLifeTime = powerStatus.BatteryLifeTime >= 0 ? new TimeSpan(0, 0, (int)powerStatus.BatteryLifeTime) as TimeSpan? : null,
            BatteryFullLifeTime = powerStatus.BatteryFullLifeTime >= 0 ? new TimeSpan(0, 0, (int)powerStatus.BatteryFullLifeTime) as TimeSpan? : null,
            BackupBatteryStatus = (BatteryStatus)powerStatus.BackupBatteryFlag,
            BackupBatteryLifePercent = powerStatus.BackupBatteryLifePercent.Between((byte)0, (byte)100) ? (byte?)powerStatus.BackupBatteryLifePercent : null,
            BackupBatteryLifeTime = powerStatus.BackupBatteryLifeTime >= 0 ? new TimeSpan(0, 0, (int)powerStatus.BackupBatteryLifeTime) as TimeSpan? : null,
            BackupBatteryFullLifeTime = powerStatus.BackupBatteryFullLifeTime >= 0 ? new TimeSpan(0, 0, (int)powerStatus.BackupBatteryFullLifeTime) as TimeSpan? : null
        };
    }
}

and then in my "device" class i have a timer which fires an event when the device is docked 然后在“设备”类中,我有一个计时器,当设备停靠时会触发一个事件

public static event EventHandler DeviceDocked;

    private static ACLineStatus _lastPowerState = PowerStatus.GetCurrent().ACLineStatus;
    private static void timer_Tick(object state)
    {
        ACLineStatus powerState = PowerStatus.GetCurrent().ACLineStatus;
        _timer.Change(Timeout.Infinite, Timeout.Infinite);
        if (powerState == ACLineStatus.Online && _lastPowerState == ACLineStatus.Offline)
        {
            var e = DeviceDocked;
            if (e != null)
            {
                e(null, EventArgs.Empty);
            }
        }
        _lastPowerState = powerState;
        _timer.Change(1000, Timeout.Infinite);
    }

That PowerStatus.GetCurrent() is probably all you need.. i hope this helps :) PowerStatus.GetCurrent()可能就是您所需要的。.我希望这会有所帮助:)

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

相关问题 防止用户在Motorola MC65和MC67 Windows Mobile上关闭GPS - Prevent users turning off GPS on Motorola MC65 and MC67 Windows Mobile 如何在摩托罗拉MC55上设置“橙色按钮”状态 - How to set “orange button” state on Motorola MC55 使用C#访问Motorola MC67的设备设置 - Access device settings of Motorola MC67 using C# Motorola MC65设备中的Magnetc Stripe Reader问题 - Magnetc Stripe Reader Issue in Motorola MC65 device DataWedge库 - 摩托罗拉MC55条码扫描非常慢 - DataWedge library - Motorola MC55 barcode scanning very slow C#-如何扫描10位数以上的5的交错2? 运行Windows Mobile 6.1的MC55上的Motorola EMDK 2.6 .NET - C# - How to scan Interleaved 2 of 5 with more than 10 digits? Motorola EMDK 2.6 .NET on MC55 running Windows Mobile 6.1 WIP6.5仿真器和Windows手持设备6.5(Motorola MC65)上未显示SIP按钮 - SIP buttons not showing on WM6.5 emulator and Windows handheld 6.5 (Motorola MC65) 在运行Windows Mobile 6.5.3的MC65上自动启动Datawedge - Automatically start Datawedge on MC65 running Windows Mobile 6.5.3 如何在Motorola MC75上禁用发送键和结束键 - How to Disable the Send and End keys on Motorola MC75 从Motorola MC 3000打印Crystal报告 - Printing Crystal Report from Motorola MC 3000
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM