void Start()
        {
            var channelDefinitions = SetupChannels();

            dataRate = LSLUtils.GetSamplingRateFor(sampling);

            channelCount = channelDefinitions.Count;

            // initialize the array once
            currentSample = new float[channelCount];

            streamInfo = new liblsl.StreamInfo(StreamName, StreamType, channelCount, dataRate, liblsl.channel_format_t.cf_float32, unique_source_id);

            // it's not possible to create a XMLElement before and append it.
            liblsl.XMLElement chns = streamInfo.desc().append_child("channels");
            // so this workaround has been introduced.
            foreach (var def in channelDefinitions)
            {
                chns.append_child("channel")
                .append_child_value("label", def.label)
                .append_child_value("unit", def.unit)
                .append_child_value("type", def.type);
            }

            outlet = new liblsl.StreamOutlet(streamInfo);
        }
        /// <summary>
        /// Setup LSL outlet for the board
        /// </summary>
        void SetupLslOutletForBoard()
        {
            var numChannels       = BrainhatBoardShim.GetNumberOfExgChannels(BoardId);
            var numAccelChannels  = BrainhatBoardShim.GetNumberOfAccelChannels(BoardId);
            var numOtherChannels  = BrainhatBoardShim.GetNumberOfOtherChannels(BoardId);
            var numAnalogChannels = BrainhatBoardShim.GetNumberOfAnalogChannels(BoardId);

            SampleSize = 2 + numChannels + numAccelChannels + numOtherChannels + numAnalogChannels;

            StreamInfo = new liblsl.StreamInfo(BoardId.GetSampleName(), "BFSample", SampleSize, SampleRate, liblsl.channel_format_t.cf_double64, BrainHatNetwork.NetworkUtilities.GetHostName());

            StreamInfo.desc().append_child_value("manufacturer", "OpenBCI");
            StreamInfo.desc().append_child_value("boardId", $"{BoardId}");
            liblsl.XMLElement chns = StreamInfo.desc().append_child("channels");

            chns.append_child("channel")
            .append_child_value("label", "SampleIndex")
            .append_child_value("unit", "0-255")
            .append_child_value("type", "index");

            for (int k = 0; k < numChannels; k++)
            {
                chns.append_child("channel")
                .append_child_value("label", $"ExgCh{k}")
                .append_child_value("unit", "uV")
                .append_child_value("type", "EEG");
            }

            for (int k = 0; k < numAccelChannels; k++)
            {
                chns.append_child("channel")
                .append_child_value("label", $"AcelCh{k}")
                .append_child_value("unit", "1.0")
                .append_child_value("type", "Accelerometer");
            }

            for (int k = 0; k < numOtherChannels; k++)
            {
                chns.append_child("channel")
                .append_child_value("label", $"Other{k}");
            }

            for (int k = 0; k < numAnalogChannels; k++)
            {
                chns.append_child("channel")
                .append_child_value("label", $"AngCh{k}");
            }

            chns.append_child("channel")
            .append_child_value("label", "TimeStamp")
            .append_child_value("unit", "s");
        }
Exemple #3
0
 // Start is called before the first frame update
 void Start()
 {
     liblsl.StreamInfo streamInfo = new liblsl.StreamInfo(StreamName, StreamType, 7, 72, liblsl.channel_format_t.cf_float32);
     liblsl.XMLElement chans      = streamInfo.desc().append_child("channels");
     chans.append_child("channel").append_child_value("label", "PosX");
     chans.append_child("channel").append_child_value("label", "PosY");
     chans.append_child("channel").append_child_value("label", "PosZ");
     chans.append_child("channel").append_child_value("label", "RotW");
     chans.append_child("channel").append_child_value("label", "RotX");
     chans.append_child("channel").append_child_value("label", "RotY");
     chans.append_child("channel").append_child_value("label", "RotZ");
     outlet        = new liblsl.StreamOutlet(streamInfo);
     currentSample = new float[7];
 }
        /// <summary>
        /// Get channel lists of current stream
        /// </summary>
        protected List <string> GetChannelsList()
        {
            List <string> channels = new List <string>();

            if (inlet != null)
            {
                liblsl.XMLElement chan = inlet.info().desc().child("channels").child("channel");
                for (int i = 0; i < inlet.info().channel_count(); i++)
                {
                    string chanName = chan.child_value("label");
                    channels.Add(chanName);
                    chan = chan.next_sibling();
                }
            }
            return(channels);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            // Check for command line arguments
            if (args.Length > 0)
            {
                hrDeviceName = args[0];
                // To print the command line
                // arguments using foreach loop
                foreach (Object obj in args)
                {
                    Console.WriteLine("Attempting to connect to " + obj);
                }
            }

            // create LSL stream info and outlet
            info = new liblsl.StreamInfo("Polar", "HRV", 2, 10);

            // add descriptions of
            liblsl.XMLElement chns = info.desc().append_child("channels");
            chns.append_child("hr");
            chns.append_child("rr");

            //chns.append_child("channel")
            //    .append_child_value("label", "hr")
            //    .append_child_value("unit", "bpm")
            //    .append_child_value("type", "HR");

            //chns.append_child("channel")
            //    .append_child_value("label", "rr")
            //    .append_child_value("unit", "ms")
            //    .append_child_value("type", "HR");

            outlet = new liblsl.StreamOutlet(info);

            // Run main loop
            MainAsync(args).Wait();

            Console.ReadLine();

            // Return exit code to the shell
            // For scripting/batch processing, it's an ERRORLEVEL cmd.exe shell variable
            Environment.Exit(_exitCode);
        }
 // Start is called before the first frame update
 void Start()
 {
     liblsl.StreamInfo streamInfo = new liblsl.StreamInfo(StreamName, StreamType, 12, 1 / Time.fixedDeltaTime, liblsl.channel_format_t.cf_float32, StreamId);
     liblsl.XMLElement chans      = streamInfo.desc().append_child("channels");
     chans.append_child("channel").append_child_value("label", "Timestamp");
     chans.append_child("channel").append_child_value("label", "ConvergenceDistance");
     chans.append_child("channel").append_child_value("label", "ConvergenceDistanceIsValid");
     chans.append_child("channel").append_child_value("label", "GazeRayOriginX");
     chans.append_child("channel").append_child_value("label", "GazeRayOriginY");
     chans.append_child("channel").append_child_value("label", "GazeRayOriginZ");
     chans.append_child("channel").append_child_value("label", "GazeRayDirectionX");
     chans.append_child("channel").append_child_value("label", "GazeRayDirectionY");
     chans.append_child("channel").append_child_value("label", "GazeRayDirectionZ");
     chans.append_child("channel").append_child_value("label", "GazeRayIsValid");
     chans.append_child("channel").append_child_value("label", "IsLeftEyeBlinking");
     chans.append_child("channel").append_child_value("label", "IsRightEyeBlinking");
     outlet        = new liblsl.StreamOutlet(streamInfo);
     currentSample = new float[12];
 }
Exemple #7
0
    public int Configure(string name, string type, int chan_count, double rate,
                         liblsl.channel_format_t format, string unique_id, IDictionary <string,
                                                                                        IDictionary <string, int> > metadata_dicts_names)
    {
        StreamName   = name;
        StreamType   = type;
        UniqueID     = unique_id;
        ChannelCount = chan_count;
        int idx;

        if (_outletsName.IndexOf(name) == -1)
        {
            // Populate XML meta data
            liblsl.StreamInfo si = new liblsl.StreamInfo(
                name,
                type,
                chan_count,
                rate,
                format,
                unique_id);
            liblsl.XMLElement streamInfoXML = si.desc();

            foreach (var map_name in metadata_dicts_names)
            {
                liblsl.XMLElement map_el = si.desc().append_child(map_name.Key);
                foreach (var property in map_name.Value)
                {
                    map_el = map_el.append_child_value(property.Key.ToString(), property.Value.ToString());
                }
            }
            ;

            _lslStreamInfos.Add(si);
            _outlets.Add(new liblsl.StreamOutlet(_lslStreamInfos[_lslStreamInfos.Count - 1]));
            _outletsName.Add(name);
            idx = _outletsName.Count - 1;
        }
        else
        {
            idx = _outletsName.IndexOf(name);
        }
        return(idx);
    }
        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();
        }
        void Awake()
        {
            UnityEngine.Debug.Log("LSLMarkerStream");

            sample = new double[lslChannelCount];

            lslStreamInfo = new liblsl.StreamInfo(
                lslStreamName,
                lslStreamType,
                lslChannelCount,
                nominal_srate,
                lslChannelFormat,
                unique_source_id);
            lslStreamInfo.desc().append_child_value("manufacturer", "UnityLSL");
            liblsl.XMLElement chns     = lslStreamInfo.desc().append_child("channels");
            string[]          channels = { "MarkerTime", "MarkerValue", "CurrentTime" };
            foreach (string chanName in channels)
            {
                chns.append_child("channel").append_child_value("label", chanName).append_child_value("type", "Marker");
            }

            lslOutlet = new liblsl.StreamOutlet(lslStreamInfo);
        }
    // Use this for initialization
    void Start()
    {
        head = GameObject.Find("Camera (eye)");

        if (head != null)
        {
            // initialize the array once
            currentSample = new float[ChannelCount];

            //dataRate = LSLUtils.GetSamplingRateFor(sampling);

            streamInfo = new liblsl.StreamInfo(StreamName, StreamType, ChannelCount, dataRate, liblsl.channel_format_t.cf_float32, uid);

            //setup LSL stream metadata (code from vizard)
            //streamInfo.desc().append_child("synchronization").append_child_value("can_drop_samples", "true");
            var setup = streamInfo.desc().append_child("setup");
            setup.append_child_value("name", StreamName);
            // channels with position and orientation in quaternions
            objs = setup.append_child("objects");
            obj  = objs.append_child("object");
            obj.append_child_value("label", StreamName);
            obj.append_child_value("id", StreamName);
            obj.append_child_value("type", "Mocap");

            channels = streamInfo.desc().append_child("channels");
            chan     = channels.append_child("channel");
            chan.append_child_value("label", StreamName + "_X");
            chan.append_child_value("object", StreamName);
            chan.append_child_value("type", "PositionX");
            chan.append_child_value("unit", "meters");

            chan = channels.append_child("channel");
            chan.append_child_value("label", StreamName + "_Y");
            chan.append_child_value("object", StreamName);
            chan.append_child_value("type", "PositionY");
            chan.append_child_value("unit", "meters");

            chan = channels.append_child("channel");
            chan.append_child_value("label", StreamName + "_Z");
            chan.append_child_value("object", StreamName);
            chan.append_child_value("type", "PositionZ");
            chan.append_child_value("unit", "meters");

            chan = channels.append_child("channel");
            chan.append_child_value("label", StreamName + "_quat_X");
            chan.append_child_value("object", StreamName);
            chan.append_child_value("type", "OrientationX");
            chan.append_child_value("unit", "quaternion");

            chan = channels.append_child("channel");
            chan.append_child_value("label", StreamName + "_quat_Y");
            chan.append_child_value("object", StreamName);
            chan.append_child_value("type", "OrientationY");
            chan.append_child_value("unit", "quaternion");

            chan = channels.append_child("channel");
            chan.append_child_value("label", StreamName + "_quat_Z");
            chan.append_child_value("object", StreamName);
            chan.append_child_value("type", "OrientationZ");
            chan.append_child_value("unit", "quaternion");

            chan = channels.append_child("channel");
            chan.append_child_value("label", StreamName + "_quat_W");
            chan.append_child_value("object", StreamName);
            chan.append_child_value("type", "OrientationW");
            chan.append_child_value("unit", "quaternion");

            outlet = new liblsl.StreamOutlet(streamInfo);
        }
    }
Exemple #11
0
    // Use this for initialization
    void Start()
    {
        if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer)
        {
            Debug.Log("You're running " + SystemInfo.operatingSystem +
                      ". Aborting StreamOutEvents.cs");
            Debug.Log("Remember to check MExperimentController.ResetCamera script if attempting VR");
            return; // LSL crashes OSX
        }
        // 1 - Create the stream descriptor.
        int channel_count = 1;

        liblsl.StreamInfo streamInfo = new liblsl.StreamInfo(StreamName, StreamType, channel_count, liblsl.IRREGULAR_RATE, liblsl.channel_format_t.cf_string, UniqueID);

        // TODO 2 - Fill in the stream header using info obtained from MExperimentController.
        liblsl.XMLElement streamInfoXML = streamInfo.desc();

        /*
         * foreach (GameObject target in MExperimentController.instance.taskInfo.animalHolder)
         * {
         *  obj_map.Add(MExperimentController.instance.taskInfo.animalHolder.IndexOf(target), target.name);
         * }
         */
        List <IDictionary <int, string> > metadata_dicts = new List <IDictionary <int, string> >
        {
            phase_map, task_type_map, countermand_map, cuedPositionIndex, targetPositionIndex, obj_map
        };
        // Insert names of lists ..
        IDictionary <string, IDictionary <int, string> > metadata_dicts_names = new Dictionary <string, IDictionary <int, string> >
        {
            { "phase_map", phase_map },
            { "task_type_map", task_type_map },
            { "countermand_map", countermand_map },
            { "cuedPositionIndex", cuedPositionIndex },
            { "targetPositionIndex", targetPositionIndex },
            { "obj_map", obj_map }
        };

        foreach (var map_name in metadata_dicts_names)
        {
            liblsl.XMLElement map_el = streamInfo.desc().append_child(map_name.Key);
            foreach (var property in map_name.Value)
            {
                map_el = map_el.append_child_value(property.Key.ToString(), property.Value);
                // Debug.Log(property.Key.ToString() + property.Value);
                // System.Console.WriteLine(property.Key.ToString() + property.Value);
            }
        }
        ;

        // 3 - Create the stream and push the first event.
        outlet = new liblsl.StreamOutlet(streamInfo);
        // string[] events_array = { "Begin event stream." };
        // outlet.push_sample(events_array);

        // 4 - Register as a listener for MExperimentController publish events.
        GetComponent <WisconsinExperimentController>().OnPublish += OnPublish;

        // Test desc XML header: resolve the stream and open an inlet
        liblsl.StreamInfo[] results = liblsl.resolve_stream("name", StreamName);
        liblsl.StreamInlet  inlet   = new liblsl.StreamInlet(results[0]);
        liblsl.StreamInfo   inf     = inlet.info();
        Debug.Log("The stream's XML meta-data is: ");
        Debug.Log(inf.as_xml());
    }