Hi @Ange
For the first problem, @Becca suggested this solution in another topic: Sending multiple triggers in one routine using serial port - #4 by Becca
I stopped receiving errors afterwards however, the triggers were not shown regardless. You could try simply using port.write (without a win.callOnFlip() function). That worked for me. But it is said that this may lead to less preceise timing so timing verification with a phototide etc might be considered here.
For the second problem, I realized I did not reset the port back to 0 and when I did that, the problem was solved:
if pulse_started and not pulse_ended:
if globalClock.getTime() - pulse_start_time >= 0.005:
port.write[0x00] # !
pulse_ended = True