Specifying when to send trigger (brainproducts)

Hi,
I’m trying to set up my EEG experiment and have a problem with sending the triggers. My design is RSVP (rapid serial visual presentation) in which I’m presenting one word at the time. I would like to send the trigger when W4 appears.

Here’s what my trials look like:

I’m using the following code:

#Begin experiment:
import serial
port = serial.Serial(‘COM3’)
port.write([0x00])

#begin routine:
pulse_started = False
pulse_ended = False

#each frame:
if W4 == True and not pulse_started:
port.write([0x01])
pulse_start_time = globalClock.getTime()
pulse_started = True
if pulse_started and not pulse_ended:
if globalClock.getTime() - pulse_start_time ==0.01:
port.write([0x00])
pulse_ended = True

Right now, no triggers are sent at all, so something is off. I’d be very grateful if someone could help me!

Ok, so I found the problem, I just had to add .status after W4.
But my new issue now is that the trigger is only sent for the first trial! Any tips on how to get it to keep sending for each?

Again, very grateful for any help!

Update in case anyone googles their way here:
I finally got it to work using a different code, the one suggested by Becca here:
Sending triggers to brain vision trigger box - Builder - PsychoPy