| Reference | Downloads | Github

Triggering from Serial port

Dear PhycopPy developers,
I need to adapt a script to trigger from a Serial Port. Could you provide a demo or some test script so I can understand the syntax and how the trigger data is retrieved?
Thank you very much in advance.
Best wishes,


General purpose communication with serial devices using Python is usually done with the PySerial library.

Something like this will write a byte to the port and read the response.

import serial

def main():
    # open the port
    port = serial.Serial("COM1", 9600)


    while not port.inWaiting():

    return 0

if __name__ == "__main__":

Dear mdc,

Thank you for the response. I have trial-ed this out on our scanner (also changed the port to COM3 which is the active port) and unfortunately I didn’t get any print of an ‘a’. I was then made aware that I should be using the serial port option anyway.

In alternative we have a National Instruments Card that is connected to the stimulus computer. I have also installed the drivers for this ( but how can I now communicate with my stimulus psychopy code?

Thank you very much in advance.
Best wishes,


The code I provided is an example. You need to replace ‘a’ with whatever bytes the device is expecting.

I’m not familiar with PyDAQmx, but you should be able to call the API within your experiment’s main loop as you would any other Python module. The authors of PyDAQmx provide documentation here: