Read the battery power of the device
One of the things that we may not consider when we develop our mobile applications is the battery life of our device. It may be worth to consider building in a monitoring tool into our application to let the user know if their device need recharging.
The last thing that you want to happen is the user is in front of a customer with the device and about to put all the information in when it dies. While in reality the only option is to charge the device or carry spare batteries, it is important to make sure the user is aware when the battery is running low.
Sapphire Solutions (http://www.sapphire-solutions.co.uk) have developed the Sapphire Battery Utility that allows your eVB or VB.NET/C# application to read the current battery level of the device.
The Sapphire Battery Utility is very straightforward; it will return the battery level as a percentage. The utility comes as a compiled DLL that simply plugs right into your application using a DLL declaration call.
Running the demo project
Sapphire have also provided an extensive demo project in both eMbedded Visual Basic and VB.NET that show how to use all the functions of the DLL. You get all the eVB and VB.NET source code which is not only great for experienced programmers to implement the utility, but also great for new programmers to see how the application has been approached.
The latest version of the Sapphire Battery Utility can be downloaded from their web site here:
Once you have downloaded the demo project and unzip it, you will have two versions of the demo project, one for eVB and the other for VB.NET. You will also have a folder containing the different DLLs compiled for the different devices.
Simply select the DLL that matches the device. If you are developing in eVB, then you will need to copy the DLL to the \Windows\ path. Alternatively, if you are developing in VB.NET or C#, you need to copy the DLL to the application path. Check the project settings to see where the demo project will deploy itself to.
Now you are ready to run the demo. Please note the following screenshots have been taken from the VB.NET demo project.
Dim lPercent As Long
lPercent = BatteryPercent()
If lPercent = 255 Then
lblBattery.Text = " Battery Charging...."
lblBattery.Text = " Battery level is " & lPercent & " %"
Sapphire Solutions also provide a comprehensive manual for all their utilities. It includes a definition of the DLL function calls, some sample code and FAQs to help with any troubleshooting.
Their manual documentation can be viewed online, downloaded as a HTML document for offline use and even a downloadable Windows help file. These can all be found on their web site at http://www.sapphire-solutions.co.uk/manual.
Licence of use
Sapphire Solutions provide an unlimited use demo version of the Sapphire Battery Utility. While the product will function as normal, the user will receive a popup message stating that it is a demo version. It is great for trying out the utility, checking device compatibility, building it into your application and selling the idea to your customer. Students can use it as well for their college or university projects without having to purchase it either.
At the time of writing, Sapphire isn’t charging for the utility but you will need to register with them in order to get a licensed version of the utility. You can either purchase it with any other product or contact them directly with your company details and they will send you a licensed version via email.
|Copyright © 2004, CFVB.NET. All Right Reserved.|