Example #1
0
        /// <summary>
        /// Set up unattended power management mode so reader
        /// can be shut down cleanly before handheld suspends.
        /// </summary>
        /// <param name="portName"></param>
        private static void EnableUnattendedReaderMode(string portName)
        {
            DebugLog_Log_ToDisk("EnableUnattendedReaderMode");
            lock (rdrPowerReqHandles)
            {
                if (0 == rdrPowerReqHandles.Count)
                {
                    // See Unattended Mode example at http://stackoverflow.com/questions/336771/how-can-i-run-code-on-windows-mobile-while-being-suspended
                    //Modify for could not turn on issue
                    //CoreDLL.PowerPolicyNotify(PPNMessage.PPN_UNATTENDEDMODE, 1);
                    //DebugLog_Log_ToDisk("Set PPN_UNATTENDEDMODE to 1");

                    // Request that devices remain powered in unattended mode
                    // NOTE: If you don't do this, the system suspends anyway 1 minute after you press the power button
                    // (USB reader power light goes out, system publishes a Suspend notification.)
                    // With this request, it seems to run indefinitely.
                    foreach (string devName in new string[] {
                        portName + ":", // RFID Reader
                        "wav1:",        // Speaker
                        "com3:",        // GPS Intermediate Driver
                    })
                    {
                        IntPtr handle = CoreDLL.SetPowerRequirement(devName, CEDeviceDriverPowerStates.D0,
                                                                    DevicePowerFlags.POWER_NAME | DevicePowerFlags.POWER_FORCE,
                                                                    nullIntPtr, 0);
                        rdrPowerReqHandles.Add(handle);
                        DebugLog_Log_ToDisk("Set PowerRequirement " + handle.ToString() + " for " + devName);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Check status of connection and restore, if down
        /// </summary>
        public static void CheckConnection()
        {
            if (!subscriptionsDone)
            {
                Utility.PowerManager.PowerNotify += new PowerManager.PowerEventHandler(PowerManager_PowerNotify);
                DebugLog.Log     += new LogProvider.LogHandler(DebugLog_Log_ToDisk);
                subscriptionsDone = true;
            }
            lock (readerLock)
            {
                try
                {
                    if (null == _rdr)
                    {
                        //Modify for could not turn on issue
                        CoreDLL.PowerPolicyNotify(PPNMessage.PPN_UNATTENDEDMODE, 1);
                        DebugLog_Log_ToDisk("Set PPN_UNATTENDEDMODE to 1");

                        _rdr = RFIDScanner.ConnectReader();
                        EnableUnattendedReaderMode(Utility.ReaderPortName);

                        //_rdr.ParamSet("/reader/powerMode", Reader.PowerMode.MEDSAVE);
                        _rdr.ParamSet("/reader/powerMode", Reader.PowerMode.FULL);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Example #3
0
        private int BatteryStatusCheck()
        {
            try
            {
                if (CoreDLL.GetSystemPowerStatusEx2(status, (uint)Marshal.SizeOf(status), true) != 0)
                {
                    if (status.BatteryLifePercent <= 5)
                    {
                        return(1);
                    }
                    else if (status.BatteryVoltage < 3700)
                    {
                        return(2);
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                writeErrorLog(ex.Message, ex);
                throw ex;
            }

            return(-1);
        }
Example #4
0
 /// <summary>
 /// Withdraw unattended power management requirements
 /// to allow handheld to fully suspend.
 /// </summary>
 private static void DisableUnattendedReaderMode()
 {
     lock (rdrPowerReqHandles)
     {
         if (0 < rdrPowerReqHandles.Count)
         {
             foreach (IntPtr handle in rdrPowerReqHandles)
             {
                 CoreDLL.ReleasePowerRequirement(handle);
                 DebugLog_Log_ToDisk("Released PowerRequirement " + handle.ToString());
             }
             rdrPowerReqHandles.Clear();
             //Modify for could not turn on issue
             DebugLog_Log_ToDisk("Set PPN_UNATTENDEDMODE to 0");
             CoreDLL.PowerPolicyNotify(PPNMessage.PPN_UNATTENDEDMODE, 0);
             //DebugLog_Log_ToDisk("Set PPN_UNATTENDEDMODE to 0");
         }
     }
 }
Example #5
0
 private void Main_Closing(object sender, CancelEventArgs e)
 {
     CoreDLL.ShowTaskbar();
 }
Example #6
0
 private void Main_Load(object sender, EventArgs e)
 {
     CoreDLL.HideTaskbar();
 }