using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace PSTech.Images
{
public class Images
{
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(ConsoleEventHandler handler, bool add);
private delegate bool ConsoleEventHandler(CtrlType sig);
static ConsoleEventHandler ConsoleCtrlEventHandler;
public enum CtrlType
{
CtrlCEvent = 0,
CtrlBreakEvent = 1,
CtrlCloseEvent = 2,
CtrlLogOffEvent = 5,
CtrlShutdownEvent = 6,
}
private static bool ConsoleHandler(CtrlType sig)
{
Exithandler((int)sig);
return true;
}
static bool Running = true;
static int NumberOfSamplesToGrab = 1000;
static int SamplesGrabbed = 0;
class MyTrackerListener : TrackerListener
{
public override void OnTrackerData(TrackerData data,
ErrorStatus status)
{
if (SamplesGrabbed++ >= NumberOfSamplesToGrab)
{
Running = false;
}
}
}
static void Exithandler(int sig)
{
Tracker.Shutdown();
Environment.Exit(0);
}
static int Main(string[] args)
{
ConsoleCtrlEventHandler += new ConsoleEventHandler(ConsoleHandler);
SetConsoleCtrlHandler(ConsoleCtrlEventHandler, true);
try
{
Tracker tracker = new Tracker();
Console.Write("Running PST Server version " + tracker.GetVersionInfo() + "\n");
TrackerListener listener = new MyTrackerListener();
tracker.AddTrackerListener(ref listener);
tracker.StartTracker();
Console.Write("System check: " + tracker.Systemcheck() + "\n\n");
Console.Write("***************************\n\n");
tracker.SetFramerate(60);
Console.Write("Current frame rate: " + tracker.GetFramerate() + " Hz\n\n");
tracker.EnableImageTransfer();
Console.Write("Enabled image transfer. Current frame rate: " + tracker.GetFramerate() + " Hz\n\n");
Console.Write("***************************\n\n");
for (int i = 0; i < 100; ++i)
{
Pstsdk.Image images = tracker.GetImage();
Console.Write("Retrieval operation successful!\n");
Console.Write("Retrieved " + images.Images.Length + " image(s) of size: " + images.Width + " X " + images.Height + "\n\n");
Thread.Sleep(17);
}
Console.Write("Waiting 5 seconds for image transfer to be automatically disabled...\n\n");
Thread.Sleep(5000);
Pstsdk.Image image = tracker.GetImage();
Console.Write("Retrieval operation successful!\n");
Console.Write("Retrieved " + image.Images.Length + " image(s) of size: " + image.Width + " X " + image.Height + "\n\n");
while (Running)
{
Thread.Sleep(100) ;
}
}
{
Console.Write(e + "\n");
}
finally
{
Tracker.Shutdown();
}
Console.Write("Press enter to continue...\n");
Console.Read();
return 0;
}
}
}