Trigger generation issue

Dear Community,

Info:
Psychtoolbox-3 (3.0.19)
MATLAB platform (2021b)
ubuntu (22.04)

I have a very broad question. I am running my experiment and pass the triggers on EEG. However, sometimes random triggers are missing, around 50 out of 2000+. I was not able to figure any pattern in the way they fail to being recorded. They are triggers with different codes too, which are present on most cases, but then accidentally drop out. This issue is pretty annoying, since it takes time to recover them and I still loose some of my trials.

Here is the port setup code snippet:

% Set up serial port 
portParams = 'BaudRate=115200 DTR=1 Terminator=10';
com = '/dev/ttyACM0'; %COM port for serial connection
SerPort = IOPort('OpenSerialPort', com, portParams);    % Get handle for serial port

Here’s how I pass the triggers:
IOPort('Write', SerPort, ['WRITE 13 1000 0' char(10)]);

I am now trying to figure out what causes this problem: PTB, trigger port or the EEG recording software (eego, ANT). Are there any reasons the triggers may accidentally not be going through due to the PTB settings?

I will be grateful for any piece of advice!
Please let me know if you need further details.

Best,
Kat