Tutorials

How to get the Emotiv headset or EmoComposer reading with C# (C Sharp)



How to get the Emotiv headset or EmoComposer reading with C# (C Sharp)

In this tutorial you will learn how to make a simple consol application that will read the state of your smile, left eye direction, and blink status. The rest of the functionality is straight forward from there.

This tutorial assumes that:

-          You are using Microsoft Visual Studio 2008

-          You are using DotNetEmotivSDK.dll 1.0.0.0

-          You are using edk.dll 1.0.0.0

 

In order to read the current state of the Emotiv system you need to:

-          Connect to the EmoEnging Connect() RemoteConnect() if you are using emoComposer

-          Capture the EmoState when the EmoEngin throws up the EmoStateUpdated event.

-          When the EmoStateUpdated event occurs you can read the EmoState. Note the EmoState is created by the EmoStateUpdatedEventArgs when the EmoStateUpdated event occurs.

Please see the code below for the main code in a VS2008 Consol project. Also click here for the entire project. Please note that you will need to re-link the DotNetEmotivSDK.dll.

Text Box: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Emotiv;

namespace BMItestConsolR6
{
    class Program
    {
        EmoEngine engine;
        static void Main(string[] args)
        {
            Program program = new Program();
            program.mainLoop();


        }


        void mainLoop()
        {
            engine = EmoEngine.Instance;
            engine.EmoStateUpdated += new  EmoEngine.EmoStateUpdatedEventHandler(engine_EmoStateUpdated);
            engine.RemoteConnect("127.0.0.1",1726);

            while (true)
            {
                engine.ProcessEvents(1000);
            }
        }

        void engine_EmoStateUpdated(object sender, EmoStateUpdatedEventArgs e)
        {
            EmoState es = e.emoState;
            Console.WriteLine("User has lower face expression: " + es.ExpressivGetLowerFaceAction().ToString()
                + "of strength " + es.ExpressivGetLowerFaceActionPower().ToString());
            float leftEye = 0;
            float rightEye = 0;
            es.ExpressivGetEyelidState(out leftEye,out rightEye);
            Console.WriteLine("Look Left"+ es.ExpressivIsLookingLeft().ToString());
            Console.WriteLine("Smile Extent: " + es.ExpressivGetSmileExtent().ToString());
            //Console.WriteLine("Look left: " + leftEye.ToString());
        }
    }
}

The end result will be a consol window that will output your smile extent twice in the form of lower facial expression strength, your smile strength and that state of you looking in the left direction.