473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

write BatteryLifePercent into a string and send it

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
Nov 16 '05 #1
2 3918
Try doing a google groups search here
(http://groups-beta.google.com/group/...ramework.compa
ctframework) to see if you can find what you're looking for.

--
Tim Wilson
..Net Compact Framework MVP

"Alessandro" <sa***************@gmail.com> wrote in message
news:3b*************************@posting.google.co m...
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

Nov 16 '05 #2
There are several free power meter components, I use the one from
www.componentscience.net in the ElementsEx library.

--
floyd
"Alessandro" <sa***************@gmail.com> wrote in message
news:3b*************************@posting.google.co m...
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

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jajoo | last post by:
Hi everyone, I am trying to send files with multipart/form-date. Everything is ok with the send. But when I am receiving the files I should specify a directory where the files to be saved. The...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
0
by: Ireney Berezniak | last post by:
Hi, I am trying to send an UTF-8 XML string to remote resource via HttpWebRequest using POST method, which means that I need to get the request stream and write my XML string to it. No problems...
3
by: John A Grandy | last post by:
When writing rss xml to the client browser , is there any reason to load the rss xml string into an XmlDocument and then Response.Write() the XmlDocument.OuterXML.ToString() ? option 1: ...
5
by: Ivovh | last post by:
Hi, I am writing a application that should be able send commands to a device using the COM port. I have tested the commands with hyper terminal and there they work. For Example I press:...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: arjan321 | last post by:
Hello all, I have a strange problem with the .NET serialPort class. When I write some data to the serialport, not all the data is immediately send: every once in a while, only ~50 characters...
0
by: kuguy | last post by:
Hi all, I'm new to the forums, so I hope this isn't in the wrong place... I have that "Software caused connection abort: socket write error" exception error that i've never meet before. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.