send trigger via virtual serial port using an adapter/trigger box for parallel port
Dear folks,
i must admit that i am a complete noob in sending triggers. 😗
I have put an adapter to my parallel port. This makes it possible to connect it with any computer via USB. This adapter makes the system believe it is connected via serial port 'COM6' ;)
I used an old script from 2014 which was written by Edwin and tried to adapt it with the modern python codes/OS version. Well, of course this did not work. I am not sure whether i was close or whether i missed something. I did not receive any error messages, but i did not see any triggers in the BrainVision Recorder neither. In other posts it was mentioned that triggers are only send if they changed. So i tried to send 3 triggers. I also tried to implement what i found here. This is my code:
# we will need to import the 'serial' module,
# which allows us to send and receive
# information via the serial port
import serial
#checkout which ports are available
#serial.tools.list_ports #does not work this way
# next, we will need to start a connection to
# the serial port
#var.trigger = serial.Serial('COM3')
trigger = serial.Serial()
trigger.port = 'COM6'
trigger.open()
trigger.write(0)
trigger.read()
# finally, we want to make sure that the
# connection to the serial port will be stopped
# when the experiment is aborted or finished
var.cleanup_functions.append(trigger.close)
# this sends a trigger with value 0
# if you require a different value, please
# use a number between 0 and 255
trigger.is_open
trigger.write(0)
trigger.readline()
#send stim with picture
keepQuiet=canvas()
path = pool['keepQuiet.tif']
keepQuiet.image(path)
keepQuiet.show()
#send trigger to other computer
trigger.write(1)
trigger.readline()
#get response
enter = keyboard(keylist = ['RETURN'])
key, time=enter.get_key()
#send response trigger
mber between 0 and 255
trigger.write(255)
trigger.readline()
Comments
Further i found python codes from BrainVision. However, i do not know what to do with it:
import serial import time import threading Connected = True PulseWidth = 0.01 def ReadThread(port): while Connected: if port.inWaiting() > 0: print '0x%X' %ord(port.read(1)) port = serial.Serial('COM6') thread = threading.Thread(target=ReadThread, args=(port,)) thread.start() port.write([0x00]) time.sleep(PulseWidth) port.write([0x01]) time.sleep(PulseWidth) port.write([0x00]) time.sleep(PulseWidth) port.write([0xFF]) time.sleep(PulseWidth) Connected = False thread.join(1.0) port.close()It runs without error messages and gives my some debug output:
Any suggestions, how i can get and see the triggers in the Recorder? It works fine for a colleague who uses presentation. So the hardware is correctly connected. ;)
after 2 weeks of intensive trying:
i had to install the drivers for the parallel port adapter from neurospec. 🤣
With the correct driver, the neurospec adapter, BrainVision Recorder, BrainVision ActiChamp and OpenSesame 3.2.8 it works! 🤗
This is my final code which did send triggers.
test_stim=canvas() test_stim.text('test stim') test_stim.show() clock.sleep(1000) try: import serial exp.port= serial.Serial('COM8') print 'serial port read', exp.port.baudrate, exp.port.bytesize, exp.port.parity except: print 'serial port not read' try: exp.port.write(chr(0)) print 'trigger has been sent' clock.sleep(50) except: print 'trigger not sent' exp.port.write(chr(1)) self.sleep(200) exp.port.write(chr(9)) exp.port.close()