Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,809 changes: 878 additions & 931 deletions LSL.cs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions examples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<PropertyGroup>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
</Project>
48 changes: 27 additions & 21 deletions examples/HandleMetaData/HandleMetaData.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@
using System;
using System.Threading;
using LSL;

namespace ConsoleApplication1
namespace LSLExamples
{
class Program
static class HandleMetaData
{
static void Main(string[] args)
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)
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++)
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");
.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");
.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);
StreamOutlet outlet = new 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]);
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
liblsl.StreamInfo inf = inlet.info();
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:");
liblsl.XMLElement ch = inf.desc().child("channels").child("channel");
for (int k=0;k<info.channel_count();k++) {
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();
}
Expand Down
13 changes: 7 additions & 6 deletions examples/HandleMetaData/HandleMetaData.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\liblsl.csproj" />
</ItemGroup>
<PropertyGroup>
<Product>HandleMetaData</Product>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<Version>1.14</Version>
<LangVersion>8.0</LangVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\liblsl.csproj" />
</ItemGroup>
</Project>
18 changes: 18 additions & 0 deletions examples/LSLExamples.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- All-in-one example project.
It contains a launcher for all examples in the subdirectories that
compiles to a single .exe, prints some information about the wrapper and
passes all arguments through to the example specified as first command line
argument. -->
<PropertyGroup>
<TargetFramework>netcoreapp5.0</TargetFramework>
<Product>Labstreaminglayer C# examples</Product>
<Version>1.14</Version>
<LangVersion>8.0</LangVersion>
<OutputType>Exe</OutputType>
<StartupObject>LSLExamples.EntryPoint</StartupObject>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\liblsl.csproj" />
</ItemGroup>
</Project>
29 changes: 29 additions & 0 deletions examples/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Linq;
using System.Reflection;

namespace LSLExamples
{
static class EntryPoint
{
public static void Main(string[] args) {
var examples = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.Namespace =="LSLExamples").ToDictionary(e=>e.Name, e=>e);

var WrapperVersion = Assembly.GetAssembly(typeof(LSL.LSL)).GetName().Version.ToString();
Console.Out.Write("Wrapper version: ");
Console.Out.WriteLine(WrapperVersion);
Console.Out.Write("liblsl version: ");
Console.Out.WriteLine(LSL.LSL.library_version());
if (args.Length < 1 || !examples.ContainsKey(args[0])) {
Console.Out.WriteLine("\nNot enough arguments. Valid examples:");
foreach(var name in examples.Keys) Console.Out.WriteLine(name);
return;
}
var method = examples[args[0]].GetMethod("Main", BindingFlags.Public|BindingFlags.Static);
Console.Out.WriteLine(method);
method.Invoke(null, new object[]{ args});
}
}
}

19 changes: 8 additions & 11 deletions examples/ReceiveData/ReceiveData.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
using System;
using System.Threading;
using LSL;

namespace ConsoleApplication1
namespace LSLExamples
{
class Program
static class ReceiveData
{
static void Main(string[] args)
public static void Main(string[] args)
{
// wait until an EEG stream shows up
liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "EEG");
StreamInfo[] results = LSL.LSL.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]);
using StreamInlet inlet = new StreamInlet(results[0]);
results.DisposeArray();
System.Console.Write(inlet.info().as_xml());

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

System.Console.ReadKey();
}
}
}
16 changes: 9 additions & 7 deletions examples/ReceiveData/ReceiveData.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\liblsl.csproj" />
</ItemGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Product>ReceiveData</Product>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<Product>Labstreaminglayer C# examples</Product>
<Version>1.14</Version>
<LangVersion>8.0</LangVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\liblsl.csproj" />
</ItemGroup>
</Project>
18 changes: 9 additions & 9 deletions examples/ReceiveDataInChunks/ReceiveDataInChunks.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
using System;
using System.Threading;
using LSL;

namespace ConsoleApplication1
namespace LSLExamples
{
class Program
static class ReceiveDataInChunks
{
static void Main(string[] args)
public static void Main(string[] args)
{
// wait until an EEG stream shows up
liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "EEG");
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.
liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0],
postproc_flags: liblsl.processing_options_t.proc_ALL);
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 (true)
while (!Console.KeyAvailable)
{
int num = inlet.pull_chunk(buffer,timestamps);
int num = inlet.pull_chunk(buffer, timestamps);
for (int s = 0; s < num; s++)
{
for (int c = 0; c < 8; c++)
Expand Down
14 changes: 8 additions & 6 deletions examples/ReceiveDataInChunks/ReceiveDataInChunks.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\liblsl.csproj" />
</ItemGroup>
<PropertyGroup>
<Product>ReceiveDataInChunks</Product>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<Product>Labstreaminglayer C# examples</Product>
<Version>1.14</Version>
<LangVersion>8.0</LangVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\liblsl.csproj" />
</ItemGroup>
</Project>
18 changes: 9 additions & 9 deletions examples/ReceiveStringMarkers/ReceiveStringMarkers.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using System;
using System.Threading;
using LSL;

namespace ConsoleApplication1
namespace LSLExamples
{
class Program
static class ReceiveStringMarkers
{
static void Main(string[] args)
public static void Main(string[] args)
{
// wait until an EEG stream shows up
liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "Markers");
StreamInfo[] results = LSL.LSL.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());
using StreamInlet inlet = new StreamInlet(results[0]);
results.DisposeArray();
Console.Write(inlet.info().as_xml());

// read samples
string[] sample = new string[1];
while (true)
while (!Console.KeyAvailable)
{
inlet.pull_sample(sample);
System.Console.WriteLine(sample[0]);
Console.WriteLine(sample[0]);
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions examples/ReceiveStringMarkers/ReceiveStringMarkers.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\liblsl.csproj" />
</ItemGroup>
<PropertyGroup>
<Product>ReceiveStringMarkers</Product>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<Product>Labstreaminglayer C# examples</Product>
<Version>1.14</Version>
<LangVersion>8.0</LangVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\liblsl.csproj" />
</ItemGroup>
</Project>
16 changes: 7 additions & 9 deletions examples/SendData/SendData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@
using System.Threading;
using LSL;

namespace ConsoleApplication1
namespace LSLExamples
{
class Program
static class SendData
{
static void Main(string[] args)
public static void Main(string[] args)
{
Random rnd = new Random();

// create stream info and outlet
liblsl.StreamInfo info = new liblsl.StreamInfo("TestCSharp", "EEG", 8, 100, liblsl.channel_format_t.cf_float32, "sddsfsdf");
liblsl.StreamOutlet outlet = new liblsl.StreamOutlet(info);
using StreamInfo info = new StreamInfo("TestCSharp", "EEG", 8, 100, channel_format_t.cf_float32, "sddsfsdf");
using StreamOutlet outlet = new StreamOutlet(info);
float[] data = new float[8];
while (true)
while (!Console.KeyAvailable)
{
// generate random data and send it
for (int k = 0; k < data.Length; k++)
data[k] = rnd.Next(-100, 100);
outlet.push_sample(data);
System.Threading.Thread.Sleep(10);
Thread.Sleep(10);
}

System.Console.ReadKey();
}
}
}
14 changes: 8 additions & 6 deletions examples/SendData/SendData.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\liblsl.csproj" />
</ItemGroup>
<PropertyGroup>
<Product>SendData</Product>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<Product>Labstreaminglayer C# examples</Product>
<Version>1.14</Version>
<LangVersion>8.0</LangVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\liblsl.csproj" />
</ItemGroup>
</Project>
Loading