-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
上位机运行报错 #1
Comments
谢谢,这个库貌似没有12代intel的温度传感器,我把cpu温度改成gpu功耗了,但是跑起来我发现数据根本对不上,如图:import ctypes
import sys
import clr
import time
from pathlib import Path
import socket
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
class Observer:
def __init__(self) -> None:
clr.AddReference(
str(Path(__file__).parent.absolute()/'LibreHardwareMonitorLib.dll'))
from LibreHardwareMonitor.Hardware import Computer
self.computer = Computer()
self.computer.IsCpuEnabled = True
self.computer.IsGpuEnabled = True
self.computer.Open()
self.observe_types = (
('cpu load', 'CPU Total', 'load'),
('cpu temp', 'GPU Package', 'power'),
('gpu load', 'GPU Core', 'load'),
('gpu temp', 'GPU Core', 'temperature'),
)
""" self.observe_types = (
(
'cpu占用',
'cpu温度',
'gpu占用',
'gpu温度',
),
(
'CPU Total',
'Core (Tctl/Tdie)',
'GPU Core',
'GPU Core',
),
('load', 'temperature', 'load', 'temperature'),
) """
self.sensor_index = [[_[0]] for _ in self.observe_types]
for hardware in range(0, len(self.computer.Hardware)):
for sensor in range(0, len(self.computer.Hardware[hardware].Sensors)):
match_identifier = [
index for index, (title, _name, _id) in enumerate(self.observe_types)
if _name in str(self.computer.Hardware[hardware].Sensors[sensor].Name)
and _id in str(self.computer.Hardware[hardware].Sensors[sensor].Identifier)
]
print(self.computer.Hardware[hardware].Sensors[sensor].Name,
self.computer.Hardware[hardware].Sensors[sensor].Identifier,
self.computer.Hardware[hardware].Sensors[sensor].Value)
if len(match_identifier) > 0:
self.sensor_index[match_identifier[0]].extend(
[hardware, sensor])
def getData(self):
# 更新硬件信息
# print(self.sensor_index)
for h in set([_[1] for _ in self.sensor_index]):
self.computer.Hardware[h].Update()
data = ''
for title, hardware, sensor in self.sensor_index:
data += f'{title} : {str(self.computer.Hardware[hardware].Sensors[sensor].Value)}{"%" if "load" in title else "℃"}\n'
# print(title, str(self.computer.Hardware[hardware].Sensors[sensor].Value))
return data
def main():
ob = Observer()
addr = '192.168.31.69'
port = 34567
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while True:
try:
print('尝试连接 ', f'{addr}:{port}', end='\r')
soc.connect((addr, port))
print('连接成功')
while True:
print(ob.getData())
soc.send((ob.getData()+"\0").encode('utf-8'))
time.sleep(1)
except ConnectionError as e:
print(e.strerror)
print('连接关闭')
soc.close()
time.sleep(1)
if __name__ == '__main__':
main() |
抱歉,这是老版的程序,适用lvgl的程序小修改一下就好 在
|
可以了!,不过要改成 |
大佬,我还想请教一个问题,下位机的有个main文件有什么区别? |
src外面的那个main.cpp是最开始写代码做的备份,没什么用src里面的main文件就是esp32程序主入口文件
|
懂了,谢谢。 |
如图,我把
self.sensor_index
打印出来了,貌似cpu temp
少了点东西我的cpu是i7 12700h
The text was updated successfully, but these errors were encountered: