psychopy.org | Reference | Downloads | Github

Troubles setting the parallel port to send triggers


#1

Hello,

I have difficulties to send a message on the parallel port using PsychoPy in a python script (not using the standalone)
I tried multiple times and on multiple computers (Ubuntu 16.04, Windows 10, Linux Mint 18.3), and I always end up with the same error message :

$ python2 send_triggers.py
fatal: Not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
  File "send_triggers.py", line 23, in <module>
    parallel.setData(0)
  File "/usr/lib/python2.7/dist-packages/psychopy/parallel/__init__.py", line 161, in setData
    raise RuntimeError('Port address must be set using setPortAddress')
RuntimeError: Port address must be set using setPortAddress

Here is the code that triggered the error message :

from pynput import keyboard
import time
from psychopy import parallel


keys_to_listen = ('z', 'x', ',', '.') #definition of variables irrelevant to the current bug

markers_press = (1, 2, 3, 4)
markers_release = (10, 20, 30, 40)
is_pressed = [False, False, False, False]



####set parallel port
parallel.setPortAddress(address=0x0378)
parallel.setData(0)
time.sleep(2)

I found this similar topic on the forum but the trick (putting inpout32.dll in the same directory as the script) didn’t work (even on Windows 10): Cannot send a signal via ParallelPort using PsychoPy on Windows7 (64bit)

One thing to note is that I am currently testing this script on computers that doesn’t have any parallel ports. However, when I went to try the script on the stimulation computer (which has a parallel port) I had the same error message.

Another (maybe) useful thing to note is that when I installed PsychoPy I had an error message saying that pyobjc-core and iolabs failed to install properly. Pyobjc-core says it requires macOS to be installed, so it’s likely not a problem, but I am suspicious about iolabs.

Do someone have an idea about what is going wrong ? I’m starting to feel like I am the mistake since I can’t make it work on any computer :sweat_smile:

Thanks !


#2

The setPortAddress will fail to set the port address if it encounters an error - but it will only emit a warning. You will then run into the error when trying to use setData.

You will need to work out why setPortAddress isn’t working. The warning message that is emitted should be helpful.

You will know if it has worked if parallel.PORT is not None after calling setPortAddress.


#3

Thanks for your help !
I don’t see any warning when running setPortAddress, so I don’t know where to start to work it out… I tried calling parallel.PORT right after setPortAddress and it doesn’t output anything (I was expecting to see at least ‘None’ being returned, but nope).

Also, I got my hand on a parallel port card, so I am installing it and I’ll see if actually having a parallel port solves the problem.


#4

How are you running the code? If it is in an interactive window, you might not see the warning until it is closed (I don’t).

Mine looks something like:

15.4165 	WARNING 	Could not initiate port: [Errno 2] No such file or directory: '/dev/parport0'

Yes, same for me - unless I use print parallel.PORT.

Yes, you will need a parallel port to be available for your code to complete without error.


#5

I am running the code using either Spyder or the Windows/Linux terminal. What should I use in order to see the warning message and confirm that I have the same than you ?
I called print parallel.PORT and it actually returned None. So I guess the setPortAddress call is not working, as you suggested ?

I installed the parallel port card on my computer but I have nothing to plug it to (the EEG amplifier I will use for recordings is not easily accessible, I’d like to make sure I have something that theoretically works before trying it out).

Do you have any idea of what I could try next to debug the setPortAddress function ?


#6

I think if you do something like the following then you should see the message:

import psychopy.parallel
import psychopy.logging

psychopy.parallel.setPortAddress()
psychopy.logging.flush()

You could try typing the above into an ipython session also.


#7

On the first try, I had the following warning :

In [1]: import psychopy.parallel
   ...: import psychopy.logging
   ...:
   ...: psychopy.parallel.setPortAddress()
   ...: psychopy.logging.flush()
   ...:
0.3595  WARNING         psychopy.parallel has been imported but no parallel port
 driver found. Install either inpout32 or dlportio
0.3598  WARNING         Could not initiate port: global name 'ParallelPort' is not defined

So I installed the InpOut32 and InpOutx64 drivers using the installer from : http://www.highrez.co.uk/downloads/inpout32/
I also did put both .dll files in the same folder as my Python script. Now I have only the second warning :

In [2]: import psychopy.parallel
   ...: import psychopy.logging
   ...:
   ...: psychopy.parallel.setPortAddress()
   ...: psychopy.logging.flush()
   ...:
99.4235         WARNING         Could not initiate port: global name 'ParallelPort' is not defined

If it’s not a driver problem (since I made the first warning disappear by installing them), then what could it be ?


#8

Try restarting your interactive session and running the code again.


#9

Check the documentation at http://www.psychopy.org/api/parallel.html

You are using the legacy functions, trying to directly set properties of the library itself. As per the documentation above:

We would strongly recommend you use the class above instead: these [functions] are provided for backwards compatibility only.

i.e. create a parallel port instance, and set the the properties of that, as shown in this example from that documentation:

from psychopy import parallel
port = parallel.ParallelPort(address = 0x0378)
port.setData(4)
port.readPin(2)
port.setPin(2, 1)
# etc

Can't connect to Parallel Port
#10

That’s weird because when I restart the iPython session I got both warnings back, as if the driver previously installed was uninstalled. I have to run the setup again while keeping the iPython session open in order to make the first warning disappear.

I tried sending messages on the parallel port using Matlab and PsychToolbox and it seem to work fine… To do this, I just had to put InpOutx64.dll in the System32 folder. Now I got InpOut32.dll and InpOutx64.dll in both System32 and SysWOW64, but it still doesn’t work in PsychoPy.


#11

I keep having this error message when using the ParallelPort function, according to other posts on the forum it also seem to be linked to driver issues, but playing with InpOut32.dll and InpOutx64.dll didn’t do the trick for me :frowning:

In [1]: from psychopy import parallel 
In [2]: port = parallel.ParallelPort(address = 0x0378) 
--------------------------------------------------------------------------- 
AttributeError Traceback (most recent call last) 
<ipython-input-2-4b7c314e7240> in <module>() 
----> 1 port = parallel.ParallelPort(address = 0x0378)
 AttributeError: 'module' object has no attribute 'ParallelPort'

Edit : I tried testing my parallel port using http://www.xlentelectronics.nl/LPTTest/LPTTestUtilx64r.htm
However, this soft doesn’t detect any LPT (it should be LPT1, as I set it in the Device Manager).


#12

Hello Hyruuk,

I’m currently also trying to get the parallel port to work on a Windows 10 computer and am having similar issues. Were you able to resolve this?

Thank you!