7 Replies Latest reply on May 17, 2017 11:59 AM by Sean Kennedy

    MC65 Battery Level Programatically

    Peter McWha

      On an MC65, how does one determine the current battery level in VB.NET? Symbol.MT2000.Utils.BatteryState.Level returns -1.

        • Re: MC65 Battery Level Programatically
          Ritesh Gupta

          Hi,

           

          Look at Symbol.ResourceCoodination namespace and the SmartBatteryStatus class.  There is a property there for StateOfHealthEx.

           

          Also here is latest version of EMDK: https://portal.motorolasolutions.com/Support/US-EN/Resolution?solutionId=88177&productDetailGUID=e085d085364cf310VgnVCM10000081c7b10aRCRD&detailChannelGUID=171acaf8fb16e310VgnVCM1000000389bd0aRCRD

          • Re: MC65 Battery Level Programatically
            Peter McWha

            RG:

             

            Aaargh, my bad.

             

            One has to declare an instance of the class first, as in:

             

            sbs = New Symbol.ResourceCoordination.SmartBatteryStatus

            myuint = sbs.StateOfHealthEx

             

            I've marked your answer "correct".  Thank you for the help.

            • Re: MC65 Battery Level Programatically
              Peter McWha

              Except that, on a fully charged battery, the interface reports a StateOfHealthEx value of zero.  Or is this supposed to be the percentage of charge USED and not REMAINING?

              • Re: MC65 Battery Level Programatically
                Peter McWha

                OK, just ran an extended test and determined that on an MC65, regardless of the battery state of discharge, StateOfHealthEx value is constantly zero.

                 

                I ran the battery down and the value is still zero.

                 

                So either there is a bug in the MC65, or, StateOfHealthEx is not the answer.

                  • Re: MC65 Battery Level Programatically
                    Daniel Silva

                    A couple of comments.

                     

                    The MT2000 APIs only work on our MT2000 device.  This is not the first time I've seen someone try to use them on something else, so wanted to mention this for anyone else that gets confused by this.

                     

                    If you look in the EMDK help file, under Programmer's Guide/MC65 Programming you will see down the bottom.

                    2.    The ChargeCycles and StateOfHealth fields in the SmartBatteryStatus structure are not supported.


                    The Smart Battery API features are only supported in certain devices, but it gives information more around how many charge cycles the battery has had, not the current charge state.  If you are looking for the current charge state of the battery, you can use the standard Microsoft API's.  There is a sample app that comes with the EMDK that shows how this can be done.  It should be on your PC in a path similar to this.

                    C:\Users\Public\Motorola EMDK for .NET\v2.9\Samples VS2008\C#\CS_PowerSample1


                    • Re: MC65 Battery Level Programatically
                      Sean Kennedy

                      Two things as part of this article -- and it was with a Case for MC67 that I found what was going wrong in .NET.   (Thanks Jacques G.)

                       

                      First -- Battery Life (How much Charge do I have.) Versus Battery Health.  

                       

                      The Symbol.ResourceCoordination.SmartbatteryStatus  is a Smart Battery Health Metrics method to query the Smart Battery Stats.

                      (Psion had a similar method for EP10, XT15, and others)

                       

                      Battery LIFE however is different and this Microsoft Article is a better plan:

                      HOWTO: Get the Device Power Status

                       

                       

                      One thing I found for .NET when setting up the call to SmartBatteryStatus is in the object init.

                       

                      Be careful if you do this:

                      *** snip ***

                      {

                          public partial class Form1 : Form

                          {

                             

                              private delegate void MethodInvoker();

                       

                       

                              private Symbol.ResourceCoordination.SmartBatteryStatus _smartBatteryStatus;

                       

                       

                              public Form1()

                              {

                                  InitializeComponent();

                                  GetBatteryState();

                              }

                       

                       

                              private void btnExit_Click(object sender, EventArgs e)

                              {

                                  Application.Exit();

                              }

                       

                       

                              private void btnRefresh_Click(object sender, EventArgs e)

                              {

                                  SetBatteryState();

                              }

                       

                       

                              private void GetBatteryState()

                              {

                                  _smartBatteryStatus = new SmartBatteryStatus();

                                  int batteryHealth = _smartBatteryStatus.StateOfHealth;               //THIS DOES NOT WORK NOR RETURNS ANYTHING

                       

                      *** /snip ***

                       

                      Instead do this:

                       

                      *** snip ***

                       

                      {

                          public partial class Form1 : Form

                          {

                             

                              private delegate void MethodInvoker();

                       

                       

                              // private Symbol.ResourceCoordination.SmartBatteryStatus _smartBatteryStatus;     //  NOTE THIS CHANGE

                       

                       

                              public Form1()

                              {

                                  InitializeComponent();

                                  SetBatteryState();

                              }

                       

                       

                              private void btnExit_Click(object sender, EventArgs e)

                              {

                                  Application.Exit();

                              }

                       

                       

                              private void btnRefresh_Click(object sender, EventArgs e)

                              {

                                  GetBatteryState();

                              }

                       

                       

                              private void GetBatteryState()

                              {

                                  Symbol.ResourceCoordination.SmartBatteryStatus _smartBatteryStatus = new Symbol.ResourceCoordination.SmartBatteryStatus();  //  NOTE THIS CHANGE  

                                  _smartBatteryStatus.Refresh(); //  NOTE THIS CHANGE

                                  int batteryHealth = _smartBatteryStatus.StateOfHealth;                   //THIS NOW WILL GET A NUMBER FOR YOU

                      *** /snip ***

                       

                       

                      But Like I say -- you only get the Health Stats and Battery details.  (Like Battery Serial Number and BatteryMfgDate)

                       

                      I do hope this helps.   -sean