1"""Rest server example of the PST SDK
2
3This example shows how to enable the REST server using the PST SDK.
4The REST server enables network-based access to the PST Tracker using
5the HTTP protocol. GET and POST requests can be made to the server to
6send and receive data and change parameters. The REST interface offers
7a programming language independent interface to the PST Tracker.
8Besides accessing the REST server directly using a browser, a networking
9library can be used to interface with the server programatically.
10
11Copyright PS-Tech B.V. All Rights Reserved.
12"""
13import context
14import time
15import sys
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_rest_server()
34 pst.Tracker.shutdown()
35
36def main():
37 if(len(sys.argv) < 2):
38 print("\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. "
39 "See the documentation of the Python bindings for more information.")
40 exit(0)
41
42
43 register_exit_handler()
44
45 try:
46
47
48 with pst.Tracker("", "","", sys.argv[1]) as tracker:
49
50 tracker.start()
51
52
53
54
55
56
57 tracker.enable_rest_server("localhost", "7278")
58
59 print("PST REST server enabled. See the PST SDK Manual for example commands.")
60
61
62 time.sleep(60)
63
64
65 tracker.disable_rest_server()
66 except psterrors.TrackerError as err:
67
68 print(err.message)
69
70if __name__ == "__main__":
71 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