我在运行代码时一次又一次地收到此错误。
Exception in thread Thread-213:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/dist-packages/pyfirmata/util.py", line 47, in run
self.board.iterate()
File "/usr/local/lib/python2.7/dist-packages/pyfirmata/pyfirmata.py", line 264, in iterate
byte = self.sp.read()
File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 483, in read
ready, _, _ = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout.time_left())
ValueError: filedescriptor out of range in select()
我要做的就是计算项目中的耗电量。 我也在分享我的部分代码。我的柜台还在计数但之后 得到这个错误,我的柜台停了下来。 我可以在没有迭代器的情况下使用它,或者我是否需要停止迭代器。此应用程序应连续24x7运行。 所以应该没有代码错误的机会。请帮我克服它。如果我错了请帮助我,我只从互联网上学习python。
Traceback (most recent call last):
File "/media/pi/abc/MYPythonGUI.py", line 127, in <lambda>
File "/media/pi/abc/MYPythonGUI.py", line 119, in updateLabel
IOError: [Errno 24] Too many open files: 'Memory'
这是我的代码
import sys
import logging
from PyQt4 import QtGui, QtCore
import datetime
import time
from pyfirmata import Arduino, util
logging.basicConfig(filename='test.ods',level=logging.INFO, format='%(asctime)s:%(message)s')
PowerAccumulated = [0,0]
Mem=open('Memory','r')
PowerAccumulated[0] = float(Mem.read())
Mem.close()
class Window(QtGui.QMainWindow):
def _Power_Calculations(Self):
Date_labe2 = QtGui.QLabel(((datetime.datetime.today()).strftime("%d/%m/%y %H:%M")), Self)
newfont = QtGui.QFont("Times", 20, QtGui.QFont.Bold)
Date_labe2.setFont(newfont)
Date_labe2.setStyleSheet("color: blue")
Date_labe2.resize(250,120)
Date_labe2.move(610,400)
power_label2 = QtGui.QLabel(str(PowerAccumulated[1]), Self)
newfont = QtGui.QFont("Times", 20, QtGui.QFont.Bold)
power_label2.setFont(newfont)
power_label2.setStyleSheet("color: blue")
power_label2.resize(270,120)
power_label2.move(440,75)
QtCore.QTimer.singleShot(500, lambda: Self.updateLabel(power_label2,Date_labe2))
power_label3 = QtGui.QLabel("KW", Self)
newfont = QtGui.QFont("Times", 20, QtGui.QFont.Bold)
power_label3.setFont(newfont)
power_label3.setStyleSheet("color: blue")
power_label3.resize(270,120)
power_label3.move(600,75)
Self.show()
def updateLabel(Self, power_label2,Date_labe2):
try:
board=Arduino('/dev/ttyACM0')
iterator=util.Iterator(board)
iterator.start()
V1=board.get_pin('a:0:i')
time.sleep(0.1)
Voltage=100*(V1.read())
I1=board.get_pin('a:1:i')
time.sleep(0.1)
Current=20*float(I1.read())
if Current < 0.0976 :
Current = 0.0976
except:
Voltage=0.0
Current=0.0
Power=round( ((Voltage * Current * 0.98 * 1.732)/1000),3)
PowerAccumulated[1] =round((Power + PowerAccumulated[0]),3)
Self.Voltage = Voltage
Self.Current = Current
Self.Power = Power
Self.PowerAccumulated=PowerAccumulated[1]
logging.info('Valotage:{} - Current:{} - Power:{} - Power Accumulation:{}'.format(Self.Voltage, Self.Current, Self.Power, Self.PowerAccumulated))
Mem1=open('Memory','w')
Mem1.write(str(PowerAccumulated[1]))
Mem1.close()
PowerAccumulated[0] = PowerAccumulated[1]
power_label2.setText(str(PowerAccumulated[1]))
Date_labe2.setText((datetime.datetime.today()).strftime("%d/%m/%y %H:%M"))
QtCore.QTimer.singleShot(500, lambda: Self.updateLabel(power_label2,Date_labe2))
def run():
app = QtGui.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
run()