简体   繁体   English

PsychoPy:无法从并行端口读取数据

[英]PsychoPy: unable to read data from parallel port

I am using Psychopy v1.82.01 (coder view) on a Windows 7 computer to run an fMRI experiment. 我在Windows 7计算机上使用Psychopy v1.82.01(编码器视图)来运行fMRI实验。 I would like to readData() from the parallel port (for recording button presses and for receiving the trigger from the scanner to sync). 我想从并行端口读取data()(用于记录按钮按下以及从扫描器接收触发器以进行同步)。 However, when I use readData() or readPin() all pins seem to remain low ('0'). 但是,当我使用readData()或readPin()时,所有引脚似乎都保持低电平('0')。

For a sanity check I have tried reading the data from the port in Presentation (to check the devices are working/correct address/etc) and this recognizes the button presses. 为了进行健全性检查,我尝试从Presentation中的端口读取数据(检查设备是否工作/正确的地址/等),这可以识别按下按钮。 Oddly, if I am in the PsychoPy shell (using readData() and readPin()) and Presentation is open, with the 'port test' window open, then it does work! 奇怪的是,如果我在PsychoPy shell(使用readData()和readPin())并且Presentation已打开,并打开'port test'窗口,那么它确实有效! Also, If I send data to the port from Presentation then I can read this in PsychoPy (so I'm fairly confident my code is fine). 此外,如果我从Presentation发送数据到端口,那么我可以在PsychoPy中读到这个(所以我相当自信我的代码很好)。 The setData() functions work fine, I'm only having difficulty reading the data. setData()函数运行正常,我只是难以读取数据。

The code I am using is: 我使用的代码是:

from psychopy import parallel
button = parallel.ParallelPort(0x2010)

while True:
    if button.readPin(5) !=0:
        break

print 'value received'

I am not super confident with parallel ports, or the 'behind the scenes' working of the parallel functions, but it seems to be that there is some sort of access issue with reading the port, that is overridden when Presentation is accessing the port, but the functions I am using from PsychoPy can't manage on their own? 我对并行端口或并行功能的“幕后”工作并不十分自信,但似乎存在读取端口的某种访问问题,当Presentation访问端口时会被覆盖,但我从PsychoPy使用的功能无法自行管理? Is this feasible? 这可行吗?

Any ideas on where to start fixing this would be greatly appreciated!! 任何想法从哪里开始修复这将是非常感谢!!

Finally got it working! 终于搞定了! In case anyone else has similar problems, in the _inpout32.py file (/parallel/_inpout32.py) in the function ' init ' there is a command to switch to zero bit 5 of the control register. 如果其他人有类似的问题,在函数' init '的_inpout32.py文件(/parallel/_inpout32.py)中有一个命令切换到控制寄存器的第5位。 I copied this command and also included it in the setData() function and then in readData() I changed this so bit 5 is high (input arguments are the base address + 2, and 32): 我复制了这个命令,并将它包含在setData()函数中,然后在readData()中我改变了这一点,因此第5位为高(输入参数是基地址+ 2和32):

self.port.Out32(self.base + 2, 32)

Have possibly caused more unforeseen problems, but for now this seems to work! 可能引起了更多不可预见的问题,但是现在这似乎有用了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM