Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Tobii EyeX UDP data shipper to VMWare VM host.
// Used to send data from a VMWare VM running the EyeX software
// with a Steelseries Sentry to a Mac OSX host over UDP.
namespace MinimalGazeDataStream
{
using EyeXFramework;
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using Tobii.EyeX.Framework;
public static class Program
{
public static void Main(string[] args)
{
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPAddress addr = IPAddress.Parse("192.168.181.1");
IPEndPoint ep = new IPEndPoint(addr, 11249);
using (var eyeXHost = new EyeXHost())
{
// Create a data stream: lightly filtered gaze point data.
// Other choices of data streams include EyePositionDataStream and FixationDataStream.
using (var lightlyFilteredGazeDataStream = eyeXHost.CreateGazePointDataStream(GazePointDataMode.LightlyFiltered))
// using (var lightlyFilteredGazeDataStream = eyeXHost.CreateFixationDataStream(FixationDataMode.Sensitive))
{
using (var eyeStream = eyeXHost.CreateEyePositionDataStream())
{
// Start the EyeX host.
eyeXHost.Start();
// Write the data to the console.
lightlyFilteredGazeDataStream.Next += (s, e) =>
{
string msg = String.Format("{{\"gaze\":[{0},{1}],\"time\": {2}}}", e.X, e.Y, e.Timestamp);
byte[] sendbuf = Encoding.ASCII.GetBytes(msg);
sock.SendTo(sendbuf, ep);
// Console.WriteLine("G: {0}", msg);
};
eyeStream.Next += (s, e) =>
{
string msg = String.Format("{{\"leftEye\":[{0},{1},{2}],\"rightEye\":[{3},{4},{5}],\"time\": {6}}}",
e.LeftEye.X, e.LeftEye.Y, e.LeftEye.Z,
e.RightEye.X, e.RightEye.Y, e.RightEye.Z,
e.Timestamp);
byte[] sendbuf = Encoding.ASCII.GetBytes(msg);
sock.SendTo(sendbuf, ep);
// Console.WriteLine("E: {0}", msg);
};
// Let it run until a key is pressed.
Console.WriteLine("Listening for gaze data, press any key to exit...");
Console.In.Read();
}
}
}
}
}
}
Owner

trishume commented Mar 17, 2016

My very first C# program! 90% copy-pasted from various code snippets. Is legitimately terrible but gets the job done.

Owner

trishume commented Mar 17, 2016

You'll need to put it in a visual studio solution, and add the EyeXHost project and Client.Net20 dll as references.

Thanks for posting this! Unfortunately I got a bit stuck on the setup. Would you be able to describe in a bit more detail the steps to set up the project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment