psychopy.org | Reference | Downloads | Github

Trying to connect MRI scanner using serial port

Dear PsychoPy experts,

We are trying to code an fMRI based experiment.
Our code works perfectly on our computers, but when we try to move it to the scanner, we cannot get the code to communicate with our fMRI stimulus delivery console, made by MRA (model: fMRI-0502-STD1).

We try to connect it through the serial port, using the serial port example in the psychopy website, adapted to our own ports.

import serial
ser = serial.Serial(2, 19200, timeout=1) # open first serial port
#ser = serial.Serial(’/dev/ttyS1’, 19200, timeout=1)#or something like this for Mac/Linux machines
ser.write(‘someCommand’)
line = ser.readline() # read a ‘\n’ terminated line
ser.close()

when we run this script we get the following error.

######### Running: C:\Users\stim_1\Desktop\Pessoa\JUV_exp\coms_test.py #########
Traceback (most recent call last):
File “C:\Users\stim_1\Desktop\Pessoa\JUV_exp\coms_test.py”, line 3, in
ser = serial.Serial(2, 19200, timeout=1) # open first serial port
File “C:\Users\stim_1\AppData\Local\PsychoPy3\lib\site-packages\serial\serialwin32.py”, line 31, in init
super(Serial, self).init(*args, **kwargs)
File “C:\Users\stim_1\AppData\Local\PsychoPy3\lib\site-packages\serial\serialutil.py”, line 218, in init
self.port = port
File “C:\Users\stim_1\AppData\Local\PsychoPy3\lib\site-packages\serial\serialutil.py”, line 264, in port
raise ValueError(’“port” must be None or a string, not {}’.format(type(port)))
ValueError: “port” must be None or a string, not <class ‘int’>

We tried using the launchscan() function, but we can’t get that to communicate with our console too.

Thank you