PST SDK  6.0.0.0-272350a
sharedmemory.cpp

This example can be found in examples\cpp\sharedmemory\sharedmemory.cpp. When the PST SDK has been installed through the PST Software Suite installer the examples can be found in the Development folder.

This example shows how to activate the shared memory communication pipeline that enables communication of the PST Client application through the PST SDK. Note that for the shared memory pipeline to function, the application has to run with elevated access (administrator rights). After enabling shared memory, the PST Client application can be used to download calibration information and manage tracking targets.

When compiling and running this example, please make sure that the required dependencies can be found by the executable (e.g. by copying the Redist directory into the build directory. When the PST SDK has been installed through the PST Software Suite installer the Redist folder can be found in the Development folder.). On Windows, the Visual Studio project files are configured to use a relative path to the Redist directory as the working directory. If the examples have been copied, please ensure the working directory is still valid.

#ifdef WIN32
#include <windows.h>
#else
#include <csignal>
#endif
/*
* Define handler functions required to ensure a clean shutdown of the PST Tracker
* when the application is terminated.
*/
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
/* End of handler functions */
#include <iostream>
#include <thread>
#include <chrono>
#include "pstsdk_cpp.h"
/*
* Implement the exit handler to shut-down the PST Tracker connection on application termination.
*/
static void Exithandler(int sig)
{
exit(0);
}
int main(int argc, char *argv[])
{
// Register the exit handler with the application
#ifdef WIN32
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
#else
signal(SIGTERM, Exithandler);
signal(SIGKILL, Exithandler);
signal(SIGQUIT, Exithandler);
signal(SIGINT, Exithandler);
#endif
// Implement error handling of PSTech::TrackerException exceptions to prevent
// improper PST Tracker shutdown on errors.
try
{
// Create an instance of the Tracker object using the default configuration path and file names.
#ifdef WIN32
#else
// On Linux, specify the type of grabber that needs to be used as the last parameter:
// "basler_ace" for PST HD or "basler_dart" for PST Pico
PSTech::pstsdk::Tracker pst("","config.cfg","models.db",argv[1]);
#endif
// Start the tracker server.
pst.Start();
// Enable the shared memory pipeline to enable client connections.
std::cout << "Shared memory server initialized. Start the PST Client application to create a connection.\n";
// Wait for one minute before terminating this application.
std::this_thread::sleep_for(std::chrono::milliseconds(60000));
// Disable the shared memory pipeline. If the PST Client is still connected at this point,
// it will try to reconnect and otherwise exit.
}
{
std::cout << e.full_description() << "\n";
// Handle the error.
}
// Make sure that the connection to the PST Tracker is shut down properly.
return 0;
}
PSTech::pstsdk::Tracker
Main PST SDK class implementing tracker communication.
Definition: pstsdk_cpp.h:87
PSTech::pstsdk::Tracker::EnableSharedMemory
static void EnableSharedMemory()
Enable shared memory communication layer.
PSTech::pstsdk::Tracker::Shutdown
static void Shutdown()
Shutdown the tracking system, stopping tracking.
PSTech::pstsdk::Tracker::Start
void Start()
Start tracking.
pstsdk_cpp.h
TrackerExceptions.h
PSTech::pstsdk::Tracker::DisableSharedMemory
static void DisableSharedMemory()
Disable shared memory communication layer.
PSTech::PSTException::full_description
virtual const char * full_description() const
PSTech::TrackerException
Definition: TrackerExceptions.h:49