getSystemPowerStatus

G

Guest

Can anyone tells me that how can I get SystemPowerStatus from OpenNetCF ? I
can find Stucture SystemPowerStatus from Win32.Core but I cannot find the
getSystemPowerStatus. And I cant' use the BatteryMonitor an dBatteryLife
since the device I have cannot detect battery life. It always says battery
remaining is 0%.

In fact, I tried use the coredll myself but it does not work, here is the
code:

Private Declare Function GetSystemPowerStatus Lib "coredll.dll" (ByRef
PowerStatus As SystemPowerStatus) As Boolean

Private Sub TimerPower_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TimerPower.Tick

Dim powerStatus As SystemPowerStatus
Dim b As Boolean = GetSystemPowerStatus(powerStatus)
Dim bf As Integer = powerStatus.BatteryFlag
If powerStatus.ACLineStatus = ACLineStatus.Online Then
PowerIndicator.BackColor = Color.Lime
ElseIf bf = BatteryFlag.High Then
PowerIndicator.BackColor = Color.Lime
ElseIf bf = BatteryFlag.Critical Then
PowerIndicator.BackColor = Color.Red
ElseIf bf = BatteryFlag.Low Then
PowerIndicator.BackColor = Color.Yellow
End If
end sub

Can anyone tell me what's wrong with the code or tell me how can I use the
getPowerStatus from OpenNETCF ?

Thanks

Kempton
 
A

anamika

Hi Kempton,

Try this
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 System.UInt32
Public BatteryFullLifeTime As System.UInt32
Public Reserved2 As Byte
Public BackupBatteryFlag As Byte
Public BackupBatteryLifePercent As Byte
Public Reserved3 As Byte
Public BackupBatteryLifeTime As System.UInt32
Public BackupBatteryFullLifeTime As System.UInt32
End Class

<DllImport("coredll")> _
Private Shared Function GetSystemPowerStatusEx(ByVal
lpSystemPowerStatus As SYSTEM_POWER_STATUS_EX, ByVal fUpdate As
Boolean) As System.UInt32
End Function

Private status As New SYSTEM_POWER_STATUS_EX

Public Sub ShowStatus()
If Convert.ToInt32(GetSystemPowerStatusEx(status, False)) = 1 Then
BatteryStatus.Text = "Battery:" & String.Format("{0}%",
status.BatteryLifePercent)
End If
end sub

Thanks

Anamika
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top