Linux can';t打开设备:打开的文件太多错误

Linux can';t打开设备:打开的文件太多错误,linux,python-3.x,raspberry-pi,spi,Linux,Python 3.x,Raspberry Pi,Spi,嗨,我在树莓皮3里有很糟糕的代码。我正在尝试阅读4 RC522模块,我能做到。但几分钟后,我出现了“无法打开设备:打开的文件太多”错误,我的while循环终止 我没有分享所有的功能。我想重要的部分是while循环。我在每个循环中创建实例。我想这是个大错误。我不能再耽搁了。我尝试将null赋值给我的对象,但仍然出现相同的错误。我的密码在下面 注意:我有4个SPI地址,我用它们创建实例 #!/usr/bin/env python # -*- coding: utf8 -*- import time

嗨,我在树莓皮3里有很糟糕的代码。我正在尝试阅读4 RC522模块,我能做到。但几分钟后,我出现了“无法打开设备:打开的文件太多”错误,我的while循环终止

我没有分享所有的功能。我想重要的部分是while循环。我在每个循环中创建实例。我想这是个大错误。我不能再耽搁了。我尝试将null赋值给我的对象,但仍然出现相同的错误。我的密码在下面

注意:我有4个SPI地址,我用它们创建实例

#!/usr/bin/env python
# -*- coding: utf8 -*-
import time
import sys
import os
import RPi.GPIO as GPIO
import MFRC522
import signal
from time import gmtime, strftime
from time import sleep
import requests
#import xml.etree.ElementTree as ET
#import xmltodict, json
from lxml import objectify
from bs4 import BeautifulSoup
continue_reading = True

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(37, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)

# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
    global continue_reading
    print "Ctrl+C captured, ending read."
    continue_reading = False
    GPIO.cleanup()

kullanici = "xxxx"
sifre = "xxxx"
birim = "xxxx"
ogrKEY = " "


def end_read(signal,frame):
    global continue_reading
    print "Ctrl+C captured, ending read."
    continue_reading = False
    GPIO.cleanup()


# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)

# Create an object of the class MFRC522
#
adresler = ["/dev/spidev0.0", "/dev/spidev0.1", "/dev/spidev1.0","/dev/spidev1.1"]

# Welcome message
print "Welcome to the MFRC522 data read example"
print "Press Ctrl-C to stop."
j = 0
# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:
    MIFAREReader = None
    pin = 0
    if j == 100:
       j = 0
    i = j % 4

    if i == 0:
    MIFAREReader =  MFRC522.MFRC522(adresler[0], 16)
        pin = 15
    elif i == 1:
    MIFAREReader =  MFRC522.MFRC522(adresler[1], 18)
        pin = 13
    elif i == 2:
        MIFAREReader = MFRC522.MFRC522(adresler[2], 33)
        pin = 7
    else:
        MIFAREReader = MFRC522.MFRC522(adresler[3], 31)
        pin = 37


    # Scan for cards 
    (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)

    # If a card is found
    if status == MIFAREReader.MI_OK:
       print "Card detected"

       # Get the UID of the card
       (status,uid) = MIFAREReader.MFRC522_Anticoll()

       # If we have the UID, continue
       if status == MIFAREReader.MI_OK:
              # print "su okuyucudan okundu" % i
           # Print UID
           print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])

           # This is the default key for authentication
           key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
           # Select the scanned tag
           MIFAREReader.MFRC522_SelectTag(uid)

           # Authenticate
           status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 10, key, uid)

           # Check if authenticated
           if status == MIFAREReader.MI_OK:
               MIFAREReader.MFRC522_Read(10)
           ogrKEY = MIFAREReader.returnOGR()
                   sonuc =  parser(ogrKEY)
                   if sonuc == True:
            openTurnsTile(pin)
                   else:
            sonuc = personelKontrol(ogrKey)
                        if sonuc == True:
                openTurnsTile(pin)
               MIFAREReader.MFRC522_StopCrypto1()
           else:
               print "Authentication error"
    j = j + 1

创建MFRC522对象时,它实际上调用
spi.openSPI()
,但从不关闭它。此python库适用于单个实例,但现在您正在处理打开FD的多个实例,因此也需要使用
spi.closeSPI()
,否则将出现错误“打开的FD太多”


检查PID的数量

没有closeSPI函数:(抱歉,我发现,closeSPI函数自然在spi库中,对此表示抱歉:)谢谢。如果这有帮助,请您放弃投票?谢谢:)