1"""Shared memory example of the PST SDK
2
3This example shows how to activate the shared memory communication pipeline
4that enables communication of the PST Client application through the PST SDK.
5Note that for the shared memory pipeline to function, the application has to
6run with elevated access (administrator rights). After enabling shared memory,
7the PST Client application can be used to download calibration information and
8manage tracking targets.
9
10Copyright PS-Tech B.V. All Rights Reserved.
11"""
12import context
13import time
14import sys
15import ctypes
18
19"""Helper function to register the exit handler with the application"""
20def register_exit_handler():
21 if sys.platform.startswith("linux"):
22 import signal
23 signal.signal(signal.SIGTERM, exit_handler)
24 signal.signal(signal.SIGHUP, exit_handler)
25 signal.signal(signal.SIGQUIT, exit_handler)
26 signal.signal(signal.SIGINT, exit_handler)
27 elif sys.platform.startswith("win"):
28 import win32api
29 win32api.SetConsoleCtrlHandler(exit_handler, True)
30
31"""Implement the exit handler to shut-down the PST Tracker connection on application termination."""
32def exit_handler(*args):
33 pst.Tracker.disable_shared_memory()
34 pst.Tracker.shutdown()
35
36"""Check if user is an admin."""
37def is_admin():
38 if sys.platform.startswith("win"):
39 try:
40 return ctypes.windll.shell32.IsUserAnAdmin()
41 except:
42 return False
43 elif sys.platform.startswith("linux"):
44 return True
45
46def main():
47 if is_admin():
48 if(len(sys.argv) < 2):
49 print("\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. "
50 "See the documentation of the Python bindings for more information.")
51 exit(0)
52
53
54 register_exit_handler()
55
56 try:
57
58
59 with pst.Tracker("", "","", sys.argv[1]) as tracker:
60
61 tracker.start()
62
63
64 tracker.enable_shared_memory()
65
66 print("Shared memory server initialized. Start the PST Client application to create a connection.\n")
67
68
69 time.sleep(60)
70
71
72
73 tracker.disable_shared_memory()
74 except psterrors.TrackerError as err:
75
76 print(err.message)
77 else:
78
79 ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
80
81if __name__ == "__main__":
82 main()
Module containing all error related classes and functions.
Definition errors.py:1
Module containing all tracker related classes and functions.
Definition tracker.py:1