检查Python脚本Raspberry的电源状态

2024-05-16 02:45:53 发布

您现在位置:Python中文网/ 问答频道 /正文

是否有一个与屏幕上的黄色闪电或红色PWR LED闪烁相同的东西可以从Python脚本中使用,以了解树莓是否存在电源问题

谢谢


Tags: 脚本led屏幕树莓红色电源黄色pwr
1条回答
网友
1楼 · 发布于 2024-05-16 02:45:53

在@MarkSetchell(谢谢!)的帮助下,这一切都很有效。我已经在RPI 3B+上测试了它,但有一些电源问题:

import subprocess

pt = subprocess.Popen(['/opt/vc/bin/vcgencmd', 'get_throttled'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
(res,err) = pt.communicate()
res = res.decode().split("=")[1]
res = res.rstrip("\n")
print ("Current Power Issues?    = ",(int(res,0) & 0x01) == 0x01)
print ("Any Power issues before? = ",(int(res,0) & 0x50000) == 0x50000)

相关问题 更多 >