How to set up sync with fMRI using parallel port

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win7
PsychoPy version (e.g. 1.84.x): 2020.1.3
Standard Standalone? (y/n) If not then what?: y
**What are you trying to achieve?:
I am try to set up a fMRI experiment using psychopy. However I cannot work out how to get triggers send from the scanner (a Phlips Achieva 3T).
There is no hardware damage - I can read triggers successfully using E-Prime. And when I set the readPin to port.readPin(12), which is always up, I keep got ones.
What did you try to make it work?:
I have installed parallel port drivers (inpout32.dll) in both the programe folder and System32. And, I have set up a Routine Named “PPconfig” at the beginning of the experiemt. In this routine, I used the following codes:
Begin Experiement:
from psychopy import parallel
port = parallel.ParallelPort(0xC100)
pinvalue = 0
triggertime = 0

Each Frame:
pinvalue = port.readPin(10) #read pin 12 or 10
if pinvalue != 0:
triggertime = core.getTime()
logging.exp(‘trigger recived: start of scan’)
continueRoutine = False
I also have a text component said “waiting for trigger…” in this routine, which suppose to present till trigger was recived.

It seems that someone get it wordked used while True: loop, I have also tried it in my set up, as follows:
Begin Experiement:
from psychopy import parallel
port = parallel.ParallelPort(0xC100)
pinvalue = 0
triggertime = 0

Begin Routine:
while True:
if port.readPin(10) != 0:
break
logging.exp(‘trigger recived: start of scan’)
continueRoutine = False
The programe got stucked. Then I learned that while loop cannot work with builder view from Ending loop conditionnally. While loop?. So I turned to each frame.

**What specifically went wrong when you tried that?:
When I am reading Pin 10, using “pinvalue = port.readPin(10)” the programe stucked at the waiting screen, seems it get nothing from the parallel port. Though I have tried every input pins I can recognize, I am not sure if I have read the wrong Pin or I have missed something in my code. Also, as I am not familar with how the trigger works, I am not sure in the case of getting trigger from scanner do I just use readPin or do I have to send something to the scanner first? And is there anyway I could read more pins? Actually, is there an example for getting triggers from fMRI?
I am very lost on how to fix this. Does anyone have any advice?

Include pasted full error message if possible. “That didn’t work” is not enough information.

Do you have any other programs to interface with this hardware? It may be that there’s a problem with the cable / port / fMRI which means it genuinely isn’t giving a response, is there maybe some software which comes with it you could test it with?

I think the OP indicated that pin 12 gave 1 as expected, but the issue was just with pin 10?

If unsure, make a separate test file with a number of text stimuli. In each one, put something like:

$port.readPin(12) 

and

$port.readPin(10) 

etc on each stimulus, with each one set to update on very frame.

This will eliminate any issues with your code logic: the only code you’ll need is to create the port at the start of the experiment.

As Todd suggests, is the port number (0xC100) the same as you successfully use with E-Prime?

Thank you for reply @TParsons @Michael. Just to clarify, so my code looks fine, right?
I have double checked. The I/O range of parallel port is C100-C103, hence the address should be 0xC100.
I recently notice that, e.g. in MRI experiment: start routine by MRI pulse from parallel port, they also configured the parallel port address in the settings, which I haven’t done. Should that be the problem?

1 Like

any update on how to solve this? I am also programming a stim to use in MR but have not found any information on how to wait for the syncbox trigger.