aardio语法和一般编程语言并无二致.需要的自己去官方学习.今天主要介绍怎么来调用.net组件.

OpenHardwareMonitorLib.dll

c#写的开源组件,支持c++,python,aardio调用,可监控计算机的温度传感器,风扇速度,电压,负载和时钟速度,还有另一个加强版,支持更多,下一篇文章介绍.

支持CPU温度,功耗,电压,转速,显卡,独立显卡等.

aardio也有相应的库 sys.openHardwareMonitor.也有示例.但是今天我们不是用这个而是直接调用他的dll文件.

我们需要把 OpenHardwareMonitorLib.dll放在项目res文件夹下,选择内嵌资源,这样就能把dll打包到exe中.

实现代码

import console;

import dotNet;

hardwareType1 = {

[0] = "Mainboard";

[1] = "SuperIO";

[2] = "CPU";

[3] = "RAM";

[4] = "GpuNvidia";

[5] = "GpuAti";

[6] = "TBalancer";

[7] = "Heatmaster";

[8] = "HDD";

}

sensorType1 = {

[0] = "电压", // V

[1] = "时钟", // MHz

[2] = "温度", // °C

[3] = "负载", // %

[4] = "风扇转速", // RPM

[5] = "流", // L/h

[6] = "控制", // %

[7] = "等级", // %

[8] = "因素", // 1

[9] = "功耗", // W

[10] = "数据", // GB = 2^30 Bytes

[11] = "低数据", // MB = 2^20 Bytes

[12] = "网速", // MB/s = 2^20 Bytes/s

}

sensorFormat1 = {

[0] = lambda(v) ..string.format("%.3f V", v);

[1] = lambda(v) ..string.format("%.1f MHz", v);

[2] = lambda(v) ..string.format("%.1f °C", v);

[3] = lambda(v) ..string.format("%.1f %%", v);

[4] = lambda(v) ..string.format("%d RPM", v); // RPM

[5] = lambda(v) ..string.format("%.1f L/h", v);

[6] = lambda(v) ..string.format("%.1f %%", v);

[7] = lambda(v) ..string.format("%.1f %%", v);

[8] = lambda(v) ..string.format("%d", v);

[9] = lambda(v) ..string.format("%.1f W", v);

[10] = lambda(v) ..string.format("%.1f GB", v);

[11] = lambda(v) ..string.format("%.1f MB", v);

[12] = lambda(v) ..string.format("%.1f MB/s", v);

}

dotNet.loadFile("/res/OpenHardwareMonitorLib.dll").import("OpenHardwareMonitor");

var c1 = ..OpenHardwareMonitor.Hardware.Computer();

c1.MainboardEnabled = true;

c1.CPUEnabled = true;

c1.HDDEnabled = true;

c1.RAMEnabled = true;

c1.GPUEnabled = true;

c1.FanControllerEnabled = true;

c1.Open();

hardware1 = c1.Hardware

for(i=1;hardware1.Length;1){

hardware1[i].Update()

console.dump(hardware1[i].Name)

for(j=1;hardware1[i].Sensors.Length;1){

var sensor =hardware1[i].Sensors[j]

var sensors = sensorFormat1[sensor.SensorType];

console.dump(sensor.Name,sensorType1[sensor.SensorType],sensors(sensor.Value:0),sensors(sensor.Max:0),sensors(sensor.Min:0))

}

}

有了上边数据,可以很容易开发出显示硬件监控程序.但是这个库缺点也很明显,不能获取网速,硬盘使用率,个人更推荐另一个 LibreHardwareMonitorLib.dll,这两个都是在github开源的,网上大多数代码都是配合c#,python的使用,关于其他语言 aardio,c++的没有,但是是支持的,只要可以调用dll的语言应该都可以.

个人没有学过c#,如果对c#了解,还能再aardio调用更多数据.