psychopy.org | Reference | Downloads | Github

PsychoPy does not download Pupil Labs Surface Data

Hi!

I have been trying to integrate my psychopy experiment with the Pupil Labs Pupil Core eye tracker. However, the PsychoPy Runner becomes unresponsive when I include my eye tracking code. Below is my eye tracking function, embedded in my experimental code. And attached is my entire experimental code.

def is_looking_at_surface(surface_name):
    context = zmq.Context()
    # open a req port to talk to pupil
    addr = "127.0.0.1"  # remote ip or localhost
    req_port = "50020"  # same as in the pupil remote gui
    req = context.socket(zmq.REQ)
    req.connect("tcp://{}:{}".format(addr, req_port))
    # ask for the sub port
    req.send_string("SUB_PORT")
    sub_port = req.recv_string()

    # open a sub port to listen to pupil
    sub = context.socket(zmq.SUB)
    sub.connect("tcp://{}:{}".format(addr, sub_port))
    sub.setsockopt_string(zmq.SUBSCRIBE, "surface")

    topic = sub.recv_string()
    msg = sub.recv()  # bytes
    surfaces = loads(msg, raw=False)
    print(surfaces)
    filtered_surface = {
        k: v for k, v in surfaces.items() if surfaces["name"] == surface_name
    }
    # note that we may have more than one gaze position data point (this is expected behavior)

    gaze_positions = filtered_surface["gaze_on_surfaces"]

    for gaze_pos in gaze_positions:
        norm_gp_x, norm_gp_y = gaze_pos["norm_pos"]

        # only print normalized gaze positions within the surface bounds
        if 0 <= norm_gp_x <= 1 and 0 <= norm_gp_y <= 1:
            return True
        else:
            return False

UniformityIllusion.py (26.4 KB)