Reputation: 41
I am using Psychopy v1.82.01 (coder view) on a Windows 7 computer to run an fMRI experiment. I would like to readData() from the parallel port (for recording button presses and for receiving the trigger from the scanner to sync). However, when I use readData() or readPin() all pins seem to remain low ('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. 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! 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). The setData() functions work fine, I'm only having difficulty reading the data.
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? Is this feasible?
Any ideas on where to start fixing this would be greatly appreciated!!
Upvotes: 3
Views: 533
Reputation: 41
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. 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):
self.port.Out32(self.base + 2, 32)
Have possibly caused more unforeseen problems, but for now this seems to work!
Upvotes: 1