# Trying to connect MRI scanner using serial port

**URL:** <https://discourse.psychopy.org/t/trying-to-connect-mri-scanner-using-serial-port/11398>\
**Category:** Coding\
**Created:** [March 9, 2020, 5:38pm UTC](https://discourse.psychopy.org/t/trying-to-connect-mri-scanner-using-serial-port/11398 "2020-03-09T17:38:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![navotnaor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/navotnaor/32/6660_2.png) [@navotnaor](https://discourse.psychopy.org/u/navotnaor)\
**Post date:** [March 9, 2020, 5:38pm UTC](https://discourse.psychopy.org/t/trying-to-connect-mri-scanner-using-serial-port/11398/1 "2020-03-09T17:38:59Z")

</div>

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
