How to use the pylsl.StreamOutlet function in pylsl

To help you get started, we’ve selected a few pylsl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OpenBCI / OpenBCI_LSL / lib / streamerlsl.py View on Github external
new_locs = [loc for loc in locs.split(',')]

      chns = self.info_eeg.desc().child('channels')
      ch = chns.child("channel")
      for label in new_locs:
        ch.set_child_value('label', label)
        ch = ch.next_sibling()

      
      print("New Channel Montage:")
      print(str(new_locs))


      #create StreamOutlet
      self.outlet_eeg = StreamOutlet(self.info_eeg)
      self.outlet_aux = StreamOutlet(self.info_aux)
github alexandrebarachant / muse-lsl / stimulus_presentation / generate_N170.py View on Github external
import numpy as np
from pandas import DataFrame
from psychopy import visual, core, event
from pylsl import StreamInfo, StreamOutlet, local_clock

parser = OptionParser()
parser.add_option("-d", "--duration",
                  dest="duration", type='int', default=400,
                  help="duration of the recording in seconds.")

(options, args) = parser.parse_args()

# Create markers stream outlet
info = StreamInfo('Markers', 'Markers', 1, 0, 'int32', 'myuidw43536')
outlet = StreamOutlet(info)

markernames = [1, 2]
start = time()

# Set up trial parameters
n_trials = 2010
iti = 0.3
soa = 0.2
jitter = 0.2
record_duration = np.float32(options.duration)

# Setup trial list
image_type = np.random.binomial(1, 0.5, n_trials)
trials = DataFrame(dict(image_type=image_type,
                        timestamp=np.zeros(n_trials)))
github compmem / smile / smile / lsl.py View on Github external
"""
    if _got_pylsl:
        global _lsl_outlets

        s = "_"
        unique_identifier = s.join([server_name, server_type, str(nchans),
                                    str(suggested_freq), str(channel_format),
                                    str(unique_id)])

        if unique_identifier in _lsl_outlets.keys():
            return _lsl_outlets[unique_identifier]
        else:
            info = StreamInfo(server_name, server_type, nchans, suggested_freq,
                              channel_format, unique_id)
            _lsl_outlets[unique_identifier] = StreamOutlet(info)
            return _lsl_outlets[unique_identifier]
    else:
        print("Unable to setup LSL server! No sync pulses will be made.")
        return None
github alexandrebarachant / muse-lsl / muselsl / stream.py View on Github external
address = found_muse['address']
                name = found_muse['name']

    if not eeg_disabled:
        eeg_info = StreamInfo('Muse', 'EEG', MUSE_NB_EEG_CHANNELS, MUSE_SAMPLING_EEG_RATE, 'float32',
                              'Muse%s' % address)
        eeg_info.desc().append_child_value("manufacturer", "Muse")
        eeg_channels = eeg_info.desc().append_child("channels")

        for c in ['TP9', 'AF7', 'AF8', 'TP10', 'Right AUX']:
            eeg_channels.append_child("channel") \
                .append_child_value("label", c) \
                .append_child_value("unit", "microvolts") \
                .append_child_value("type", "EEG")

        eeg_outlet = StreamOutlet(eeg_info, LSL_EEG_CHUNK)

    if ppg_enabled:
        ppg_info = StreamInfo('Muse', 'PPG', MUSE_NB_PPG_CHANNELS, MUSE_SAMPLING_PPG_RATE,
                              'float32', 'Muse%s' % address)
        ppg_info.desc().append_child_value("manufacturer", "Muse")
        ppg_channels = ppg_info.desc().append_child("channels")

        for c in ['PPG1', 'PPG2', 'PPG3']:
            ppg_channels.append_child("channel") \
                .append_child_value("label", c) \
                .append_child_value("unit", "mmHg") \
                .append_child_value("type", "PPG")

        ppg_outlet = StreamOutlet(ppg_info, LSL_PPG_CHUNK)

    if acc_enabled:
github dbdq / neurodecode / pycnbi / utils / cnbi_lsl.py View on Github external
Sampling rate in Hz. Defaults to irregular sampling rate.
    stype:
        Signal type in string format
    source_id:
        If None, set to server name

    Returns
    -------
    outlet: LSL server object

    """
    if source_id is None:
        source_id = server_name
    sinfo = pylsl.StreamInfo(server_name, channel_count=n_channels, channel_format=channel_format,\
                           nominal_srate=nominal_srate, type=stype, source_id=source_id)
    return pylsl.StreamOutlet(sinfo)
github sccn / lsl_archived / LSL / liblsl-Python / examples / HandleMetadata.py View on Github external
# now attach some meta-data (in accordance with XDF format,
# see also code.google.com/p/xdf)
chns = info.desc().append_child("channels")
for label in ["C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"]:
    ch = chns.append_child("channel")
    ch.append_child_value("label", label)
    ch.append_child_value("unit", "microvolts")
    ch.append_child_value("type", "EEG")
info.desc().append_child_value("manufacturer", "SCCN")
cap = info.desc().append_child("cap")
cap.append_child_value("name", "EasyCap")
cap.append_child_value("size", "54")
cap.append_child_value("labelscheme", "10-20")

# create outlet for the stream
outlet = StreamOutlet(info)

# (...normally here one might start sending data into the outlet...)

# === the following could run on another computer ===

# first we resolve a stream whose name is MetaTester (note that there are
# other ways to query a stream, too - for instance by content-type)
results = resolve_stream("name", "MetaTester")

# open an inlet so we can read the stream's data (and meta-data)
inlet = StreamInlet(results[0])

# get the full stream info (including custom meta-data) and dissect it
info = inlet.info()
print("The stream's XML meta-data is: ")
print(info.as_xml())
github sccn / lsl_archived / Apps / PupilLabs / pupil_lsl_relay.py View on Github external
def _create_python_repr_lsl_outlet(self, name):
        """Create 1 channel python representation outlet"""
        stream_info = lsl.StreamInfo(
            name=name,
            type='Pupil Capture',
            channel_count=1,
            channel_format=lsl.cf_string,
            source_id='%s @ %s' % (name, self.g_pool.ipc_sub_url))
        self._append_channel_info(stream_info, ("Python Representation",))
        self._append_acquisition_info(stream_info)
        return lsl.StreamOutlet(stream_info)
github alexandrebarachant / muse-lsl / stimulus_presentation / generate_spatial_gratings.py View on Github external
parser = OptionParser()
parser.add_option("-d", "--duration",
                  dest="duration", type='int', default=400,
                  help="duration of the recording in seconds.")

(options, args) = parser.parse_args()

# Create markers stream outlet
info = StreamInfo('Markers', 'Markers', 3, 0, 'float32', 'myuidw43536')
channels = info.desc().append_child("channels")

for c in ['Frequency', 'Contrast', 'Orientation']:
    channels.append_child("channel") \
        .append_child_value("label", c)

outlet = StreamOutlet(info)

start = time()

# Set up trial parameters
n_trials = 2010
iti = 1.0
soa = 1.5
jitter = 0.5
record_duration = np.float32(options.duration)

# Setup trial list
frequency = np.random.binomial(1, 0.5, n_trials)
contrast = np.ones(n_trials, dtype=int)
orientation = np.random.randint(0, 4, n_trials) * 45

trials = pd.DataFrame(dict(frequency=frequency,
github dbdq / neurodecode / pycnbi / stream_player / stream_player.py View on Github external
print(i, ch)
        print('Trigger channel : %s' % event_ch)
    else:
        raise RuntimeError('Error while loading %s' % fif_file)

    # set server information
    sinfo = pylsl.StreamInfo(server_name, channel_count=n_channels, channel_format='float32',\
        nominal_srate=sfreq, type='EEG', source_id=server_name)
    desc = sinfo.desc()
    channel_desc = desc.append_child("channels")
    for ch in raw.ch_names:
        channel_desc.append_child('channel').append_child_value('label', str(ch))\
            .append_child_value('type','EEG').append_child_value('unit','microvolts')
    desc.append_child('amplifier').append_child('settings').append_child_value('is_slave', 'false')
    desc.append_child('acquisition').append_child_value('manufacturer', 'PyCNBI').append_child_value('serial_number', 'N/A')
    outlet = pylsl.StreamOutlet(sinfo, chunk_size=chunk_size)

    input('Press Enter to start streaming.')
    print('Streaming started')

    idx_chunk = 0
    t_chunk = chunk_size / sfreq
    finished = False
    if high_resolution:
        t_start = time.perf_counter()
    else:
        t_start = time.time()
    
    # start streaming
    while True:
        idx_current = idx_chunk * chunk_size
        chunk = raw._data[:, idx_current:idx_current + chunk_size]
github kaczmarj / rteeg / demonstrations / synthesize_data / send_markers.py View on Github external
"""Example program to demonstrate how to send markers into LSL."""

import random
import time

from pylsl import StreamInfo, StreamOutlet

info = StreamInfo(name='markers', type='Markers', channel_count=1,
                  channel_format='int32', source_id='markers_test1234')

# next make an outlet
outlet = StreamOutlet(info)
trigger = 0
print("now sending markers...")
while True:
    # pick a sample to send an wait for a bit
    outlet.push_sample([trigger])
    print(trigger)
    trigger += 1
    time.sleep(2.0)