Skip to content

Commit 55098eb

Browse files
author
David Medine
committed
first commit to newly hosted repo
0 parents  commit 55098eb

9 files changed

Lines changed: 1419 additions & 0 deletions

LSL.cs

Lines changed: 1188 additions & 0 deletions
Large diffs are not rendered by default.

examples/HandleMetaData.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Threading;
3+
using LSL;
4+
5+
namespace ConsoleApplication1
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
// 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++)
16+
chns.append_child("channel")
17+
.append_child_value("label", labels[k])
18+
.append_child_value("unit", "microvolts")
19+
.append_child_value("type","EEG");
20+
info.desc().append_child_value("manufacturer","SCCN");
21+
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+
26+
// create outlet for the stream
27+
liblsl.StreamOutlet outlet = new liblsl.StreamOutlet(info);
28+
29+
// === the following could run on another computer ===
30+
31+
// 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]);
34+
// get the full stream info (including custom meta-data) and dissect it
35+
liblsl.StreamInfo inf = inlet.info();
36+
Console.WriteLine("The stream's XML meta-data is: ");
37+
Console.WriteLine(inf.as_xml());
38+
Console.WriteLine("The manufacturer is: " + inf.desc().child_value("manufacturer"));
39+
Console.WriteLine("The cap circumference is: " + inf.desc().child("cap").child_value("size"));
40+
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++) {
43+
Console.WriteLine(" " + ch.child_value("label"));
44+
ch = ch.next_sibling();
45+
}
46+
Console.ReadKey();
47+
}
48+
}
49+
}

examples/ReceiveData.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Threading;
3+
using LSL;
4+
5+
namespace ConsoleApplication1
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
// wait until an EEG stream shows up
12+
liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "EEG");
13+
14+
// open an inlet and print some interesting info about the stream (meta-data, etc.)
15+
liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
16+
System.Console.Write(inlet.info().as_xml());
17+
18+
// read samples
19+
float[] sample = new float[8];
20+
while (true)
21+
{
22+
inlet.pull_sample(sample);
23+
foreach (float f in sample)
24+
System.Console.Write("\t{0}",f);
25+
System.Console.WriteLine();
26+
}
27+
28+
System.Console.ReadKey();
29+
}
30+
}
31+
}

examples/ReceiveDataInChunks.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Threading;
3+
using LSL;
4+
5+
namespace ConsoleApplication1
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
// wait until an EEG stream shows up
12+
liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "EEG");
13+
14+
// open an inlet and print meta-data
15+
liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
16+
System.Console.Write(inlet.info().as_xml());
17+
18+
// read samples
19+
float[,] buffer = new float[512, 8];
20+
double[] timestamps = new double[512];
21+
while (true)
22+
{
23+
int num = inlet.pull_chunk(buffer,timestamps);
24+
for (int s = 0; s < num; s++)
25+
{
26+
for (int c = 0; c < 8; c++)
27+
Console.Write("\t{0}", buffer[s, c]);
28+
Console.WriteLine();
29+
}
30+
}
31+
}
32+
}
33+
}

examples/ReceiveStringMarkers.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Threading;
3+
using LSL;
4+
5+
namespace ConsoleApplication1
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
// wait until an EEG stream shows up
12+
liblsl.StreamInfo[] results = liblsl.resolve_stream("type", "Markers");
13+
14+
// open an inlet and print meta-data
15+
liblsl.StreamInlet inlet = new liblsl.StreamInlet(results[0]);
16+
System.Console.Write(inlet.info().as_xml());
17+
18+
// read samples
19+
string[] sample = new string[1];
20+
while (true)
21+
{
22+
inlet.pull_sample(sample);
23+
System.Console.WriteLine(sample[0]);
24+
}
25+
}
26+
}
27+
}

examples/SendData.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.Threading;
3+
using LSL;
4+
5+
namespace ConsoleApplication1
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
Random rnd = new Random();
12+
13+
// create stream info and outlet
14+
liblsl.StreamInfo info = new liblsl.StreamInfo("BioSemi", "EEG", 8, 100, liblsl.channel_format_t.cf_float32, "sddsfsdf");
15+
liblsl.StreamOutlet outlet = new liblsl.StreamOutlet(info);
16+
float[] data = new float[8];
17+
while (true)
18+
{
19+
// generate random data and send it
20+
for (int k = 0; k < data.Length; k++)
21+
data[k] = rnd.Next(-100, 100);
22+
outlet.push_sample(data);
23+
System.Threading.Thread.Sleep(10);
24+
}
25+
26+
System.Console.ReadKey();
27+
}
28+
}
29+
}

examples/SendDataInChunks.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Threading;
3+
using LSL;
4+
5+
namespace ConsoleApplication1
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
Random rnd = new Random();
12+
// create stream info and outlet
13+
liblsl.StreamInfo info = new liblsl.StreamInfo("BioSemi", "EEG", 8, 100, liblsl.channel_format_t.cf_float32, "sddsfsdf");
14+
liblsl.StreamOutlet outlet = new liblsl.StreamOutlet(info);
15+
16+
// send data in chunks of 10 samples and 8 channels
17+
float[,] data = new float[10, 8];
18+
while (true)
19+
{
20+
for (int s = 0; s < 10; s++)
21+
for (int c = 0; c < 8; c++)
22+
data[s, c] = rnd.Next(-100, 100);
23+
outlet.push_chunk(data);
24+
System.Threading.Thread.Sleep(100);
25+
}
26+
}
27+
}
28+
}

examples/SendStringMarkers.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Threading;
3+
using LSL;
4+
5+
namespace ConsoleApplication1
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
// create stream info and outlet
12+
liblsl.StreamInfo inf = new liblsl.StreamInfo("Test1", "Markers", 1, 0, liblsl.channel_format_t.cf_string, "giu4569");
13+
liblsl.StreamOutlet outl = new liblsl.StreamOutlet(inf);
14+
15+
Random rnd = new Random();
16+
string[] strings = new string[] { "Test", "ABC", "123" };
17+
string[] sample = new string[1];
18+
for (int k = 0; ; k++)
19+
{
20+
// send a marker and wait for a random interval
21+
sample[0] = strings[k % 3];
22+
outl.push_sample(sample);
23+
System.Threading.Thread.Sleep(rnd.Next(1000));
24+
}
25+
}
26+
}
27+
}

readme.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The is the C# interface to the lab streaming layer. To use it, you need to include the file LSL.cs in
2+
your project, and make sure that the library liblsl32.dll is found (e.g., in your application's root
3+
directory or in a system path).
4+
5+
If you are deploying on a platform that requires a different binary than liblsl32.dll (e.g., liblsl64.so
6+
on 64-bit Linux, or liblsl64.dylib on Mac OS, then you need to replace the libname constant in LSL.cs
7+
by the corresponding file name).

0 commit comments

Comments
 (0)