Search code examples
pythonpsychopyparallel-port

How to send data through parallel port in Python?


I need to send some data via parallel port using Python. And for this I am using psychopy.parallel module.

I have two Windows 7 x64 machines connected via parallel port. This connection is tested and working because it is used by another software to send data via LPT1 port.

I have installed the necessary libraries for psychopy.parallel as described here.

Here is my naive intuition:

Machine 1 (Sending data):

from psychopy import parallel
port = parallel.ParallelPort(address="0xC010")
port.setData(3) # sets just pin 2, 3 high

Checking on Machine 1

port.readData()
> 3

Checking on Machine 2 (Receiving data):

from psychopy import prallel
port = parallel.ParallelPort(address="0xEC00")
port.readData()
> 0 

I see that although I can set the pins correctly on Machine 1 and read the result, Machine 2 just gives me a 0.

  • How to send and receive a signal via parallel port correctly?

Solution

  • There are a few options:

    • Maybe you haven't got the right driver for pyparallel/psychopy to talk to. You'll need a 32bit parallel port driver if you're using the Standalone PsychoPy (which includes 32bit python). The answer in the link below tells you how to download another test utility that will insert the correct version of both 32bit and 64bit drivers, which you need to do on both machines obviously
    • your script sending the pules will finish immediately and conceivably the pins are all being set back to low when the script ends? (I think this isn't usually the case but worth checking)
    • have you set the right address for the parallel port? Your code currently uses the default address but there are various options.
    • Lastly, the link below tells you how to do it using inpout32.dll directly but I think the drivers are the first thing to get fixed

    PsychoPy sending triggers on 64bit OS