How to set the stop data of p_port to zero and the duration in code component

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): 2020.2.10
Standard Standalone? (y/n) If not then what?:y
**What are you trying to achieve?: I want to set response triggers when subjects press a button, and make this response trigger’s stop data set to zero after 25ms.

**What did you try to make it work?:

if len(key_resp_o1.keys) > 0:
    if int(key_resp_o1.keys[0]) == int(cur_corans_o1):
        p_port_enc1.setData(201) 
    else: 
        p_port_enc1.setData(202)
else:
    p_port_enc1.setData(255)

image


**What specifically went wrong when you tried that?:
I don’t know how to set the stop value and duration of this port component in the code component.
so when I was collecting the MEG data, this response trigger wouldn’t go back to zero and would overlap with other triggers.

Any thoughts/comments/advices would be veeeery appreciated!

Many thanks! :heartpulse: :sparkling_heart:

I read other guys’ issue and was inspired to come up with the solution:
at the “end routine” tab in my code component, I wrote the following code:

# enc1
if len(key_resp_o1.keys) > 0:
    if int(key_resp_o1.keys[0]) == int(cur_corans_o1):
        p_port_enc1.setData(218)
    else: 
        p_port_enc1.setData(219)
else:
    p_port_enc1.setData(255)

core.wait(0.05)
p_port_enc1.setData(0)



Is this code right if I want to make the trigger index go back to 0 after 50ms?
Please help me out of this :cry: :sob:, thanks a lot :sparkling_heart: