Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Problem sending SerialPort Triggers

Hi everyone,

I'm trying to build an ERP oddball experiment but I'm having trouble sending the triggers. Since I'm new to code, I've managed to collect information from the forum discussions and have used the following inline scripts:

#SerialPort_Open
import serial
exp.serial_port = serial.Serial('COM3')

#SerialPort_Send
exp.serial_port.write(chr(1))

#SerialPort_Close
exp.serial_port.close()

The EEG is being recorded with Biosemi ActiveTwo system and the ActiView software. Although the experiment run as expected, no trigger is sent. I've tried to move the SerialPort_Open inline script before the loop but the experiment crashes with the following error:

 File "C:\Program Files (x86)\OpenSesame\lib\site-packages\serial\serialwin32.py", line 62, in open
  raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
SerialException: could not open port 'COM3': WindowsError(2, 'El sistema no puede encontrar el archivo especificado.')

I wonder if there may be some error in the python code or if I didn't insert the Inline scripts in the correct place. I've attached an image of a simplified version of the experiment so you can have a look at the structure.

Does anyone have any suggestions?

Thanks in advanced,

Jose

Comments

  • Hi,

    I am running the same kind of experiment. I managed to see the triggers on the recording software with this method (the port is a serial port and I've found the address of the port in the Windows Device Manager).

    First, I put this inline script at the very beginning of my experiment.

    Then I put this inline script after each stimulus

    After that, I put an inline script to reset the port to zero (for example at the end of the trial sequence).

    Always write the code in the "Run" tab and not the Prepare tab. And that's it. It works for me, but I am very new to OpenSesame so I am not sure that this is the best solution to your problem !

    Eva

  • Hi Eva,

    Thanks for your answer. I have made some changes following your comments, however, triggers are still not sending. Attached a simplified version of the experiment just to try to solve this problem.

    The inline scripts are as follows:

    For SerialPort_Open

    import serial
    exp.serial_port = serial.Serial('COM3')
    exp.cleanup_functions.append(exp.serial_port.close)
    

    For SerialPort_Send

    exp.serial_port.write(chr(1))
    

    For resetPort_to_0

    exp.serial_port.write(chr(0)) 
    

    For SerialPort_Close

    exp.serial_port.close()
    

    The experiment doesn't crash, but it doesn't send triggers either. Does anyone has any clue how to get through this issue?

  • edited February 20

    Could be an issue on the receiving end. I am not too familiar with BioSemi, but:

    • Some systems are really finicky about specifying the baud rate.
    • What does Biosemi "expect" to see? Perhaps you should do a byte conversion on your end, so something along the lines of (for Python3):
    serial_port.write(bytes([1]))
    

    Like I said, total guesswork though. Maybe BioSemi support will be able to better assist you.

Sign In or Register to comment.