PC Meter Desktop Application

Intro | Building the Device | Arduino Code | Desktop Application | Download & More

The desktop application continuously reads the CPU load and memory usage from Windows and sends the numbers to the meter device over the virtual COM port on the Arduino. I wrote it in C# and it requires .NET Framework 4.0 to run.

Using the program

PC Meter runs as a system tray application. Clicking on the tray icon will present the menu, which looks like this:

PC Meter Menu

CPU Load and Memory usage are displayed. Connected will be checked if the program is able to open the specified COM port, clicking on it will open/close the port. When the port is closed, you can click on Settings to bring up a form where you can specify which COM port to use.

That's basically it. The rest of this article will cover some details on how I developed the application.

Programmer's Notes

Retrieving the CPU Load & Memory usage

CPU Load is retrieved using a PerformanceCounter, which is well documented on multiple websites. Getting physical memory usage is a bit trickier however. The original version of this program used PerformanceCounter, but it turned out that it was wrong as it included physical memory and the page file both. To get just the physical memory used, I now use GetPerformanceInfo by Antonio Bakula.

(Special thanks to mnedix who brought the memory error to my attention. Checked out his very cool CPU/Memory indicator that uses nixie tubes!)

Bad values from the PerformanceCounter?

I've had one computer which was running Windows 7 that would report CPU load when the task manager showed none. I've read elsewhere that PerformanceCounter isn't always reliable. I don't know if that's true or not, but that's what this program depends on for CPU load. I've tried the program with 2-3 other computers running either Windows XP or 7 and they've worked fine.

Running as a system tray application

The first version of this program would hang when the computer was shutdown or suspended. The problem was that I hadn't developed it properly to work as a system try application. The new version of PC Meter written in 2018 does work correctly thanks to Michael Sorens' excellent guide and framework for creating a system tray application. I highly recommend reading his article if you're interested in that aspect of the program.

So far, I've only tested suspending the computer and waking it back up on one computer running Windows 7, and it works. I had to write some extra code to ignore an IOException that occurred. But once I did that it succeeds in resuming the connection to the COM port and sending data after waking up. I'll test it further when I'm able.

Back to Electronics Projects | Back to Main Menu


Posted 3/22/2018