Tobii Pro SDK Python API
call_eyetracker_manager.py
1 import os
2 import subprocess
3 import platform
4 import glob
5 import tobii_research as tr
6 
7 
8 def call_eyetracker_manager_example():
9  try:
10  os_type = platform.system()
11  ETM_PATH = ''
12  DEVICE_ADDRESS = ''
13  if os_type == "Windows":
14  ETM_PATH = glob.glob(os.environ["LocalAppData"] +
15  "/TobiiProEyeTrackerManager/app-*/TobiiProEyeTrackerManager.exe")[0]
16  DEVICE_ADDRESS = "tobii-ttp://IS404-100107417574"
17  elif os_type == "Linux":
18  ETM_PATH = "TobiiProEyeTrackerManager"
19  DEVICE_ADDRESS = "tobii-ttp://TOBII-IS404-100107417574"
20  elif os_type == "Darwin":
21  ETM_PATH = "/Applications/TobiiProEyeTrackerManager.app/Contents/MacOS/TobiiProEyeTrackerManager"
22  DEVICE_ADDRESS = "tobii-ttp://TOBII-IS404-100107417574"
23  else:
24  print("Unsupported...")
25  exit(1)
26 
27  eyetracker = tr.EyeTracker(DEVICE_ADDRESS)
28 
29  mode = "displayarea"
30 
31  etm_p = subprocess.Popen([ETM_PATH,
32  "--device-address=" + eyetracker.address,
33  "--mode=" + mode],
34  stdout=subprocess.PIPE,
35  stderr=subprocess.PIPE,
36  shell=False)
37 
38  stdout, stderr = etm_p.communicate() # Returns a tuple with (stdout, stderr)
39 
40  if etm_p.returncode == 0:
41  print("Eye Tracker Manager was called successfully!")
42  else:
43  print("Eye Tracker Manager call returned the error code: " + str(etm_p.returncode))
44  errlog = None
45  if os_type == "Windows":
46  errlog = stdout # On Windows ETM error messages are logged to stdout
47  else:
48  errlog = stderr
49 
50  for line in errlog.splitlines():
51  if line.startswith("ETM Error:"):
52  print(line)
53 
54  except Exception as e:
55  print(e)
56 
57 
58 if __name__ == "__main__":
59  call_eyetracker_manager_example()