write BatteryLifePercent into a string and send it

A

Alessandro

Hi everyone...
I'm a beginner in C#, I'm trying to:

-> check the BatteryLifePercent, and put the value into a string;
->check the ACLineStatus to know if the device is connected to
external power,
->if yes add this info into the string;
->send the string via UDP to a server.

i wrote a very simple code to create an UdpClient and send a string to
a Server,
and this introduction to PowerStatus:

using System;
using System.Collections;
using System.Data;
using System.Runtime.InteropServices;

namespace PowerStatus
{
/// <summary>
/// Summary description for MainBatteryMonitor
/// </summary>

class MainBatteryMonitor
{
/// <summary>
/// The main entry point for the application
/// </summary>

public class SYSTEM_POWER_STATUS_EX2
{
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;
public uint BatteryVoltage;
public uint BatteryCurrent;
public uint BatteryAverageCurrent;
public uint BatteryAverageInterval;
public uint BatterymAHourConsumed;
public uint BatteryTemperature;
public uint BackupBatteryVoltage;
public byte BatteryChemistry;
}

public class 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(SYSTEM_POWER_STATUS_EX lpSystemPowerStatus,
bool fUpdate);

[DllImport("coredll")]
private static extern uint
GetSystemPowerStatusEx2(SYSTEM_POWER_STATUS_EX2 lpSystemPowerStatus,
uint dwLen, bool fUpdate);

static void Main(string[] args)
{
SYSTEM_POWER_STATUS_EX status = new SYSTEM_POWER_STATUS_EX();
SYSTEM_POWER_STATUS_EX2 status2 = new SYSTEM_POWER_STATUS_EX2();


..... ??? ...


I'm getting trouble to check those values about PowerStatus, and
putting them into a string...

Could anyone help me??
Thanks a lot!!!

Alessandro Sacchi
 

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