psychopy.org | Reference | Downloads | Github

Sending triggers from psychopy to Brain vision triggerbox

Hello,

I want to do an EEG experiment with Psychopy and Brainvision software (through BrainVision Triggerbox). I know how to use Builder but I am pretty amateur in coding. Since I must use a serial port for sending triggers, I could not use the Builder. My planned experiment is to playing sounds as the stimulus and sending the time of the stimulus to the EEG recording system. For a test of sending triggers, I just created a simple version of the experiment like this:

I have found this code suggested:

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))

# Open the Windows device manager, search for the "TriggerBox VirtualSerial Port (COM6)"
# in "Ports /COM & LPT)" and enter the COM port number in the constructor.
port = serial.Serial("COM6")

# Start the read thread
thread = threading.Thread(target=ReadThread, args=(port,))
thread.start()

# Set the port to an initial state
port.write([0x00])
time.sleep(PulseWidth)

# Set Bit 0, Pin 2 of the Output(to Amp) connector
port.write([0x01])
time.sleep(PulseWidth)

# Reset Bit 0, Pin 2 of the Output(to Amp) connector
port.write([0x00])
time.sleep(PulseWidth)

# Reset the port to its default state
port.write([0xFF])
time.sleep(PulseWidth)

# Terminate the read thread
Connected = False
thread.join(1.0)

# Close the serial port
port.close()

But to be honest, I could not find in which section I should use it.
I would be happy if someone helps me.