DataHub: Difference between revisions

Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(12 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/apps/files/?dir=/DistributionWiki/LabStreamingLayer&fileid=16159332014 viewer & streamer]
       | {{Surfdrive|https://surfdrive.surf.nl/s/GLSnbBaYsbEWjPX|Viewer & Streamer}}
     }}
     }}
   | manuals            = {{bulleted list
   | manuals            = {{bulleted list
Line 20: Line 20:
       | [https://labstreaminglayer.readthedocs.io/info/supported_devices.html Supported Devices and Tools]
       | [https://labstreaminglayer.readthedocs.io/info/supported_devices.html Supported Devices and Tools]
   }}
   }}
   | header2            = Templates
   | templates            = {{bulleted list
  | data2              = {{bulleted list
       | {{Surfdrive|https://surfdrive.surf.nl/s/gPenWNAqq8AXa7x|Example Scripts}}
       | [https://surfdrive.surf.nl/files/index.php/s/qggfMMKsnUIDO0k example scripts (zip)]
   }}
   }}
}}
}}
Line 40: 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 48: 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"
)


A short example for receiving lsl data:
channels = data_info.desc().append_child("channels")
<syntaxhighlight lang="python" line>
for name in ["A", "B", "C", "D"]:
#!/usr/bin/env python
    chan = channels.append_child("channel")
    chan.append_child_value("name", name)
    chan.append_child_value("unit", "unitless")
    chan.append_child_value("type", "TestData")
 
data_outlet = StreamOutlet(data_info, chunk_size=1)


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>