线程与SpiDev - IOError [Errno 9]:错误的文件描述符

时间:2015-06-23 18:14:16

标签: python multithreading spi ioerror

我已经创建了一个用于线程的函数,它不断地检查芯片寄存器中断,如果发生这个中断,它将从芯片中获取值,进行一些计算并将计算出的值放入一个链接到a的队列中使用tkinter创建的GUI。

def workerThread1(self):
    ##registers##
    AWATTHR = 0x01
    [...]

    ##variables##
    cAWATTHR = 2.365579 * 10 ** (-5)
    [...]

    ##register values##
    b1MMODE = 0xFC
    [...]

    ##set up SPI##
    spi = spidev.SpiDev()
    spi.open(0, 0)
    spi.mode=0b01

    ##write register values##
    spi.xfer2([WRITE|MMODE, b1MMODE], SPISPD, SPIDLY, SPILNG)
    [...]

    ##loop##
    spi.xfer2([WRITE|LINECYC, b1LINECYC, b2LINECYC], SPISPD, SPIDLY, SPILNG)
    spi.xfer2([RSTATUS], SPISPD, SPIDLY, SPILNG)
    while self.running == 1:
        n = n + 1
        rFREQ = spi.xfer2([FREQ, DBYTE, DBYTE], SPISPD, SPIDLY, SPILNG)
        vFREQ = Bits(uint = rFREQ[1]*VMSB16BIT + rFREQ[2], length = 16)
        sFREQ = sFREQ + vFREQ.uint
        LENERGY = [...]
        if LENERGY == '1':
            rvFREQ = (1 / ((sFREQ / n) * 9.6 * 10 ** (-6)))
            [...]
            transfer = [rvFREQ, [...]]
            self.queue.put(transfer)                
            n = 0
            sFREQ = 0
    spi.close()

不幸的是我总是得到“IOError:(Errno 9)错误的文件描述符”,带有以下回溯:

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 505, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/pi/GUI-LOG/GUI1.py", line 277, in workerThread1
rFREQ = spi.xfer2([FREQ, DBYTE, DBYTE], SPISPD, SPIDLY, SPILNG)
IOError: [Errno 9] Bad file descriptor

我期待着有关我在这里做错的任何提示。

0 个答案:

没有答案