473,671 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

write BatteryLifePerc ent into a string and send it

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

-> check the BatteryLifePerc ent, 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.Collecti ons;
using System.Data;
using System.Runtime. InteropServices ;

namespace PowerStatus
{
/// <summary>
/// Summary description for MainBatteryMoni tor
/// </summary>

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

public class SYSTEM_POWER_ST ATUS_EX2
{
public byte ACLineStatus;
public byte BatteryFlag;
public byte BatteryLifePerc ent;
public byte Reserved1;
public uint BatteryLifeTime ;
public uint BatteryFullLife Time;
public byte Reserved2;
public byte BackupBatteryFl ag;
public byte BackupBatteryLi fePercent;
public byte Reserved3;
public uint BackupBatteryLi feTime;
public uint BackupBatteryFu llLifeTime;
public uint BatteryVoltage;
public uint BatteryCurrent;
public uint BatteryAverageC urrent;
public uint BatteryAverageI nterval;
public uint BatterymAHourCo nsumed;
public uint BatteryTemperat ure;
public uint BackupBatteryVo ltage;
public byte BatteryChemistr y;
}

public class SYSTEM_POWER_ST ATUS_EX
{
public byte ACLineStatus;
public byte BatteryFlag;
public byte BatteryLifePerc ent;
public byte Reserved1;
public uint BatteryLifeTime ;
public uint BatteryFullLife Time;
public byte Reserved2;
public byte BackupBatteryFl ag;
public byte BackupBatteryLi fePercent;
public byte Reserved3;
public uint BackupBatteryLi feTime;
public uint BackupBatteryFu llLifeTime;
}

[DllImport("core dll")]
private static extern uint
GetSystemPowerS tatusEx(SYSTEM_ POWER_STATUS_EX lpSystemPowerSt atus,
bool fUpdate);

[DllImport("core dll")]
private static extern uint
GetSystemPowerS tatusEx2(SYSTEM _POWER_STATUS_E X2 lpSystemPowerSt atus,
uint dwLen, bool fUpdate);

static void Main(string[] args)
{
SYSTEM_POWER_ST ATUS_EX status = new SYSTEM_POWER_ST ATUS_EX();
SYSTEM_POWER_ST ATUS_EX2 status2 = new SYSTEM_POWER_ST ATUS_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 3932
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.goog le.com...
Hi everyone...
I'm a beginner in C#, I'm trying to:

-> check the BatteryLifePerc ent, 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.Collecti ons;
using System.Data;
using System.Runtime. InteropServices ;

namespace PowerStatus
{
/// <summary>
/// Summary description for MainBatteryMoni tor
/// </summary>

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

public class SYSTEM_POWER_ST ATUS_EX2
{
public byte ACLineStatus;
public byte BatteryFlag;
public byte BatteryLifePerc ent;
public byte Reserved1;
public uint BatteryLifeTime ;
public uint BatteryFullLife Time;
public byte Reserved2;
public byte BackupBatteryFl ag;
public byte BackupBatteryLi fePercent;
public byte Reserved3;
public uint BackupBatteryLi feTime;
public uint BackupBatteryFu llLifeTime;
public uint BatteryVoltage;
public uint BatteryCurrent;
public uint BatteryAverageC urrent;
public uint BatteryAverageI nterval;
public uint BatterymAHourCo nsumed;
public uint BatteryTemperat ure;
public uint BackupBatteryVo ltage;
public byte BatteryChemistr y;
}

public class SYSTEM_POWER_ST ATUS_EX
{
public byte ACLineStatus;
public byte BatteryFlag;
public byte BatteryLifePerc ent;
public byte Reserved1;
public uint BatteryLifeTime ;
public uint BatteryFullLife Time;
public byte Reserved2;
public byte BackupBatteryFl ag;
public byte BackupBatteryLi fePercent;
public byte Reserved3;
public uint BackupBatteryLi feTime;
public uint BackupBatteryFu llLifeTime;
}

[DllImport("core dll")]
private static extern uint
GetSystemPowerS tatusEx(SYSTEM_ POWER_STATUS_EX lpSystemPowerSt atus,
bool fUpdate);

[DllImport("core dll")]
private static extern uint
GetSystemPowerS tatusEx2(SYSTEM _POWER_STATUS_E X2 lpSystemPowerSt atus,
uint dwLen, bool fUpdate);

static void Main(string[] args)
{
SYSTEM_POWER_ST ATUS_EX status = new SYSTEM_POWER_ST ATUS_EX();
SYSTEM_POWER_ST ATUS_EX2 status2 = new SYSTEM_POWER_ST ATUS_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.goog le.com...
Hi everyone...
I'm a beginner in C#, I'm trying to:

-> check the BatteryLifePerc ent, 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.Collecti ons;
using System.Data;
using System.Runtime. InteropServices ;

namespace PowerStatus
{
/// <summary>
/// Summary description for MainBatteryMoni tor
/// </summary>

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

public class SYSTEM_POWER_ST ATUS_EX2
{
public byte ACLineStatus;
public byte BatteryFlag;
public byte BatteryLifePerc ent;
public byte Reserved1;
public uint BatteryLifeTime ;
public uint BatteryFullLife Time;
public byte Reserved2;
public byte BackupBatteryFl ag;
public byte BackupBatteryLi fePercent;
public byte Reserved3;
public uint BackupBatteryLi feTime;
public uint BackupBatteryFu llLifeTime;
public uint BatteryVoltage;
public uint BatteryCurrent;
public uint BatteryAverageC urrent;
public uint BatteryAverageI nterval;
public uint BatterymAHourCo nsumed;
public uint BatteryTemperat ure;
public uint BackupBatteryVo ltage;
public byte BatteryChemistr y;
}

public class SYSTEM_POWER_ST ATUS_EX
{
public byte ACLineStatus;
public byte BatteryFlag;
public byte BatteryLifePerc ent;
public byte Reserved1;
public uint BatteryLifeTime ;
public uint BatteryFullLife Time;
public byte Reserved2;
public byte BackupBatteryFl ag;
public byte BackupBatteryLi fePercent;
public byte Reserved3;
public uint BackupBatteryLi feTime;
public uint BackupBatteryFu llLifeTime;
}

[DllImport("core dll")]
private static extern uint
GetSystemPowerS tatusEx(SYSTEM_ POWER_STATUS_EX lpSystemPowerSt atus,
bool fUpdate);

[DllImport("core dll")]
private static extern uint
GetSystemPowerS tatusEx2(SYSTEM _POWER_STATUS_E X2 lpSystemPowerSt atus,
uint dwLen, bool fUpdate);

static void Main(string[] args)
{
SYSTEM_POWER_ST ATUS_EX status = new SYSTEM_POWER_ST ATUS_EX();
SYSTEM_POWER_ST ATUS_EX2 status2 = new SYSTEM_POWER_ST ATUS_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
7123
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 problem is that Tomcat saves the files into %CATALINA_HOME%/bin directory. I am wondering why? Why not into my application directory? The application directory is %CATALINA_HOME%/webapps/picture. As a parameter of directory I am giving "." – which...
18
4878
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) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
0
1060
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 here. The problem that I'm running into is that the "+" sign that one of the XML elements contains is lost somehow in the transaction. I verified that the "+" is actually in the XML string prior to getting bytes, and writing to stream: ...
3
7698
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: string rssXml = null; -- build rssXML -- Response.Write(rssXml);
5
5876
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: Escape then shift-x then shift-j and the device does what its suppose to do. No I made a little programma that connects to the comport. I use
0
789
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 by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
3
14049
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 by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
3
10544
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 of the 64 characters I'm sending gets send. Then, when I do a write() again, the data gets send. This is unacceptable behavior for my program.
0
5883
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. Basically what im trying to do is the following: - a client connect to a server using sslsocket. - server receive the connection and reply with the first part of the data and keep the connection open. - then client receive the reply and request for...
0
8476
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7437
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6229
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.