1 """Rest server example of the PST SDK 3 This example shows how to enable the REST server using the PST SDK. 4 The REST server enables network-based access to the PST Tracker using 5 the HTTP protocol. GET and POST requests can be made to the server to 6 send and receive data and change parameters. The REST interface offers 7 a programming language independent interface to the PST Tracker. 8 Besides accessing the REST server directly using a browser, a networking 9 library can be used to interface with the server programatically. 11 Copyright PS-Tech B.V. All Rights Reserved. 19 """Helper function to register the exit handler with the application""" 20 def register_exit_handler():
21 if sys.platform.startswith(
"linux"):
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"):
29 win32api.SetConsoleCtrlHandler(exit_handler,
True)
31 """Implement the exit handler to shut-down the PST Tracker connection on application termination.""" 32 def exit_handler(*args):
33 pst.Tracker.disable_rest_server()
34 pst.Tracker.shutdown()
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.")
43 register_exit_handler()
48 with pst.Tracker(
"",
"",
"", sys.argv[1])
as tracker:
57 tracker.enable_rest_server(
"localhost",
"7278")
59 print(
"PST REST server enabled. See the PST SDK Manual for example commands.")
65 tracker.disable_rest_server()
66 except psterrors.TrackerError
as err:
70 if __name__ ==
"__main__":