SIEMENS Trigger with Serial Port

Hey! I have been using a Parallel Port Trigger to activate my task sequence but in my lab they decided to change the trigger to a Serial Port Trigger (Siemens).

I’m assuming that something like this are the changes to use Serial Port, but I don’t know if the commands for a Serial Port are enough to read the information from the Serial Port.

    #SerialPORT
    import serial
    port = serial.Serial('COM1',9600) #open first serial port
    port.read () #this is giving me problems!

The port.read() is crashing me the program, and we are not obtaining data from the trigger.

Does anyone had ever used Siemens Trigger with Psychopy?

Thanks!

You should provide the actual error message. e.g. in your code above, there is a typo with a space between the .read and the () but we can’t tell if that is a typo in the post or in your actual code. Regardless, you should be assigning whatever the result of the function is to a variable: i.e. even if this line of code worked, the result would disappear and not be available for future use. Suggest you do something like:

result = port.readline() # note: don't think it is just .read()

I don’t know if something like this may work…

    #SerialPORT
    
    import serial
    port = serial.Serial('COM1', baudrate=9600, bytesize=serial.EIGHTBITS)
    #port.timeout = 5
    data = port.readline()
    #print data
    while data == 0:
        pass
    if data == 1:
        break

Right now, I’m having no new error messages but the pythonw.exe says not responding… I guess this is a problem with the timeout, but what I need is that the trigger sent by the MRI start the sequence and play and audio with the serial port. I’m also trying to use a parallel port, but the code is giving me the same problem, pythonw.exe not responding and no error messages.

# Parallel Port
    from psychopy import parallel
    port = parallel.ParallelPort(address=0x0378)
    port.setData(4)
    port.readPin(3)
    port.setPin(3, 1)
    #port.readPin(2)
    #port.setPin(2, 0)
    while parallel.ParallelPort(address=0x0378).readPin(2) == 0:
        pass
    if parallel.ParallelPort(address=0x0378).readPin(2) == 1:
        break

You need to check your code structure. e.g. the following will (usually) lead to an infinite loop:

data = port.readline()
while data == 0:
    pass
if data == 1:
    break

The reading from the port needs to be within the loop. If nothing was read on the initial check, the while loop will never terminate.