public static void Main(string[] args) { // wait until an EEG stream shows up StreamInfo[] results = LSL.LSL.resolve_stream("type", "EEG"); // open an inlet, with post-processing enabled, and print meta-data // Note: The use of post-processing makes it impossible to recover // the original timestamps and is not recommended for applications // that store data to disk. using StreamInlet inlet = new StreamInlet(results[0], postproc_flags: processing_options_t.proc_ALL); results.DisposeArray(); System.Console.Write(inlet.info().as_xml()); // read samples float[,] buffer = new float[512, 8]; double[] timestamps = new double[512]; while (!Console.KeyAvailable) { 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(); } } }
void SetBoardProperties(StreamInlet inlet) { var info = inlet.info(); BoardId = int.Parse(info.desc().child_value("boardId")); SampleRate = int.Parse(info.desc().child_value("sampleRate")); }
/// <summary> /// Read from the LSL stream for server status /// </summary> async Task RunReadStatusPortAsync(CancellationToken cancelToken) { ReportNetworkTimeInterval.Restart(); StreamInlet inlet = null; try { inlet = new StreamInlet(StatusStream); cancelToken.Register(() => inlet.close_stream()); inlet.open_stream(); SyncedTime = false; SetBoardProperties(inlet); Log?.Invoke(this, new LogEventArgs(HostName, this, "RunReadStatusPortAsync", $"Create LSL stream for status on host {HostName}.", LogLevel.DEBUG)); HatConnectionChanged?.Invoke(this, new HatConnectionEventArgs(HatConnectionState.Discovered, HostName, "", BoardId, SampleRate)); string[,] samples = new string[32, 1]; double[] timestamps = new double[32]; // spin until canceled while (!cancelToken.IsCancellationRequested) { await Task.Delay(StatusReadingDelay); try { var sampleCount = inlet.pull_chunk(samples, timestamps); if (sampleCount > 0 && (samples[sampleCount - 1, 0].Length > 0)) { await ParseServerStatus(samples[sampleCount - 1, 0]); } } catch (ObjectDisposedException) { } catch (Exception ex) { Log?.Invoke(this, new LogEventArgs(HostName, this, "RunReadStatusPortAsync", ex, LogLevel.WARN)); } } } catch (OperationCanceledException) { } catch (Exception e) { Log?.Invoke(this, new LogEventArgs(this, "RunReadStatusPortAsync", e, LogLevel.FATAL)); } finally { if (inlet != null) { inlet.close_stream(); } } }
public static void Main(string[] args) { { using StreamInfo inf_ = new StreamInfo("Test", "EEG", 8, 100, channel_format_t.cf_double64, "test1234"); Console.Out.WriteLine("Test"); } // create a new StreamInfo and declare some meta-data (in accordance with XDF format) using StreamInfo info = new StreamInfo("MetaTester", "EEG", 8, 100, channel_format_t.cf_float32, "myuid323457"); 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 StreamOutlet outlet = new StreamOutlet(info); // === the following could run on another computer === // resolve the stream and open an inlet StreamInfo[] results = LSL.LSL.resolve_stream("name", "MetaTester"); using StreamInlet inlet = new StreamInlet(results[0]); results.DisposeArray(); // get the full stream info (including custom meta-data) and dissect it using 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:"); 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(); }
/// <summary> /// Run function for reading data on LSL multicast data port /// </summary> async Task RunReadDataPortAsync(CancellationToken cancelToken) { StreamInlet inlet = null; try { int maxChunkLen = (int)((SampleRate * 1.5) / ReadingDelay); inlet = new StreamInlet(DataStream, 360, maxChunkLen); cancelToken.Register(() => inlet.close_stream()); inlet.open_stream(); Log?.Invoke(this, new LogEventArgs(HostName, this, "RunReadDataPortAsync", $"Create LSL data stream for host {HostName}.", LogLevel.DEBUG)); double[,] buffer = new double[512, SampleSize]; double[] timestamps = new double[512]; // spin until canceled while (!cancelToken.IsCancellationRequested) { await Task.Delay(ReadingDelay); try { int num = inlet.pull_chunk(buffer, timestamps); ProcessChunk(buffer, num); } catch (ObjectDisposedException) { } catch (Exception ex) { Log?.Invoke(this, new LogEventArgs(HostName, this, "RunReadDataPortAsync", ex, LogLevel.WARN)); } } } catch (OperationCanceledException) { } catch (Exception e) { Log?.Invoke(this, new LogEventArgs(this, "RunReadDataPortAsync", e, LogLevel.FATAL)); } finally { if (inlet != null) { inlet.close_stream(); } } }
public static void Main(string[] args) { // wait until an EEG stream shows up StreamInfo[] results = LSL.LSL.resolve_stream("type", "Markers"); // open an inlet and print meta-data using StreamInlet inlet = new StreamInlet(results[0]); results.DisposeArray(); Console.Write(inlet.info().as_xml()); // read samples string[] sample = new string[1]; while (!Console.KeyAvailable) { inlet.pull_sample(sample); Console.WriteLine(sample[0]); } }
public static void Main(string[] args) { // wait until an EEG stream shows up StreamInfo[] results = LSL.LSL.resolve_stream("type", "EEG"); // open an inlet and print some interesting info about the stream (meta-data, etc.) using StreamInlet inlet = new StreamInlet(results[0]); results.DisposeArray(); System.Console.Write(inlet.info().as_xml()); // read samples float[] sample = new float[8]; while (!System.Console.KeyAvailable) { inlet.pull_sample(sample); foreach (float f in sample) { System.Console.Write("\t{0}", f); } System.Console.WriteLine(); } }
public LSLStream(StreamInfo streamInfo, bool customts) { this.StreamInfo = streamInfo; this.streamInlet = new StreamInlet(streamInfo); //this.streamOutlet = new StreamOutlet(streamInfo); this.customts = customts; //this shouldn't be hard coded like this, but it keeps things more consistent with the old data format switch (streamInfo.name()) { case "FixationBegin": filename = "FixationBeg"; datasource = "EYETRACKER"; datatype = "Begin"; streamtype = "Fixation"; header = "DataType,X,Y,DeviceTimestamp, LSLTimestamp, AdjustedUnix" + Environment.NewLine; break; case "FixationData": filename = "FixationDat"; datasource = "EYETRACKER"; datatype = "Data"; streamtype = "Fixation"; header = "DataType,X,Y,DeviceTimestamp, LSLTimestamp, AdjustedUnix" + Environment.NewLine; break; case "FixationEnd": filename = "FixationEnd"; datasource = "EYETRACKER"; datatype = "End"; streamtype = "Fixation"; header = "DataType,X,Y,DeviceTimestamp, LSLTimestamp, AdjustedUnix" + Environment.NewLine; break; case "GazeData": filename = "GazeData"; datasource = "EYETRACKER"; datatype = "Gaze"; streamtype = "Gaze"; header = "X,Y,DeviceTimestamp, LSLTimestamp, AdjustedUnix" + Environment.NewLine; break; case "Debug": filename = "DebugData"; datasource = "DEBUG"; datatype = "Debug"; streamtype = "Debug"; header = "VAL, LSLTimestamp, AdjustedUnix" + Environment.NewLine; break; case "Debug2": filename = "Debug2Data"; datasource = "DEBUG2"; datatype = "Debug"; streamtype = "Debug"; header = "VAL, LSLTimestamp, AdjustedUnix" + Environment.NewLine; break; case "Quality": filename = "EEGQualityData"; datasource = "EEG"; datatype = "StreamQuality"; streamtype = "StreamQuality"; header = "C1,C2,C3,C4,C5,C6,C7,C8,Timestamp, AdjustedUnix" + Environment.NewLine; break; default: filename = "EEGData"; datasource = "EEG"; datatype = "EEG"; streamtype = "EEG"; header = "C1,C2,C3,C4,C5,C6,C7,C8,Timestamp, AdjustedUnix" + Environment.NewLine; break; } }