| PST SDK 6.0.0.0-272350a

minimal.cs

This example can be found in `examples\csharp\minimal\minimal.cs`. When the PST SDK has been installed through the PST Software Suite installer the examples can be found in the Development folder.

This is a bare minimum example showing how to connect to the PST SDK and how to register a listener to receive data.

Note that for simplicity reasons, this example does not take the recommended safety precautions to shut down the PST Tracker when the application shuts down. In an actual implementation, please follow the safety precautions recommended in the Safe Tracker Termination section of the Using PST SDK page of the manual. Examples of how to implement the safety precautions can be found in the other examples.

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.).

// Copyright PS-Tech B.V. All Rights Reserved.
using System;
using System.Threading;
using PSTech.Pstsdk;
namespace PSTech.Minimal
{
public class Minimal
{
class MyTrackerListener : TrackerListener
{
public override void OnTrackerData(TrackerData data, ErrorStatus status)
{
// Do something with the tracker data in data
}
}
static void Main(string[] args)
{
// 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.
Tracker tracker = new Tracker();
//Create tracker listener with callback functions for data and/or mode updates.
TrackerListener listener = new MyTrackerListener();
// Register the TrackerListener object to the tracker server.
tracker.AddTrackerListener(ref listener);
// Start the tracker server.
tracker.StartTracker();
// Wait for 10 seconds, allowing for the detection of tracking targets.
Thread.Sleep(10000);
}
catch (Exception e)
{
// Do something with the error.
}
finally
{
// Make sure that the connection to the PST Tracker is shut down properly.
Tracker.Shutdown();
}
}
}
}