XWidgetSoft Forum

XWidget & XLaunchpad , Desktop customization
It is currently May 1st, 2025, 7:06 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: March 29th, 2018, 7:23 am 
Offline
User avatar

Joined: July 29th, 2013, 9:13 am
Posts: 609
In the absence of any decent new cores for years now, you have to be creative. You may have seen my recent posts on polyfills (ie. giving Xwidget functionality that other variations of the language/other engines already possess. In this case we are looking at adding support for Open Hardware Monitor. This follows on from my previous post : http://bbs.xwidget.com/viewtopic.php?f=3&t=6228

What is Open Hardware Monitor?
OHM is an open-source tool for extracting detailed system information and the particular bit of information we are talking about now is the temperature information as supplied from the various sensors that have been implemented on your PC hardware. OHM can provide data on a large amount of recognised hardware, the cpu cores, hard drives, motherboards &c. It all depends whether your hardware has those sensors and whether OHM supports them.

Why use OHM?
OHM is a free and functional alternative to coretemp and speedfan. Why would anyone bother to implement support for OHM, when cores exist for coretemp and speedfan already? Well, Speedfan is useless as although it provides temperatures through some exposed shared memory it does not tell you which sensor the temperature is from, utterly pointless. Coretemp is a good alternative but it only provides temperatures for the CPUs, any other temperature sensors are ignored.

In addition, Xwidget's cores are a little flawed, the speedfan core only provides one set of temperature data due to the limitations listed above, Tony's coretemp core names the cores incorrectly, so in general the temperature monitoring available to Xwidget is quite poor.

How to access OHM without a core?
So back to the code. The following code uses ActiveX to gain access to Windows WMI, a layer where OHM stores its sensor information. You can probe that information and extract it for a pointer to display on an Xwidget gauge. OHM must be installed and running to extract the sensor information.

Using my hardware as an example, it is an old Dell E5400 laptop, a core2duo with a Seagate hybrid drive. The only sensors it provides are for the two CPU cores and the hard drive. There are no other temperature sensors on the motherboard but many other PCs will have five, six or more sensors. OHM supports all my temperature sensors.

Code:
//=========================================================================
// this function
//=========================================================================
function updateOHM(){
    var strComputer = "."; // localhost
    var loc = new ActiveXObject("WbemScripting.SWbemLocator");
    var svc = loc.ConnectServer(strComputer, "root\\OpenHardwareMonitor");
    var a = 0, cpuTemp = new Array;

    coll = svc.ExecQuery("SELECT * FROM Sensor WHERE Name LIKE '%CPU Core%' AND SensorType = 'Temperature'");
    coll = svc.ExecQuery("SELECT * FROM Sensor WHERE SensorType = 'Temperature'"); // reports data in wbemtest
    //coll = svc.ExecQuery("SELECT * FROM Sensor WHERE Identifier = '/nvidiagpu/0/temperature/0'");
   
    var items = new Enumerator(coll);

    while (!items.atEnd())
    {
        a = a + 1;
        cpuTemp[a] = items.item().Value;
        print(">> "+ items.item().Name + " " +items.item().Value);
        items.moveNext();
    }
         cpuPointer.RotateAngle = (cpuTemp[1] * 3) + 30;
         cpuPointerShadow.RotateAngle = cpuPointer.RotateAngle;
    }
//=====================
//End function
//=====================


The above code will rotate a pointer such as the one pictured below, all you have to do is to call it via a timer and the pointer will rotate.

Image

The image above has a few additional fields that can be populated by data from OHM and via WMI. The code above does not demonstrate how, you'll have to do some investigation for yourself on how to do that but the example above will act as a guide. You could also wait until I finish creating my own Xwidget with the above code.

Smooth Animations
One limitation of doing it this way is that smooth animations are not available to you. Xwidget has a problem in that even though you can assign a smooth animation to a rotator image, it does not activate unless you also bind it to a core. As there are going to be no cores assigned then smooth animation is not available unless you implement it entirely in jscript code.

This shows you how easy it would be to implement open hardware monitor core on Xwidget if Tony would only find the time... In the meantime you can use my code above.

PS - Added the newly created widget containing the code.


Attachments:
File comment: My widget that has the above code to read temperatures from OHM
tank_temperature_gauge_ohm.xwp [2.74 MiB]
Downloaded 407 times
Top
 Profile  
 
PostPosted: April 7th, 2018, 11:15 am 
Offline
User avatar

Joined: July 29th, 2013, 9:13 am
Posts: 609
OHM and WMI is one area where Xwidget has an advantage of Yahoo widgets. Xwidget uses Jscript and in Jscript there exists a javascript non-native construct called Enumerator, it is available to both MS Jscript and VBscript and is a Microsoft hack to allow these two scripting languages access to Windows Instrumentation Layer (WMI) queries. This means you can use a query in the example code above and the resulting keyed data collection is then parsed in a meaningful way so it can be used in your jscript code.

Code:
coll = svc.ExecQuery("SELECT * FROM Sensor WHERE SensorType = 'Temperature'");
    var items = new Enumerator(coll);


This can't be done in pure javascript as the Enumerator construct is non native and not available. In addition Microsoft has not released its source code so it cannot be recreated for pure javascript or any other language. It is an extension for MS scripting languages only. The WMI output is also in a key indexed form that is complex and not easily readable using standard methods. The end result is that WMI query results are not available to the Yahoo widget engine.

To overcome this I have a clever workaround that re-uses the Jscript code above from an Xwidget. It involves the Yahoo widget engine running that portion of Jscript (shown above) from the Windows command line. It is possible to run jscripts in this way without Xwidget even being installed. Windows has two methods of calling scripts, cscript and wscript. Cscript is for running Jscript code in a windowless form, it just runs the code without a console or GUI output.

Code:
C:\> cscript //Nologo getTemps.js  > json.temp


This means that the Jscript can be run, querying WMI, formatting the output and then writing that output to a file which the Yahoo widget engine can then pick up and process. In this manner I can access Microsoft's Enumerator construct even though the Yahoo engine doesn't have it by default.

The code gets temperature information from WMI, enumerates it and extracts it to a JSON file. It is called by a timer.

Any language could use this code in this manner. Using this method, I have created a Yahoo widget of the OHM temperature gauge which looks and operates the same as the Xwidget, the code is similar. I will post it here soon so you can compare the code from the two widgets.

The code attached below is the jscript that can be run from the command line in the example above. It extracts the temperature information from Open Hardware Monitor.


Attachments:
File comment: This is the jscript that can be run from the command line to extract the temperature information from Open Hardware Monitor
getTemps.zip [901 Bytes]
Downloaded 380 times
Top
 Profile  
 
PostPosted: April 10th, 2018, 6:38 am 
Offline
User avatar

Joined: July 29th, 2013, 9:13 am
Posts: 609
This is the Yahoo widget version of the OHM gauge that calls the script above, which in turn was taken from the Xwidget OHM gauge.

Image

This Yahoo widget is a perfect example of running Jscript from the command line.

Feel free to open the widget and view the code for comparison purposes and to see how it is done. You'll see the code is very much the same as the Xwidget.

Tony could easily take the above code and adapt it and incorporate it into an OHM core.


Attachments:
File comment: New version - Previous Yahoo version of widget was downloaded 6 times
Panzer OHM gauge Ywidget.zip [2.92 MiB]
Downloaded 392 times
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Powered by phpBB® Forum Software © phpBB Group