Esempio n. 1
0
    void GetData()
    {
        while(!finished)
        {
            if (inlet != null)
            {
                inlet.pull_sample(sample, 0.5f);

                numberOfScore++;
                if (numberOfScore == 1)
                {
                    Score = sample[0];
                }
                else
                {
                    Score = (numberOfScore-1)/numberOfScore*Score + sample[0]/numberOfScore;
                }
                //Score = Score * sample[0];

            }
            else
            {
                // wait until an EEG stream shows up
                liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "score", 1, 0.5f);

                // open an inlet and print some interesting info about the stream (meta-data, etc.)
                inlet = new liblsl.StreamInlet(results[0]);
                Debug.Log(inlet.info().as_xml());
            }
        }
    }
Esempio n. 2
0
    void GetData()
    {
        while(!finished)
        {
            if (inlet != null)
            {
                inlet.pull_sample(sample, 0.5f);
                //Breathe = sample[];
                if (sample[0] > 0)
                {
                    Debug.Log("Beat");
                    if (LastHeartbeat == false)
                    {
                        Heartbeat = true;
                    }
                    LastHeartbeat = true;
                }
                else
                {
                    LastHeartbeat = false;
                }
            }
            else
            {
                // wait until an EEG stream shows up
                liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "heart", 1, 0.5f);

                // open an inlet and print some interesting info about the stream (meta-data, etc.)
                inlet = new liblsl.StreamInlet(results[0]);
                Debug.Log(inlet.info().as_xml());
            }
        }
    }
Esempio n. 3
0
    // look-up stream and fetch first value
    private void connect()
    {
        log ("Connect to LSL stream type: " + streamType);
        // wait until the correct type shows up
        liblsl.StreamInfo[] results = liblsl.resolve_stream ("type", streamType, 1, 0.5f);
        if (results.Length <= 0) {
            log ("No streams found");
            return;
        } else {
            log ("Found " + results.Length + " streams, looking for name: " + streamName);
        }
        liblsl.StreamInlet tmpInlet;
        for (int i=0; i < results.Length; i++) {
            // open an inlet and print some interesting info about the stream (meta-data, etc.)
            tmpInlet = new liblsl.StreamInlet (results [i]);
            try {
                liblsl.StreamInfo info = tmpInlet.info ();
                log ("Stream number: " + i + ", name: " + info.name ());
                if (info.name ().Equals (streamName)) {
                    nbChannels = info.channel_count();
                    log ("Stream found with " + nbChannels + " channels");
                    if (nbChannels < 1) {
                        log ("Error, no channels found, skip.");
                    }
                    else {
                        inlet = tmpInlet;
                        sample = new float[nbChannels];
                        break;
                    }
                }
            }
            // could lost stream while looping
            catch (TimeoutException) {
                log ("Timeout while fetching info.");
                continue;
            } catch (liblsl.LostException) {
                log ("Connection lost while fetching info.");
                continue;
            }
        }

        if (isConnected () && !init) {
            float firstValue = readRawValue();
            // may *again* disconnect while reading value
            if (isConnected ()) {
                listMax [0] = firstValue;
                listMax [0] = firstValue;
                init = true;
            }
        } else {
            log ("Stream not found.");
        }
    }
        static void Main(string[] args)
        {
            // wait until an EEG stream shows up
            liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "Markers");

            // open an inlet and print meta-data
            liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
            System.Console.Write(inlet.info().as_xml());

            // read samples
            string[] sample = new string[1];
            while (true)
            {
                inlet.pull_sample(sample);
                System.Console.WriteLine(sample[0]);
            }
        }
        static void Main(string[] args)
        {
            // wait until an EEG stream shows up
            liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "EEG");

            // open an inlet and print some interesting info about the stream (meta-data, etc.)
            liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
            System.Console.Write(inlet.info().as_xml());

            // read samples
            float[] sample = new float[8];
            while (true)
            {
                inlet.pull_sample(sample);
                foreach (float f in sample)
                    System.Console.Write("\t{0}",f);
                System.Console.WriteLine();
            }

            System.Console.ReadKey();
        }
        static void Main(string[] args)
        {
            // create a new StreamInfo and declare some meta-data (in accordance with XDF format)
            liblsl.StreamInfo info = new liblsl.StreamInfo("MetaTester","EEG",8,100,liblsl.channel_format_t.cf_float32,"myuid323457");
            liblsl.XMLElement chns = info.desc().append_child("channels");
            String[] labels = {"C3","C4","Cz","FPz","POz","CPz","O1","O2"};
            for (int k=0;k<labels.Length;k++)
                chns.append_child("channel")
                    .append_child_value("label", labels[k])
                    .append_child_value("unit", "microvolts")
                    .append_child_value("type","EEG");
            info.desc().append_child_value("manufacturer","SCCN");
            info.desc().append_child("cap")
                .append_child_value("name","EasyCap")
                .append_child_value("size","54")
                .append_child_value("labelscheme","10-20");

            // create outlet for the stream
            liblsl.StreamOutlet outlet = new liblsl.StreamOutlet(info);

            // === the following could run on another computer ===

            // resolve the stream and open an inlet
            liblsl.StreamInfo[] results = liblsl.resolve_stream("name","MetaTester");
            liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
            // get the full stream info (including custom meta-data) and dissect it
            liblsl.StreamInfo inf = inlet.info();
            Console.WriteLine("The stream's XML meta-data is: ");
            Console.WriteLine(inf.as_xml());
            Console.WriteLine("The manufacturer is: " + inf.desc().child_value("manufacturer"));
            Console.WriteLine("The cap circumference is: " + inf.desc().child("cap").child_value("size"));
            Console.WriteLine("The channel labels are as follows:");
            liblsl.XMLElement ch = inf.desc().child("channels").child("channel");
            for (int k=0;k<info.channel_count();k++) {
                Console.WriteLine("  " + ch.child_value("label"));
                ch = ch.next_sibling();
            }
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            // wait until an EEG stream shows up
            liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "EEG");

            // open an inlet and print meta-data
            liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
            System.Console.Write(inlet.info().as_xml());

            // read samples
            float[,] buffer = new float[512, 8];
            double[] timestamps = new double[512];
            while (true)
            {
                int num = inlet.pull_chunk(buffer,timestamps);
                for (int s = 0; s < num; s++)
                {
                    for (int c = 0; c < 8; c++)
                        Console.Write("\t{0}", buffer[s, c]);
                    Console.WriteLine();
                }
            }
        }
Esempio n. 8
0
    void GetData()
    {
        while(!finished)
        {
            if (inlet != null)
            {
                inlet.pull_sample(sample, 0.5f);

                if (listMax.Count < maxWindowSize)
                {
                    if (listMax.Count < (realTime - lastTime))
                    {
                        listMax.Add(float.MinValue);
                    }
                    if (listMin.Count < (realTime - lastTime))
                    {
                        listMin.Add(float.MaxValue);
                    }
                }
                else
                {
                    if (lastTime < (realTime - 1.0f))
                    {
                        lastTime = realTime;
                        listMax.RemoveAt(0);
                        listMin.RemoveAt(0);
                        listMax.Add(float.MinValue);
                        listMin.Add(float.MaxValue);
                    }
                }

                int currentItem = listMax.Count;
                Debug.Log(currentItem);
                if (sample[0] > listMax[currentItem-1])
                {
                    listMax[currentItem-1] = sample[0];
                }
                if (sample[0] < listMin[currentItem-1])
                {
                    listMin[currentItem-1] = sample[0];
                }

                float min = float.MaxValue;
                float max = float.MinValue;
                foreach(float element in listMin)
                {
                    if (element < min)
                    {
                        min = element;
                    }
                }
                foreach(float element in listMax)
                {
                    if (element > max)
                    {
                        max = element;
                    }
                }

                Breathe = (sample[0]-min) / (max-min);
                //Debug.Log (Breathe);
            }
            else
            {
                // wait until an EEG stream shows up
                liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "breath", 1, 0.5f);

                // open an inlet and print some interesting info about the stream (meta-data, etc.)
                inlet = new liblsl.StreamInlet(results[0]);
                Debug.Log(inlet.info().as_xml());

                inlet.pull_sample(sample, 0.5f);

                listMax[0] = sample[0];
                listMin[0] = sample[0];
            }
        }
    }