Skip to content

Commit a1f2a0c

Browse files
authored
Merge pull request #12 from labstreaminglayer/restructure
Restructure the wrapper
2 parents 3fe3201 + 4786512 commit a1f2a0c

File tree

19 files changed

+1065
-1050
lines changed

19 files changed

+1065
-1050
lines changed

LSL.cs

Lines changed: 878 additions & 931 deletions
Large diffs are not rendered by default.

examples/Directory.Build.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
3+
<PropertyGroup>
4+
<LangVersion>8.0</LangVersion>
5+
</PropertyGroup>
6+
</Project>

examples/HandleMetaData/HandleMetaData.cs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,51 @@
11
using System;
2-
using System.Threading;
32
using LSL;
43

5-
namespace ConsoleApplication1
4+
namespace LSLExamples
65
{
7-
class Program
6+
static class HandleMetaData
87
{
9-
static void Main(string[] args)
8+
public static void Main(string[] args)
109
{
10+
{
11+
using StreamInfo inf_ = new StreamInfo("Test", "EEG", 8, 100, channel_format_t.cf_double64, "test1234");
12+
Console.Out.WriteLine("Test");
13+
}
1114
// create a new StreamInfo and declare some meta-data (in accordance with XDF format)
12-
liblsl.StreamInfo info = new liblsl.StreamInfo("MetaTester","EEG",8,100,liblsl.channel_format_t.cf_float32,"myuid323457");
13-
liblsl.XMLElement chns = info.desc().append_child("channels");
14-
String[] labels = {"C3","C4","Cz","FPz","POz","CPz","O1","O2"};
15-
for (int k=0;k<labels.Length;k++)
15+
using StreamInfo info = new StreamInfo("MetaTester", "EEG", 8, 100, channel_format_t.cf_float32, "myuid323457");
16+
XMLElement chns = info.desc().append_child("channels");
17+
String[] labels = { "C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2" };
18+
for (int k = 0; k < labels.Length; k++)
1619
chns.append_child("channel")
1720
.append_child_value("label", labels[k])
1821
.append_child_value("unit", "microvolts")
19-
.append_child_value("type","EEG");
20-
info.desc().append_child_value("manufacturer","SCCN");
22+
.append_child_value("type", "EEG");
23+
info.desc().append_child_value("manufacturer", "SCCN");
2124
info.desc().append_child("cap")
22-
.append_child_value("name","EasyCap")
23-
.append_child_value("size","54")
24-
.append_child_value("labelscheme","10-20");
25+
.append_child_value("name", "EasyCap")
26+
.append_child_value("size", "54")
27+
.append_child_value("labelscheme", "10-20");
2528

2629
// create outlet for the stream
27-
liblsl.StreamOutlet outlet = new liblsl.StreamOutlet(info);
28-
30+
StreamOutlet outlet = new StreamOutlet(info);
31+
2932
// === the following could run on another computer ===
30-
33+
3134
// resolve the stream and open an inlet
32-
liblsl.StreamInfo[] results = liblsl.resolve_stream("name","MetaTester");
33-
liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
35+
StreamInfo[] results = LSL.LSL.resolve_stream("name", "MetaTester");
36+
using StreamInlet inlet = new StreamInlet(results[0]);
37+
results.DisposeArray();
38+
3439
// get the full stream info (including custom meta-data) and dissect it
35-
liblsl.StreamInfo inf = inlet.info();
40+
using StreamInfo inf = inlet.info();
3641
Console.WriteLine("The stream's XML meta-data is: ");
3742
Console.WriteLine(inf.as_xml());
3843
Console.WriteLine("The manufacturer is: " + inf.desc().child_value("manufacturer"));
3944
Console.WriteLine("The cap circumference is: " + inf.desc().child("cap").child_value("size"));
4045
Console.WriteLine("The channel labels are as follows:");
41-
liblsl.XMLElement ch = inf.desc().child("channels").child("channel");
42-
for (int k=0;k<info.channel_count();k++) {
46+
XMLElement ch = inf.desc().child("channels").child("channel");
47+
for (int k = 0; k < info.channel_count(); k++)
48+
{
4349
Console.WriteLine(" " + ch.child_value("label"));
4450
ch = ch.next_sibling();
4551
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<ItemGroup>
3-
<ProjectReference Include="..\..\liblsl.csproj" />
4-
</ItemGroup>
52
<PropertyGroup>
6-
<Product>HandleMetaData</Product>
7-
<OutputType>Exe</OutputType>
8-
<TargetFramework>netcoreapp2.0</TargetFramework>
3+
<TargetFramework>net5.0</TargetFramework>
4+
<Version>1.14</Version>
5+
<LangVersion>8.0</LangVersion>
6+
<OutputType>Exe</OutputType>
97
</PropertyGroup>
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\liblsl.csproj" />
10+
</ItemGroup>
1011
</Project>

examples/LSLExamples.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<!-- All-in-one example project.
3+
It contains a launcher for all examples in the subdirectories that
4+
compiles to a single .exe, prints some information about the wrapper and
5+
passes all arguments through to the example specified as first command line
6+
argument. -->
7+
<PropertyGroup>
8+
<TargetFramework>netcoreapp5.0</TargetFramework>
9+
<Product>Labstreaminglayer C# examples</Product>
10+
<Version>1.14</Version>
11+
<LangVersion>8.0</LangVersion>
12+
<OutputType>Exe</OutputType>
13+
<StartupObject>LSLExamples.EntryPoint</StartupObject>
14+
</PropertyGroup>
15+
<ItemGroup>
16+
<ProjectReference Include="..\liblsl.csproj" />
17+
</ItemGroup>
18+
</Project>

examples/Main.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Linq;
3+
using System.Reflection;
4+
5+
namespace LSLExamples
6+
{
7+
static class EntryPoint
8+
{
9+
public static void Main(string[] args) {
10+
var examples = Assembly.GetExecutingAssembly().GetTypes()
11+
.Where(t => t.Namespace =="LSLExamples").ToDictionary(e=>e.Name, e=>e);
12+
13+
var WrapperVersion = Assembly.GetAssembly(typeof(LSL.LSL)).GetName().Version.ToString();
14+
Console.Out.Write("Wrapper version: ");
15+
Console.Out.WriteLine(WrapperVersion);
16+
Console.Out.Write("liblsl version: ");
17+
Console.Out.WriteLine(LSL.LSL.library_version());
18+
if (args.Length < 1 || !examples.ContainsKey(args[0])) {
19+
Console.Out.WriteLine("\nNot enough arguments. Valid examples:");
20+
foreach(var name in examples.Keys) Console.Out.WriteLine(name);
21+
return;
22+
}
23+
var method = examples[args[0]].GetMethod("Main", BindingFlags.Public|BindingFlags.Static);
24+
Console.Out.WriteLine(method);
25+
method.Invoke(null, new object[]{ args});
26+
}
27+
}
28+
}
29+
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
using System;
2-
using System.Threading;
31
using LSL;
42

5-
namespace ConsoleApplication1
3+
namespace LSLExamples
64
{
7-
class Program
5+
static class ReceiveData
86
{
9-
static void Main(string[] args)
7+
public static void Main(string[] args)
108
{
119
// wait until an EEG stream shows up
12-
liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "EEG");
10+
StreamInfo[] results = LSL.LSL.resolve_stream("type", "EEG");
1311

1412
// open an inlet and print some interesting info about the stream (meta-data, etc.)
15-
liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
13+
using StreamInlet inlet = new StreamInlet(results[0]);
14+
results.DisposeArray();
1615
System.Console.Write(inlet.info().as_xml());
1716

1817
// read samples
1918
float[] sample = new float[8];
20-
while (true)
19+
while (!System.Console.KeyAvailable)
2120
{
2221
inlet.pull_sample(sample);
2322
foreach (float f in sample)
24-
System.Console.Write("\t{0}",f);
23+
System.Console.Write("\t{0}", f);
2524
System.Console.WriteLine();
2625
}
27-
28-
System.Console.ReadKey();
2926
}
3027
}
3128
}
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
<ItemGroup>
3-
<ProjectReference Include="..\..\liblsl.csproj" />
4-
</ItemGroup>
1+
<Project Sdk="Microsoft.NET.Sdk">
52
<PropertyGroup>
6-
<Product>ReceiveData</Product>
7-
<OutputType>Exe</OutputType>
8-
<TargetFramework>netcoreapp2.0</TargetFramework>
3+
<TargetFramework>net5.0</TargetFramework>
4+
<Product>Labstreaminglayer C# examples</Product>
5+
<Version>1.14</Version>
6+
<LangVersion>8.0</LangVersion>
7+
<OutputType>Exe</OutputType>
98
</PropertyGroup>
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\liblsl.csproj" />
11+
</ItemGroup>
1012
</Project>

examples/ReceiveDataInChunks/ReceiveDataInChunks.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
using System;
2-
using System.Threading;
32
using LSL;
43

5-
namespace ConsoleApplication1
4+
namespace LSLExamples
65
{
7-
class Program
6+
static class ReceiveDataInChunks
87
{
9-
static void Main(string[] args)
8+
public static void Main(string[] args)
109
{
1110
// wait until an EEG stream shows up
12-
liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "EEG");
11+
StreamInfo[] results = LSL.LSL.resolve_stream("type", "EEG");
1312

1413
// open an inlet, with post-processing enabled, and print meta-data
1514
// Note: The use of post-processing makes it impossible to recover
1615
// the original timestamps and is not recommended for applications
1716
// that store data to disk.
18-
liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0],
19-
postproc_flags: liblsl.processing_options_t.proc_ALL);
17+
using StreamInlet inlet = new StreamInlet(results[0],
18+
postproc_flags: processing_options_t.proc_ALL);
19+
results.DisposeArray();
2020
System.Console.Write(inlet.info().as_xml());
2121

2222
// read samples
2323
float[,] buffer = new float[512, 8];
2424
double[] timestamps = new double[512];
25-
while (true)
25+
while (!Console.KeyAvailable)
2626
{
27-
int num = inlet.pull_chunk(buffer,timestamps);
27+
int num = inlet.pull_chunk(buffer, timestamps);
2828
for (int s = 0; s < num; s++)
2929
{
3030
for (int c = 0; c < 8; c++)
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<ItemGroup>
3-
<ProjectReference Include="..\..\liblsl.csproj" />
4-
</ItemGroup>
52
<PropertyGroup>
6-
<Product>ReceiveDataInChunks</Product>
7-
<OutputType>Exe</OutputType>
8-
<TargetFramework>netcoreapp2.0</TargetFramework>
3+
<TargetFramework>net5.0</TargetFramework>
4+
<Product>Labstreaminglayer C# examples</Product>
5+
<Version>1.14</Version>
6+
<LangVersion>8.0</LangVersion>
7+
<OutputType>Exe</OutputType>
98
</PropertyGroup>
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\liblsl.csproj" />
11+
</ItemGroup>
1012
</Project>

0 commit comments

Comments
 (0)