CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Jul 2009
    Posts
    20

    [RESOLVED] Windows CE 5.0 - Battery Strenght via registry

    Hello,
    I'm back again
    In the

    HKEY_LOCAL_MACHINE\System\State\Battery

    I have all I need to know about the battery status. I need to know what are possible values for battery strenght.

    Can you help me?
    Thanks to all!


  2. #2
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Windows CE 5.0 - Battery Strenght via registry

    Looks like there are a couple ways to go about it here:

    http://msdn.microsoft.com/en-us/library/aa456240.aspx

    Is this what you're looking for:

    BATTERYLEVEL_VERYLOW 0
    BATTERYLEVEL_LOW 21
    BATTERYLEVEL_MEDIUM 41
    BATTERYLEVEL_HIGH 61
    BATTERYLEVEL_VERYHIGH 81
    BATTERYSTATE_NORMAL 0
    BATTERYSTATE_NOTPRESENT 1
    BATTERYSTATE_CHARGING 2
    BATTERYSTATE_LOW 4
    BATTERYSTATE_CRITICAL 8

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Windows CE 5.0 - Battery Strenght via registry

    I think this is the only way to go about this
    Looks complicated ( at least for me ! ), but it would be very very interesting to get this working, I think we all would like to have a sample on this

  4. #4
    Join Date
    Jul 2009
    Posts
    20

    Re: Windows CE 5.0 - Battery Strenght via registry

    Thanks TT(n)

    @HanneSThEGreaT: I'm working on a virtual desktop for my GPS Windows CE 5.0 core base witha a 400 MHz samsung CPU.

    A image for you below



    This Virtual Desktop would be fully customizable for:
    - Background
    - Buttons (normal and hitting status)
    - Multipages
    - Every buttons can launch several applications or commands. Useful to fix the TomTom issue (My Documents folder)


    What is working now:

    - Buttons
    - GPS Status
    - Volume control by the wheel of the GPS

    What I have to do:

    - Reading a .ini file that have these options:

    _ StartUp command
    _ Buttons images and commands
    _ Exiting command

    - ... Any idea for the future

    Reading the file has been done! I've only to personalize my Virtual Desktop

  5. #5
    Join Date
    Jul 2009
    Posts
    20

    Re: Windows CE 5.0 - Battery Strenght via registry

    Hello TT(n)
    the link is for Windows Mobile instead of Windows CE... I've found no references on my VB2005, no keys in the registry on my GPS...

    Also i've not found the HKLM\System\State\Battery


  6. #6
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Windows CE 5.0 - Battery Strenght via registry

    CE is loosely based on mobile,... as I remember... lol
    The values should be the same.

    I'm not really familiar with the registry in WinCE, but here is a way to get power status in vb.net using the API.

    Code:
         Private Structure SYSTEM_POWER_STATUS
            Public ACLineStatus As Byte
            Public BatteryFlag As Byte
            Public BatteryLifePercent As Byte
            Public Reserved1 As Byte
            Public BatteryLifeTime As Int32
            Public BatteryFullLifeTime As Int32
        End Structure
    
        Private Declare Function apiGetSystemPowerStatus Lib "kernel32" Alias "GetSystemPowerStatus" (ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Int32
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim acdc As Int32 = GetPowerStatus.ACLineStatus
            Dim bStrength As Int32 = GetPowerStatus.BatteryFlag
    
            If acdc = 0 Then
                MessageBox.Show("AC power status: Offline")
            ElseIf acdc = 1 Then
                MessageBox.Show("AC power status: OnLine")
            ElseIf acdc = 2 Then
                MessageBox.Show("AC power status: Unknown")
            End If
    
            If bStrength = 1 Then
                MessageBox.Show("Battery charge status: High")
            ElseIf bStrength = 2 Then
                MessageBox.Show("Battery charge status: Low")
            ElseIf bStrength = 4 Then
                MessageBox.Show("Battery charge status: Critical")
            ElseIf bStrength = 8 Then
                MessageBox.Show("Battery charge status: Charging")
            ElseIf bStrength = 128 Then
                MessageBox.Show("Battery charge status: No system battery")
            ElseIf bStrength = 255 Then
                MessageBox.Show("Battery charge status: Unknown Status")
            End If
    
        End Sub
    
        Private Function GetPowerStatus() As SYSTEM_POWER_STATUS
            Dim SPS As New SYSTEM_POWER_STATUS
            If apiGetSystemPowerStatus(SPS) = 0 Then Return Nothing 'get the battery powerstatus and return nothing if fails
            Return SPS
        End Function
    If this api is included in the coredll, then you can also get BatteryLifePercent above.
    http://msdn.microsoft.com/en-us/libr...32(VS.85).aspx


    ___
    Last edited by TT(n); July 25th, 2009 at 06:51 AM.

  7. #7
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Windows CE 5.0 - Battery Strenght via registry

    There is an interesting article on MSDN.
    http://msdn.microsoft.com/en-us/library/aa446564.aspx

    I have not tried this myself yet but it looks like it may be what you are looking for assuming that using the registry is not a requirement.

    Related code and comments from the link above ...

    Code:
    Declare Function GetSystemPowerStatusEx Lib "coredll" _
       Alias "GetSystemPowerStatusEx" _
       (<[In](), Out()> ByVal lpSystemPowerStatus As SYSTEM_POWER_STATUS_EX, _
       ByVal fUpdate As Boolean) As Long
    The first thing to notice in the declaration is the specification of the parameter types. They can be used to specify which parameters are being passed out and which parameters will be returned containing the desired information. Since "In" is also a Visual Basic keyword, it is necessary to enclose it in square brackets. The "In" and "Out" types are actually defined by InteropServices and it is necessary to import this namespace:
    Code:
    Imports System.Runtime.InteropServices
    The next thing you will note is the SYSTEM_POWER_STATUS_EX structure that is returned by the function. This can be handled using a Structure or by placing the structure definition in a class and by specifying that the members are arranged sequentially:

    Code:
    <StructLayout(LayoutKind.Sequential)> _
    Public Class SYSTEM_POWER_STATUS_EX
      Public ACLineStatus As Byte
      Public BatteryFlag As Byte
      Public BatteryLifePercent As Byte
      Public Reserved1 As Byte
      Public BatteryLifeTime As Int16
      Public BatteryFullLifeTime As Int16
      Public Reserved2 As Byte
      Public BatteryBackupFlag As Byte
      Public BackupBatteryLifeTime As Byte  ' DocBug
      Public Reserved3 As Byte
      Public BackupBatteryLifePercent As Byte 'DocBug
      Public BackupBatteryFullLifeTime As Byte
    End Class
    Note that two of the members—BackupBatteryLifeTime and BackupBatteryLifePercent—are actually reversed from what is documented.

    Now calling this function is also straightforward:
    Code:
    Dim sps As New SYSTEM_POWER_STATUS_EX()
    ret = GetSystemPowerStatusEx(sps, False)

  8. #8
    Join Date
    Jul 2009
    Posts
    20

    Re: Windows CE 5.0 - Battery Strenght via registry

    Hello Datamiser, your method did not works... Also your I've tryed your method yesterday.

    Works only the second post of TT(n) but modifying the declaration with
    Code:
    Public Declare Function apiGetSystemPowerStatus Lib "Coredll.dll" Alias "GetSystemPowerStatusEx" (ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Int32
    Batterylifepercent now returns 50
    BatteryFullLifeTime and BatteryLifeTime are returning -1

    Any ideas?

  9. #9
    Join Date
    Jul 2009
    Posts
    20

    Re: Windows CE 5.0 - Battery Strenght via registry

    The percentage is now 40. I'll track this now

    See you next hours..

  10. #10
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Windows CE 5.0 - Battery Strenght via registry

    Ah, Data, so that's why in is in brackets.
    Cool, that makes sense now.

    Manny,
    BatteryFullLifeTime and BatteryLifeTime are returning -1
    Perhaps try using Byte instead of Int32, or some other type.

    I translated that code from the API guide, which used longs.
    Those are the only two that were different.
    I really don't know, but I suspect the type.

    Looks like you have a percentage though!

  11. #11
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Windows CE 5.0 - Battery Strenght via registry

    Hey just a wild guess, but the method Datamiser found may not work anymore, but once did.
    The struture is being passed in/out ByVal, but typically we'd use ByRef for that. Right?

    Code:
    Declare Function GetSystemPowerStatusEx Lib "coredll" _
       Alias "GetSystemPowerStatusEx" _
       (<[In](), Out()>  ByVal lpSystemPowerStatus As SYSTEM_POWER_STATUS_EX, _
      ByVal fUpdate As Boolean) As Long

    I bet that would work, if it were normal with ByRef, without in/out.
    Ehh?


    _______

  12. #12
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Windows CE 5.0 - Battery Strenght via registry

    I found another method in my local samples. This came with my symbol SDK. I have not used it yet but I did a quick look see and I do not see any references to symbol specific libs so this may work on other devices as well. I am attaching it here if you want to give it a try.
    Attached Files Attached Files
    Last edited by DataMiser; July 25th, 2009 at 07:10 PM.

  13. #13
    Join Date
    Jul 2009
    Posts
    20

    Re: Windows CE 5.0 - Battery Strenght via registry

    Good Morning!

    @TT(n) Using byte instead of int32 give me an exception error
    @DataMiser: Tryed your sampe. The Main Percentage returns same percentage of my BatteryLifePercent . Enable and disable backlight did not work. Suspend works fine!

    I'm going to try the byref / byval suggested by TT(n) but I think that the BatteryLifePercent is the solution. Next hour my GPS will shutdown for low energy, so I'll go to recharge it. Once charged I'll see the percentage battery if is 90&#37; - 100%

    Thanks to all

  14. #14
    Join Date
    Jul 2009
    Posts
    20

    Re: Windows CE 5.0 - Battery Strenght via registry

    Hello!
    After full recharging my GPS the BatteryLifePercent returns 100 now... So works fine
    The ACLineStatus works too.


  15. #15
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: [RESOLVED] Windows CE 5.0 - Battery Strenght via registry

    Which method did you end up using?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured