python将某些数据读取两次设备fi

2024-10-04 11:31:06 发布

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

我在zedboard上运行xillinux(或多或少是ubuntu12.04)。Zedboard结合了arm和fpga。在

现在编写了一个python脚本,它从设备驱动程序(/dev/xillybus_read_32)读取数据。在

现在我知道我接收到的数据是完整和正确的(我使用了一个预先编写的程序,将所有的数据存储在一个转储文件中,我将这个转储文件拆分成帧,并检查内容是否正确(每个帧都包含一个加法,因此很容易检查)。在

现在,当我尝试使用以下python脚本从设备驱动程序接收数据时:

#Read data
#Framesize
CONST_FRAMESIZE = (640*480*16)/8
#Info
frame_true = 0
frame_false = 0
#Open file
pipe_in = open("/dev/xillybus_read_32","r")
count = 0
count_false = 0
for z in xrange(1000):
        frame = "frame" + str(count) + ".raw"
        pipe_out = open(frame,"wb")
        for r in xrange(CONST_FRAMESIZE/4):
                value = pipe_in.read(4)
                pipe_out.write(value)

        pipe_out.close()

        #Compare goldendata with frame
        if filecmp.cmp("goldendata",frame):
                frame_true = frame_true + 1
                if count >= 1:
                        os.remove(frame_last)
                frame_last = frame
        else:
                print "frame_true:", frame_true
                pipe_in.close()
                sys.exit()
                #frame_false = frame_false + 1
                #os.remove(frame)
        count = count + 1;

#Close opend file
pipe_in.close()

我接收所有的数据,但有时我会得到我的32位字2次。就像它有时会把32位的单词读两遍。我不丢失数据,它只是读取32位,有时2次。很奇怪。在

Thnx公司


Tags: 文件数据indev脚本falsetrueclose