Sending sequential EEG triggers leads to a random value being sent, not the intended value

OS: Windows 10.
PC: I7 7700, GTX1060, 16gbs ram; 100Hz Monitor
EEG acquisition system: Biosemi Actiview 2
EEG Triggerbox: Neurospec MBBT-S operating in simple mode.

Hi all, I am having some issues sequentially sending triggers to my Biosemi Actiview 2. As shown by the code below, in a routine that precedes each trial, I am trying to send three triggers to mark the upcoming condition. With this code, triggers either won’t be sent and a random value (207 or 255) will appear in the recording.

The only way I have been able to get the trigger values I want displayed correctly on the actiview, is by adding this code (core.wait(0.01)) after reseting the triggerbox to zero, effectively delaying the next trigger by 10ms.

Can anyone please explain why my code does not allow me to sequentially send triggers without using core.wait()? Is there a better way to sequentially send triggers?

Thanks! :slight_smile:

This code is run in the each frame tab of a code component:

## Send triggers
if Filename == Prac_FileName: 
    if not PracTrig_pulse_started:
        #win.callOnFlip(mbbts.write, (210).to_bytes(1, 'little')) # Write trigger for practice trial
        mbbts.write((210).to_bytes(1, 'little'))
        Prac_Trial_StartTime = globalClock.getTime()
        PracTrig_pulse_started = True
    if PracTrig_pulse_started and not PracTrig_pulse_Ended:
        if globalClock.getTime() - Prac_Trial_StartTime >= Trigger_Duration:
           # mbbts.write((0).to_bytes(1, 'little')) # Reset trigger to zero
           mbbts.write(b'\x00') # Don't wait for flip
           PracTrig_pulse_Ended = True
           core.wait(0.01) # Code I have to add to get it to work

else: # On live trials send these triggers to mark the conditions
    if not TargTrial_pulse_Started:
        mbbts.write((252).to_bytes(1, 'little'))
        #win.callOnFlip(mbbts.write, (252).to_bytes(1, 'little'))
        Targ_Trial_StartTime = globalClock.getTime()
        TargTrial_pulse_Started = True
    if TargTrial_pulse_Started and not TargTrial_pulse_Ended:
        if globalClock.getTime() - Targ_Trial_StartTime >= Trigger_Duration:
            #mbbts.write((0).to_bytes(1, 'little'))
            mbbts.write(b'\x00') # Don't wait for flip
            TargTrial_pulse_Ended = True
    # Send each trigger sequentially, so after the previous one is sent, send this
    if TargTrial_pulse_Ended and not InducerDur_pulse_Started:
        # Send a trigger for inducer duration:
        for ms in Inducer_Durations_List:
            if Inducer_Duration_MS == ms:
                mbbts.write(int(Inducer_Triggers[str(ms)]).to_bytes(1, 'little'))
                #win.callOnFlip(mbbts.write, int(Inducer_Triggers[str(ms)]).to_bytes(1, 'little'))
                InducerDur_StartTime = globalClock.getTime()
                InducerDur_pulse_Started = True

    # Reset the triggerbox to zero
    if InducerDur_pulse_Started and not Inducer_Dur_pulse_Ended:
        if globalClock.getTime() - InducerDur_StartTime >= Trigger_Duration:
            #mbbts.write((0).to_bytes(1, 'little'))
            mbbts.write(b'\x00') # Don't wait for flip
            Inducer_Dur_pulse_Ended = True
    if Inducer_Dur_pulse_Ended and not BorderEdge_pulse_Started:
        if Border_Edge == 'WB':
            #win.callOnFlip(mbbts.write, (198).to_bytes(1, 'little'))
            mbbts.write((198).to_bytes(1, 'little'))
        elif Border_Edge == 'BW':
            mbbts.write((199).to_bytes(1, 'little'))
            #win.callOnFlip(mbbts.write, (199).to_bytes(1, 'little'))
        BorderEdge_StartTime = globalClock.getTime() 
        BorderEdge_pulse_Started = True

    # Reset the triggerbox to zero
    if BorderEdge_pulse_Started and not BorderEdge_pulse_Ended:
        if globalClock.getTime() - BorderEdge_StartTime >= Trigger_Duration:
           mbbts.write(b'\x00') # Don't wait for flip
           # mbbts.write((0).to_bytes(1, 'little'))
           BorderEdge_pulse_Ended = False
           core.wait(0.01) # Code I added to work

Could this be related to your issue

I had a random triggers issue myself in the past (not using Psychopy) and the above helped