You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.5 KiB

  1. import clr #package pythonnet, not clr
  2. import wmi
  3. import time
  4. openhardwaremonitor_hwtypes = ['Mainboard','SuperIO','CPU','RAM','GpuNvidia','GpuAti','TBalancer','Heatmaster','HDD']
  5. cputhermometer_hwtypes = ['Mainboard','SuperIO','CPU','GpuNvidia','GpuAti','TBalancer','Heatmaster','HDD']
  6. openhardwaremonitor_sensortypes = ['Voltage','Clock','Temperature','Load','Fan','Flow','Control','Level','Factor','Power','Data','SmallData']
  7. cputhermometer_sensortypes = ['Voltage','Clock','Temperature','Load','Fan','Flow','Control','Level']
  8. def initialize_openhardwaremonitor():
  9. file = 'OpenHardwareMonitorLib'
  10. clr.AddReference(file)
  11. from OpenHardwareMonitor import Hardware
  12. handle = Hardware.Computer()
  13. handle.MainboardEnabled = True
  14. handle.CPUEnabled = True
  15. handle.RAMEnabled = True
  16. handle.GPUEnabled = True
  17. handle.HDDEnabled = True
  18. handle.Open()
  19. return handle
  20. def initialize_cputhermometer():
  21. file = r'C:\Users\Tednokent01\Downloads\MyCity\traffic_analyzer\CPUThermometerLib'
  22. clr.FindAssembly(file)
  23. clr.AddReference(file)
  24. from CPUThermometer import Hardware
  25. handle = Hardware.Computer()
  26. handle.CPUEnabled = True
  27. handle.Open()
  28. return handle
  29. def fetch_stats(handle):
  30. for i in handle.Hardware:
  31. i.Update()
  32. for sensor in i.Sensors:
  33. parse_sensor(sensor)
  34. for j in i.SubHardware:
  35. j.Update()
  36. for subsensor in j.Sensors:
  37. parse_sensor(subsensor)
  38. def parse_sensor(sensor):
  39. if sensor.Value is not None:
  40. if type(sensor).__module__ == 'CPUThermometer.Hardware':
  41. sensortypes = cputhermometer_sensortypes
  42. hardwaretypes = cputhermometer_hwtypes
  43. elif type(sensor).__module__ == 'OpenHardwareMonitor.Hardware':
  44. sensortypes = openhardwaremonitor_sensortypes
  45. hardwaretypes = openhardwaremonitor_hwtypes
  46. else:
  47. return
  48. if sensor.SensorType == sensortypes.index('Temperature'):
  49. print(u"%s %s Temperature Sensor #%i %s - %s\u00B0C" % (hardwaretypes[sensor.Hardware.HardwareType], sensor.Hardware.Name, sensor.Index, sensor.Name, sensor.Value))
  50. if __name__ == "__main__":
  51. print("OpenHardwareMonitor:")
  52. start = time.time()
  53. #HardwareHandle = initialize_openhardwaremonitor()
  54. #print(time.time() - start)
  55. #start = time.time()
  56. #fetch_stats(HardwareHandle)
  57. print(time.time() - start)
  58. print("\nCPUMonitor:")
  59. CPUHandle = initialize_cputhermometer()
  60. fetch_stats(CPUHandle)