I am new to C# and may be doing something wrong!
I have it connected and working with EmotivXavier Control Panel. I have written a code to get the raw data in csv from the EEG Emotiv.
I downloaded the Community SDK from Emotiv GitHub. There, I could find the DotNetEmotivSDK.dll. Together with many others:
I added all this files to my project "/bin" folder and tried to reference all of them in the Visual Studio. Only one worked
Still, I could include use the Emotiv class in C#, only with this single dll.
But, when I run my code, this error shows up:
The error says:
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'edk.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Emotiv.EdkDll.Unmanged_IEE_EmoEngineEventCreate() at Emotiv.EdkDll.IEE_EmoEngineEventCreate() in C:\Users\Becchi-PC\Documents\EEG\community-sdk-master\examples\C#\DotNetEmotivSDK\EdkDll.cs:line 756 at Emotiv.EmoEngine..ctor() in C:\Users\Becchi-PC\Documents\EEG\community-sdk-master\examples\C#\DotNetEmotivSDK\EmoEngine.cs:line 393 at Emotiv.EmoEngine.get_Instance() in C:\Users\Becchi-PC\Documents\EEG\community-sdk-master\examples\C#\DotNetEmotivSDK\EmoEngine.cs:line 418 at EEG.EEG_Logger..ctor() in C:\Users\Becchi-PC\Documents\EEG\EEG_v2\Program.cs:line 21 at EEG.EEG_Logger.Main(String[] args) in C:\Users\Becchi-PC\Documents\EEG\EEG_v2\Program.cs:line 97
The missing dll (Edk.dll) is one of those i couldnt reference.
This is my full code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Reflection;
using Emotiv;
namespace EEG
{
class EEG_Logger
{
EmoEngine engine; //Criando a variavel com a Engine
int userID = -1; //ID do usuario
string filename = "outfile.csv"; //Arquivo de saida
EEG_Logger()
{
//Instanciando a Engine
engine = EmoEngine.Instance;
engine.UserAdded += new EmoEngine.UserAddedEventHandler(engine_UserAdded_Event);
//Conectando ao EEG
engine.Connect();
//Criando o Header do CSV
WriteHeader();
}
void engine_UserAdded_Event(object sender, EmoEngineEventArgs e)
{
Console.WriteLine("User Added Event has occured");
//Gravando o usuario
userID = (int)e.userId;
//Permitindo a aquisicao de dados
engine.DataAcquisitionEnable((uint)userID, true);
//Determinando o tempo do buffer
engine.DataSetBufferSizeInSec(1);
}
public void WriteHeader()
{
TextWriter file = new StreamWriter(filename, false);
string header = "COUNTER,INTERPOLATED,RAW_CQ,AF3,F7,F3, FC5, T7, P7, O1, O2,P8" +
", T8, FC6, F4,F8, AF4,GYROX, GYROY, TIMESTAMP, ES_TIMESTAMP" +
"FUNC_ID, FUNC_VALUE, MARKER, SYNC_SIGNAL,";
file.WriteLine(header);
file.Close();
}
void Run()
{
// Handle any waiting events
engine.ProcessEvents();
// If the user has not yet connected, do not proceed
if ((int)userID == -1)
return;
Dictionary<EdkDll.IEE_DataChannel_t, double[]> data = engine.GetData((uint)userID);
if (data == null)
{
return;
}
int _bufferSize = data[EdkDll.IEE_DataChannel_t.IED_TIMESTAMP].Length;
Console.WriteLine("Writing " + _bufferSize.ToString() + " lines of data ");
// Write the data to a file
TextWriter file = new StreamWriter(filename, true);
for (int i = 0; i < _bufferSize; i++)
{
//Escrevendo no arquivo
foreach (EdkDll.IEE_DataChannel_t channel in data.Keys)
file.Write(data[channel][i] + ",");
file.WriteLine("");
}
file.Close();
}
static void Main(string[] args)
{
EEG_Logger p = new EEG_Logger();
for (int i = 0; i < 10; i++)
{
p.Run();
Thread.Sleep(100);
}
}
}
}
Please help!
First of all, you should not be placing the dlls in the bin folder of your project, because that is the place where the referenced dlls are copied to, after build, not the place you should reference them from. So one option would be to copy the requested dlls in a location in your project and reference them from there (e.g.: a Lib folder).
Secondly, you can find the Emotiv SDK on github, and there is also a solution with examples, containing several projects: https://github.com/Emotiv/community-sdk/tree/master/examples/C%23. As you will notice, those projects reference the DotNetEmotivSDK project, so that would be your other option for solving your issue.
User contributions licensed under CC BY-SA 3.0