def client(server_ip): # t : test connect # q : quit client # space : enter control.set_develop_mode(True) control.defaults.audiosystem_autostart = False exp = control.initialize() udp_connection = UDPConnection() print(udp_connection) if not udp_connection.connect_peer(server_ip): print("error connecting to peer") exit() stimuli.TextScreen( "connected to " + udp_connection.peer_ip, "\nSPACE: send text\nT: trigger test\nQ: quit").present() c = Clock() while True: key = exp.keyboard.check() if key == ord("q"): break elif key == misc.constants.K_SPACE: text = io.TextInput().get() stimuli.BlankScreen().present() print("send: {} {}".format(c.time, text)) udp_connection.send(text) elif key == ord("t"): times = [] for cnt in range(20): stimuli.TextLine("ping test " + str(cnt)).present() c.reset_stopwatch() ok, time = udp_connection.ping(timeout=1) print("answer received in {} ms".format(c.stopwatch_time)) times.append(time) c.wait(100) stimuli.BlankScreen().present() print(times) feedback = udp_connection.poll() if feedback is not None: print("received: {} {}".format(c.time, feedback)) udp_connection.unconnect_peer()
expyriment.control.start() wm.present() kb.wait_char('t') # wait for scanner TTL fs.present() # clear screen, presenting fixation cross a = Clock() while not (events.empty()): onset, stype, id, stim = events.get() print('event {} {} @ {}'.format(stype, id, onset)) if a.time > onset: print('...delayed @ {}'.format(a.time)) # TODO while a.time < (onset - 10): a.wait(10) k = kb.check() if k is not None: print('keypressed: {} @ {}'.format(k, a.time)) exp.data.add([a.time, k]) stim.present() k = kb.check() if k is not None: print('keypressed: {} @ {}'.format(k, a.time)) exp.data.add([a.time, k]) try: TOTAL_EXPE_DURATION except NameError:
exp.add_data_variable_names([ 'condition', 'time', 'stype', \ 'id', 'target_time']) expyriment.control.start(skip_ready_screen=True, subject_id=args.subject_id) wm.present() kb.wait_char('t') # wait for scanner TTL fs.present() # clear screen, presenting fixation cross a = Clock() while not (events.empty()): onset, cond, stype, id, stim = events.get() while a.time < (onset - 10): a.wait(1) k = kb.check() if k is not None: exp.data.add([a.time, 'keypressed,{}'.format(k)]) stim.present() exp.data.add(['{}'.format(cond), \ a.time, \ '{},{},{}'.format(stype, id, onset)]) k = kb.check() if k is not None: exp.data.add([a.time, 'keypressed,{}'.format(k)]) fs.present()
##while feedback is None: ## feedback = udp.poll() ##print "<-- ", c.time, feedback while True: key = exp.keyboard.check() if key == ord("q"): break elif key == misc.constants.K_SPACE: text = io.TextInput().get() stimuli.BlankScreen().present() print "--> ", c.time, text udp_connection.send(text) elif key == ord("t"): times = [] for cnt in range(20): stimuli.TextLine("ping test " + str(cnt)).present() c.reset_stopwatch() ok, time = udp_connection.ping() print c.stopwatch_time times.append(time) c.wait(100) stimuli.BlankScreen().present() print times feedback = udp_connection.poll() if feedback is not None: print "<-- ", c.time, feedback udp_connection.unconnect_peer()