psychopy.org | Reference | Downloads | Github

Trail specific trigger

Hi,

I try to implement a code sending a trigger at the end of each trial via a serial port
(the experiment is build in Psychopy 1.83 , a stand allone version on a windows machine).
Sending a hard coded trigger is no problem by using the following code:

serial_port = serial.Serial(‘COM2’, baudrate=115200, bytesize=serial.EIGHTBITS)

serial_port.write(‘a’) # Send the byte a as a character

serial_port.close()

The code is implemented in a trial loop, it sends the trigger at the end of each trial, that works very well.
But I want to send different trigger information depending on the specific condition of each trial. The trial loop is accosiated with an exel table called table1 including a variable trigger_info. I’m wondering in which way I could refer to this variable so that the code above uses the information from this variable as trigger code. Using $trigger_info does not work, it seems to be more complicated. Could anybody add an example for the correct reference? Thanks in advance.

Begin experiment tab:

serial_port = serial.Serial(‘COM2’, baudrate=115200, bytesize=serial.EIGHTBITS)

End routine tab:

serial_port.write(trigger_info)

End experiment tab:

serial_port.close()