The number of responses in the task data does not match the number of triggers in the EEG data

I used the code component to create triggers for stimuli and responses in the task. However, when I checked the EEG data with EEG analysis software, the number of responses in the task data does not match the number of triggers in the EEG data. It seems that some triggers are missing that should be included. The task itself is running correctly. Is there any solution to this problem?

Please could you show your relevant code?

Is there any consistency with which triggers are missing responses?

The code for the code component is as follows.

#Begin Experiment
import serial
import time

PulseWidth = 0.01

port = serial.Serial("COM3", baudrate = 9600)
port.write([0x0])
#Response
sp10 = [0xa] 
sp99 = [0x63]
#Stimuli
##The following is the code for triggering the stimulus, but I will omit it because I want to keep the task contents confidential.

respflag = 0

#Begin Routine
respflag = 0
port.write([0x0])
time.sleep(PulseWidth)
##The following is the code for triggering the stimulus, but I will omit it because I want to keep the task contents confidential.

#Each Frame
if key_offer.keys != [] and key_offer.corr == 1:
    port.write(sp10)
    respflag = 1
elif key_offer.keys != [] and key_offer.corr == 0:
    port.write(sp99)
    respflag = 1

#End Routine
respflag = 0
port.write([0x0])
time.sleep(PulseWidth)

#End Experiment
port.close()

Regarding the task, it responds to stimuli with a choice of sp10 or sp99. Trigger dropout is not consistent. Different routines proceed according to sp10 and sp99 responses. The sp10 is followed by another routine stimulus that requires a response to another stimuli, but the trigger for that response is also dropped. However, I think that I want to try to solve firstly sp10 and sp99 dropout to tackle the next problem.