Howdy, Stranger!

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

Supported by

Sending triggers via serial port to eye-tracker

PiaPia
edited April 2017 in OpenSesame

Hi,
I have to send triggers via the serial port from the experimental computer to an eye-tracking computer.
I "found" some python-code that does so (for a different experiment) on the computer, however, I don't fully understand it.
It would be very great if you could help me understanding it.
Here it is:

import serial
class SerialPort:
    def __init__(self):
        self.ser=serial.Serial()#2, 19200, timeout=1)
        self.ser.port="COM1"
        self.ser.baudrate=115200
        self.ser.timeout=1
        self.ser.open()
        print "> Opened port: ", self.ser

    def setData(self, x):
        print "REPLACE ME"
        pass

    def setCommand(self, x):
        print "> Now sending:", x
        self.ser.write(x+"\n")

    def sendMessage(self, x):
        print "> sending msg: ", x
        self.ser.write("ET_REM %s\n"%x)

    def inc(self, x):
        self.ser.write("ET_INC %i\n"%x)
    def __del__(self):
        self.ser.close()

## setup and clear port
port=SerialPort()
port.setCommand("ET_CLR")

## start recording eyedata
port.setCommand("ET_REC") # start rec

Later on in the experiment, when the instructions are shown it says:

port.sendMessage("instructions")

Which I don't fully understand because I thought that you can only send Number 0 to 255 by the (serial-) port? Is that wrong?

Also for other events, like the start of the training session triggers are send in the same format:

port.sendMessage("training_session")
port.sendMessage("end")
port.setCommand("ET_STP")

Can I include this script as an inline script in Open Sesame? This seems to work, I'm just a bit unsure because I don't fully understand what the code does....

Thank you very much,
Pia

Comments

This discussion has been closed.