DataHub: Difference between revisions

Jump to navigation Jump to search
mNo edit summary
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Infobox software
{{Infobox software
| name                  = DataHub
| name                  = Lab Streaming Layer
| developer              = Christian Kothe; Chadwick Boulay.
| developer              = Christian Kothe; Chadwick Boulay.
| status                = -in development-
| status                = -in development-
Line 13: Line 13:
{{Infobox tsg
{{Infobox tsg
   | downloads          = {{bulleted list
   | downloads          = {{bulleted list
       | [https://surfdrive.surf.nl/files/index.php/s/zSpGD53mDQGuPKW viewer & streamer]
       | {{Surfdrive|https://surfdrive.surf.nl/s/GLSnbBaYsbEWjPX|Viewer & Streamer}}
     }}
     }}
   | manuals            = {{bulleted list
   | manuals            = {{bulleted list
Line 21: Line 21:
   }}
   }}
   | templates            = {{bulleted list
   | templates            = {{bulleted list
       | [https://surfdrive.surf.nl/files/index.php/s/qggfMMKsnUIDO0k example scripts (zip)]
       | {{Surfdrive|https://surfdrive.surf.nl/s/gPenWNAqq8AXa7x|Example Scripts}}
   }}
   }}
}}
}}
Line 39: 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 47: 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 python3.10
#!/usr/bin/env python3.10
Line 53: Line 53:


import time
import time
import numpy as np
import random
import keyboard
import keyboard
import random
from pylsl import StreamInfo, StreamOutlet
from pylsl import StreamInfo, StreamOutlet, local_clock
from LSLsettings import MarkerStreamSettings, DynamicMultiChannelStreamSettings


print(f"Setting up streams...")
from pylsl import local_clock
marker_settings = MarkerStreamSettings()


# info marker StreamInfo, outlet
# --- Setup Marker Stream ---
print("Setting up marker stream...")
marker_info = StreamInfo(
marker_info = StreamInfo(
     name=marker_settings.stream_name,
     name="MarkerStream",
     type=marker_settings.stream_type,
     type="Markers",
     channel_count=marker_settings.channel_count,
     channel_count=1,
     nominal_srate=marker_settings.sample_rate,
     nominal_srate=0, # Irregular sampling
     channel_format=marker_settings.channel_format,
     channel_format="string",
     source_id=marker_settings.source_id
     source_id="MarkerSource"
)
)
marker_outlet = StreamOutlet(marker_info, chunk_size=marker_settings.push_chunk_size)
marker_outlet = StreamOutlet(marker_info, chunk_size=1)


data_settings = DynamicMultiChannelStreamSettings(
# --- Setup Data Stream ---
    n_channels=4,
print("Setting up data stream...")
     stream_name="TestStream",
data_info = StreamInfo(
     stream_type="TestData",
     name="TestStream",
     sample_rate=100,
     type="TestData",
     channel_names=["A", "B", "C", "D"]
     channel_count=4,
    nominal_srate=100,
     channel_format="float32",
    source_id="TestStream_Source"
)
)


# info data StreamInfo, outlet
channels = data_info.desc().append_child("channels")
data_info = StreamInfo(
for name in ["A", "B", "C", "D"]:
    name=data_settings.stream_name,
     chan = channels.append_child("channel")
    type=data_settings.stream_type,
     chan.append_child_value("name", name)
     channel_count=data_settings.channel_count,
     chan.append_child_value("unit", "unitless")
     nominal_srate=data_settings.sample_rate,
     chan.append_child_value("type", "TestData")
     channel_format=data_settings.channel_format,
     source_id=data_settings.source_id
)
data_outlet = StreamOutlet(data_info, chunk_size=data_settings.push_chunk_size)


running = True
data_outlet = StreamOutlet(data_info, chunk_size=1)
marker_outlet.push_sample(["Start"])
buffer_dtype = object if data_settings.channel_format == "string" else float
buffer_in = np.array(data_settings.default_buffer, dtype=buffer_dtype)


# --- Start Streaming ---
print("Start streaming... Press 'q' to stop.")
print("Start streaming... Press 'q' to stop.")
marker_outlet.push_sample(["Start"])


while not(keyboard.is_pressed('q')):
while not keyboard.is_pressed('q'):
 
     random_numbers = [random.randint(1, 2) for _ in range(4)]
     random_numbers = [random.randint(0, 1) for _ in range(4)]
    random_numbers = [num + 1 for num in random_numbers]
     data_outlet.push_sample(random_numbers)
     data_outlet.push_sample(random_numbers)
 
     time.sleep(0.01)
     time.sleep(data_settings.push_interval)


marker_outlet.push_sample(["Stop"])
marker_outlet.push_sample(["Stop"])
 
print("Streaming stopped.")
</syntaxhighlight>
</syntaxhighlight>