-
Notifications
You must be signed in to change notification settings - Fork 0
/
PCMonitor.py
61 lines (50 loc) · 1.93 KB
/
PCMonitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import atexit
import signal
import serial
import psutil
import time
import clr
import sys
import os
hwtypes = ['Mainboard','SuperIO','CPU','RAM','GpuNvidia','GpuAti','TBalancer','Heatmaster','HDD']
sensortypes = ['Voltage','Clock','Temperature','Load','Fan','Flow','Control','Level','Factor','Power','Data','SmallData']
def initialize_openhardwaremonitor():
file = os.getcwd() + '\\dll\\OpenHardwareMonitorLib.dll'
clr.AddReference(file)
from OpenHardwareMonitor import Hardware
handle = Hardware.Computer()
handle.MainboardEnabled = True
handle.CPUEnabled = True
handle.RAMEnabled = True
handle.GPUEnabled = True
handle.HDDEnabled = True
handle.Open()
return handle
def write_gpu(handle):
for i in handle.Hardware:
i.Update()
for sensor in i.Sensors:
if hwtypes[sensor.Hardware.HardwareType] == 'GpuAti' and sensor.SensorType == sensortypes.index('Load'):
ser.write(bytes(str(sensor.Value) + '^', 'utf-8'))
elif hwtypes[sensor.Hardware.HardwareType] == 'GpuAti' and sensor.SensorType == sensortypes.index('Temperature'):
ser.write(bytes(str(sensor.Value) + ',', 'utf-8'))
def handle_exit():
ser.close()
if __name__ == "__main__":
atexit.register(handle_exit)
signal.signal(signal.SIGTERM, handle_exit)
signal.signal(signal.SIGINT, handle_exit)
ser = serial.Serial('COM5', 9600)
HardwareHandle = initialize_openhardwaremonitor()
while(True):
time.sleep(1)
cpuUsage = psutil.cpu_percent(None, False)
ser.write(bytes('*' + str(cpuUsage) + ',', 'utf-8'))
ramUsage = psutil.virtual_memory()
ramUsed = ramUsage.used / (2**30)
ramUsed = round(ramUsed, 1)
ramTotal = ramUsage.total / (2**30)
ramTotal = round(ramTotal, 1)
ser.write(bytes(str(ramUsed) + ',', 'utf-8'))
ser.write(bytes(str(ramTotal) + ',', 'utf-8'))
write_gpu(HardwareHandle)