DataHub: Difference between revisions

Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Infobox software
{{Infobox software
| name                  = DataHub
| name                  = Lab Streaming Layer
| logo                  =
| screenshot            =
| caption                =
| developer              = Christian Kothe; Chadwick Boulay.
| developer              = Christian Kothe; Chadwick Boulay.
| released              = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
| discontinued          =
| latest release version =
| latest release date    = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
| latest preview version =
| latest preview date    = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
| installed version      =
| installed version date = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
| status                = -in development-
| status                = -in development-
| programming language  = C, C++, Python, Java, C#, MATLAB
| programming language  = C, C++, Python, Java, C#, MATLAB
| operating system      = Windows, Linux, MacOS, Android, iOS
| operating system      = Windows, Linux, MacOS, Android, iOS
| platform              =
| size                  =
| language              =
| genre                  = Data collection
| genre                  = Data collection
| license                = Open source
| license                = Open source
| website                = [https://labstreaminglayer.readthedocs.io/info/intro.html LSL webpage]
| website                = [https://labstreaminglayer.readthedocs.io/info/intro.html LSL webpage]
| resources              =  
}}
  {{Infobox tsg
 
    | child              = yes
=== Resources ===
    | downloads          =
{{Infobox tsg
    | manuals            = {{bulleted list
  | downloads          = {{bulleted list
        | [https://docs.openbci.com/ Documentation]
      | {{Surfdrive|https://surfdrive.surf.nl/s/GLSnbBaYsbEWjPX|Viewer & Streamer}}
        | [https://sccn.ucsd.edu/~mgrivich/LSL_Validation.html LSL Validation]
        | [https://labstreaminglayer.readthedocs.io/info/supported_devices.html Supported Devices and Tools]
    }}
    | header2            = Templates
    | data2              = {{bulleted list
        | [https://surfdrive.surf.nl/files/index.php/s/qggfMMKsnUIDO0k example scripts (zip)]
     }}
     }}
  | manuals            = {{bulleted list
      | [https://labstreaminglayer.readthedocs.io/ Documentation]
      | [https://sccn.ucsd.edu/~mgrivich/LSL_Validation.html LSL Validation]
      | [https://labstreaminglayer.readthedocs.io/info/supported_devices.html Supported Devices and Tools]
  }}
  | templates            = {{bulleted list
      | {{Surfdrive|https://surfdrive.surf.nl/s/gPenWNAqq8AXa7x|Example Scripts}}
   }}
   }}
}}
}}
Line 52: Line 39:


===Versions===
===Versions===
The TSG uses the version 1.15.0. Open a command and type the following to find the version used:
Pylsl version 1.16.2 is installed on our [[Lab Computer]]s. Open a command and type the following to find the version used:


<code style="background-color:#000; color:#fff; padding:1px 3px;">c:>python</code><br/>
<code style="background-color:#000; color:#fff; padding:1px 3px;">c:>python</code><br/>
Line 60: Line 47:
==Usage==
==Usage==
=== Python ===
=== Python ===
A short example for sending lsl streaming data:
Example demonstrating how to send LSL stream and marker data:
<syntaxhighlight lang="python" line>
<syntaxhighlight lang="python" line>
#!/usr/bin/env python
#!/usr/bin/env python3.10
# -*- coding: utf-8 -*-


import threading
import time
import random
import keyboard
from pylsl import StreamInfo, StreamOutlet
from pylsl import StreamInfo, StreamOutlet


def getData():
from pylsl import local_clock
    while running:
        buffer_in = getSensorData()
        send_data = True
        time.sleep(0.001)


info = StreamInfo(
# --- Setup Marker Stream ---
     name='MyStream',  
print("Setting up marker stream...")
     type='COP',  
marker_info = StreamInfo(
     channel_count=4,  
     name="MarkerStream",
     nominal_srate = 200,  
     type="Markers",
     source_id='BalanceBoard_stream'
     channel_count=1,
    )
     nominal_srate=0,  # Irregular sampling
outlet = StreamOutlet(info)  
    channel_format="string",
     source_id="MarkerSource"
)
marker_outlet = StreamOutlet(marker_info, chunk_size=1)


threading.Thread(target=getData).start()
# --- Setup Data Stream ---
while running == True:
print("Setting up data stream...")
if send_data:
data_info = StreamInfo(
outlet.push_chunk(buffer_in)
    name="TestStream",
send_data = False
    type="TestData",
</syntaxhighlight>
    channel_count=4,
    nominal_srate=100,
    channel_format="float32",
    source_id="TestStream_Source"
)
 
channels = data_info.desc().append_child("channels")
for name in ["A", "B", "C", "D"]:
    chan = channels.append_child("channel")
    chan.append_child_value("name", name)
    chan.append_child_value("unit", "unitless")
    chan.append_child_value("type", "TestData")


A short example for receiving lsl data:
data_outlet = StreamOutlet(data_info, chunk_size=1)
<syntaxhighlight lang="python" line>
#!/usr/bin/env python


from pylsl import StreamInlet, resolve_stream
# --- Start Streaming ---
print("Start streaming... Press 'q' to stop.")
marker_outlet.push_sample(["Start"])


streams = resolve_stream('name', 'MyStream')
while not keyboard.is_pressed('q'):
#streams = resolve_streams()
    random_numbers = [random.randint(1, 2) for _ in range(4)]
    data_outlet.push_sample(random_numbers)
    time.sleep(0.01)


inlet = StreamInlet(streams[0])
marker_outlet.push_sample(["Stop"])
while True:
print("Streaming stopped.")
    sample, timestamp = inlet.pull_sample()
    print(timestamp, sample)
</syntaxhighlight>
</syntaxhighlight>


Line 128: Line 128:
</syntaxhighlight>
</syntaxhighlight>


A short example for sending lsl streaming data:
A short example for receiving lsl streaming data:
<syntaxhighlight lang="matlab" line>
<syntaxhighlight lang="matlab" line>
%% instantiate the library
%% instantiate the library