Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

problem with sending and receiving triggers

edited May 2017 in OpenSesame

Hey,

I have a problem with sending (to EEG) and receiving (from a button box) triggers. In the past I have been able to do this without problems, but I recently switched to a new lab and it seems I cannot get it to work here.

For example, to sent EEG triggers I am using the following code:

############################
### initiate EEG trigger ###
############################

try:
    from ctypes import windll
    global io
    io = windll.dlportio # requires dlportio.dll !!!
except:
    print 'The parallel port couldn\'t be opened’

And then later in my inline script:

Global io
trigger = 10
port_eeg = 41152
try:
    io.DlPortWritePortUchar(port_eeg, 1)    
    exp.sleep(10)
    io.DlPortWritePortUchar(port_eeg, 0)
except:
    print ‘Failed to send trigger’

However, this doesn't work as I get the message Failed to send trigger.
To obtain the portcode I have used the device manager and changed the heximal port code (A0C0) to decimal code (41152), as I previously also used decimal codes.

Does anyone have any tips what I might be doing wrong here and how I can fix it.

Cheers and thanks in advance,

Dirk

Comments

  • Hi Dirk

    The issue could be the port address, a possible reason is when the dll was written the address was meant an signed integer (32bit), so you may want to convert it. I think it should be -8384.https://stackoverflow.com/questions/16452232/how-to-convert-signed-32-bit-int-to-unsigned-32-bit-int-in-python

    Or try use the dll here psy.swan.ac.uk/staff/freegard/parallel_port/

    Good luck

    Gary

  • Hey Gary,

    Thanks for your quick reply. Not sure what you mean with -8384. When I follow the instructions on the stack overflow link 41152 stays 41152? Am I missing something here?

    Cheers,

    Dirk

  • Whoops you are right, should have tried it before I posted.

    The difference between signed and unsigned is that in binary the left hand digit indicates its sign, 0 is positive, 1 is negative and for unsigned it is a value. Plus I also forgot that the number is twos complement.

    And have just noticed it uint32 and int32 change these to uint16 and int16

    Two method shown below
    `import ctypes

    def uint16_to_int16(i):
    return ctypes.c_int16(i).value

    print uint16_to_int16(41152)
    import numpy
    print numpy.int16( numpy.uint16(41152) )`

    The number is -24384

    Hope this helps

    Gary

  • Thanks, I used an online calculator and ended up with the same number. Unfortunately that did not do the trick.

    Any other suggestions?

    Btw others here are using Matlab and Presentation software to send triggers and works fine :(

  • Hi

    Have you tried the dll on the other link?

    Gary

  • No I did not do that yet. I was a bit hesitant to download new software on a computer that others are successfully using for EEG. Could that be a potential problem?

  • No, just another dll, it can be placed in any folder on the PC as long as you use the loadlibrary with the path plus it doesn't net to be registered . I use it for all experiments that require event marking.

    It didnt work on one PC, but didn't have time to work out why, so had to create a USB device to do the job.

  • Yes, thank you very much Gary. That second link did the trick. You saved me a lot of frustration!!

  • Created the modified dll due to my frustration, glad it saved you from some :)

Sign In or Register to comment.