Class LSL

Unified Lab Streaming Layer block that can operate as either an LSL outlet (pushing pipeline data to the network) or an LSL inlet (pulling data from the network into the pipeline).

JSON configuration

Use these block entries inside a pipeline configuration. Input names must match other blocks in that pipeline; device addresses and file paths must match your setup.

"lsl_out": {
  "Type": "LslBlock",
  "Inputs": ["RMS"],
  "Params": ["outlet", "MOSAIC_EMG", "EMG", 2000, 8]
}
"lsl_in": {
  "Type": "LslBlock",
  "DesiredRate": 2000,
  "Params": ["inlet", "BioAmp", "EMG", 5.0, 32]
}

How Type, Inputs and Params work · Block catalogue and parameter reference

Namespace: MOSAIC.Models.Streaming
Assembly: MOSAIC.dll
Syntax
public sealed class LSL : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks

Outlet mode: Accepts MathNet.Numerics.LinearAlgebra.Vector<T>, MathNet.Numerics.LinearAlgebra.Matrix<T>, and tagged tuples from upstream. Each sample row is pushed via push_sample. The block re-publishes downstream so it can sit mid-pipeline. The outlet is created lazily on first sample if channel count is 0.

Inlet mode: Source block with no upstream inputs. Call Start() to spawn a background reader thread that resolves the named stream and pulls chunks. Each row is published as MathNet.Numerics.LinearAlgebra.Vector<T>. Call Stop() to shut down.

JSON config — Outlet:

"lsl_out": {
  "Type": "LslBlock",
  "Inputs": ["RMS"],
  "Params": ["outlet", "MOSAIC_EMG", "EMG", 2000, 8]
}

JSON config — Inlet:

"lsl_in": {
  "Type": "LslBlock",
  "DesiredRate": 2000,
  "Params": ["inlet", "BioAmp", "EMG", 5.0, 32]
}

Param layout: mode, stream name, stream type, rate-or-timeout, channel-count-or-chunk-len.

Integration note: Uses the source-file-based liblsl-Csharp binding (LSL.cs + native lsl.dll), not a NuGet package.

Constructors

LSL(string, double, LslMode, string, string, double, int)

Initialises a new LSL.

Declaration
public LSL(string name, double desiredRate, LslMode mode, string streamName, string streamType, double rateOrTimeout, int channelsOrChunkLen)
Parameters
Type Name Description
string name
double desiredRate
LslMode mode
string streamName
string streamType
double rateOrTimeout
int channelsOrChunkLen

Fields

_channelCount

Declaration
private int _channelCount
Field Value
Type Description
int

_initLock

Declaration
private readonly object _initLock
Field Value
Type Description
object

_isActive

Whether the outlet has been created or the inlet reader is active.

Declaration
[ObservableProperty]
private bool _isActive
Field Value
Type Description
bool

_lslStatus

Human-readable status message for the UI.

Declaration
[ObservableProperty]
private string _lslStatus
Field Value
Type Description
string

_maxChunkLen

Declaration
private int _maxChunkLen
Field Value
Type Description
int

_mode

Declaration
private readonly LslMode _mode
Field Value
Type Description
LslMode

_nominalRate

Declaration
private double _nominalRate
Field Value
Type Description
double

_outlet

Declaration
private StreamOutlet? _outlet
Field Value
Type Description
StreamOutlet

_outletInfo

Declaration
private StreamInfo? _outletInfo
Field Value
Type Description
StreamInfo

_readerThread

Declaration
private Thread? _readerThread
Field Value
Type Description
Thread

_resolveTimeout

Declaration
private double _resolveTimeout
Field Value
Type Description
double

_resolvedChannels

Resolved or configured channel count.

Declaration
[ObservableProperty]
private int _resolvedChannels
Field Value
Type Description
int

_resolvedRate

Resolved or configured sample rate (Hz).

Declaration
[ObservableProperty]
private double _resolvedRate
Field Value
Type Description
double

_running

Declaration
private volatile bool _running
Field Value
Type Description
bool

_sampleCount

Declaration
[ObservableProperty]
private long _sampleCount
Field Value
Type Description
long

_streamName

Declaration
private string _streamName
Field Value
Type Description
string

_streamType

Declaration
private string _streamType
Field Value
Type Description
string

Properties

IsActive

Whether the outlet has been created or the inlet reader is active.

Declaration
[ExcludeFromCodeCoverage]
public bool IsActive { get; set; }
Property Value
Type Description
bool

IsRunning

Whether the block is currently running (inlet reader active).

Declaration
public bool IsRunning { get; }
Property Value
Type Description
bool

JsonTypeName

Block type identifier for JSON serialization. Override for a custom name.

Declaration
protected override string JsonTypeName { get; }
Property Value
Type Description
string
Overrides
BaseBlock.JsonTypeName

LslStatus

Human-readable status message for the UI.

Declaration
[ExcludeFromCodeCoverage]
public string LslStatus { get; set; }
Property Value
Type Description
string

MaxChunkLen

Gets the max chunk length (inlet mode).

Declaration
public int MaxChunkLen { get; }
Property Value
Type Description
int

Mode

Gets the configured mode (Inlet or Outlet).

Declaration
public LslMode Mode { get; }
Property Value
Type Description
LslMode

NominalRate

Gets the nominal sample rate (outlet mode).

Declaration
public double NominalRate { get; }
Property Value
Type Description
double

ResolveTimeout

Gets the resolve timeout in seconds (inlet mode).

Declaration
public double ResolveTimeout { get; }
Property Value
Type Description
double

ResolvedChannels

Resolved or configured channel count.

Declaration
[ExcludeFromCodeCoverage]
public int ResolvedChannels { get; set; }
Property Value
Type Description
int

ResolvedRate

Resolved or configured sample rate (Hz).

Declaration
[ExcludeFromCodeCoverage]
public double ResolvedRate { get; set; }
Property Value
Type Description
double

SampleCount

Declaration
[ExcludeFromCodeCoverage]
public long SampleCount { get; set; }
Property Value
Type Description
long

StreamName

Gets the LSL stream name.

Declaration
public string StreamName { get; }
Property Value
Type Description
string

StreamType

Gets the LSL stream type.

Declaration
public string StreamType { get; }
Property Value
Type Description
string

Visualization

This block's visualization, or null when it has none.

Declaration
protected override BlockVisualization? Visualization { get; }
Property Value
Type Description
BlockVisualization
Overrides
BaseBlock.Visualization
Remarks

Blocks own their scope as a public Viz property rather than inheriting one, so the base class has no way to reach it. Overriding this is what lets the rate below be wired up automatically. With correct publication metadata, the bundle derives the time axis for one vector per publication or fixed-size contiguous sample packets from the feed shape.

When a plot needs a rate that publication frequency and feed shape cannot express (for example, variable-sized packets or overlapping windows), declare it with Viz.UpdateSignalRate. An explicit declaration wins over the derived rate. A block with several bundles must configure each one; this hook exposes only one bundle.

Viz

Optional visualization bundle. Set by the ViewModel after construction.

Declaration
public BlockVisualization? Viz { get; set; }
Property Value
Type Description
BlockVisualization

Methods

ApplySettings(string, string, double, int)

Applies updated settings from the UI. Only effective when the block is not active.

Declaration
public void ApplySettings(string streamName, string streamType, double rateOrTimeout, int channelsOrChunkLen)
Parameters
Type Name Description
string streamName

New stream name.

string streamType

New stream type.

double rateOrTimeout

Outlet: nominal rate (Hz). Inlet: resolve timeout (s).

int channelsOrChunkLen

Outlet: channel count. Inlet: max chunk length.

ConfigureInput(IServiceProvider, JsonModel)

Factory method for JSON-driven pipeline construction.

Declaration
public static LSL ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
Type Name Description
IServiceProvider sp

Service provider (dependency injection).

JsonModel m

JSON model containing Name, DesiredRate, and Params.

Returns
Type Description
LSL

A fully configured LSL instance.

Remarks

Expected Params layout:

  1. [0] Mode: "inlet" or "outlet" (string, default "outlet")
  2. [1] Stream name (string, default "MOSAIC")
  3. [2] Stream type (string, default "EMG")
  4. [3] Outlet: nominal rate (Hz) / Inlet: resolve timeout (s) (double)
  5. [4] Outlet: channel count / Inlet: max chunk length (int)

Dispose(bool)

Releases managed resources: status subscription, output dispatcher, CSV dumper, subscriber references.

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

true when called from Dispose(). There is no finalizer, so a false pass has nothing to release.

Overrides
BaseBlock.Dispose(bool)

EnsureOutlet(int)

Declaration
private void EnsureOutlet(int channelCount)
Parameters
Type Name Description
int channelCount

GetJsonParams()

Block-specific parameters for JSON. Override to provide custom parameters.

Declaration
protected override IReadOnlyList<object>? GetJsonParams()
Returns
Type Description
IReadOnlyList<object>

The values for Params, in the order this block's ConfigureInput reads them, or null when the block takes no parameters.

Overrides
BaseBlock.GetJsonParams()

OnIsActiveChanged(bool)

Executes the logic for when IsActive just changed.

Declaration
private void OnIsActiveChanged(bool value)
Parameters
Type Name Description
bool value

The new property value that was set.

Remarks

This method is invoked right after the value of IsActive is changed.

OnIsActiveChanged(bool, bool)

Executes the logic for when IsActive just changed.

Declaration
private void OnIsActiveChanged(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that was replaced.

bool newValue

The new property value that was set.

Remarks

This method is invoked right after the value of IsActive is changed.

OnIsActiveChanging(bool)

Executes the logic for when IsActive is changing.

Declaration
private void OnIsActiveChanging(bool value)
Parameters
Type Name Description
bool value

The new property value being set.

Remarks

This method is invoked right before the value of IsActive is changed.

OnIsActiveChanging(bool, bool)

Executes the logic for when IsActive is changing.

Declaration
private void OnIsActiveChanging(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that is being replaced.

bool newValue

The new property value being set.

Remarks

This method is invoked right before the value of IsActive is changed.

OnLslStatusChanged(string)

Executes the logic for when LslStatus just changed.

Declaration
private void OnLslStatusChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of LslStatus is changed.

OnLslStatusChanged(string?, string)

Executes the logic for when LslStatus just changed.

Declaration
private void OnLslStatusChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of LslStatus is changed.

OnLslStatusChanging(string)

Executes the logic for when LslStatus is changing.

Declaration
private void OnLslStatusChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of LslStatus is changed.

OnLslStatusChanging(string?, string)

Executes the logic for when LslStatus is changing.

Declaration
private void OnLslStatusChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of LslStatus is changed.

OnReceive(object, object)

Processes incoming data from an upstream block. Must be implemented by derived classes.

Declaration
protected override void OnReceive(object sender, object data)
Parameters
Type Name Description
object sender

The publishing block, or whatever else delivered the value.

object data
Overrides
BaseBlock.OnReceive(object, object)
Remarks

Called on the dispatching thread, not the UI thread.

OnResolvedChannelsChanged(int)

Executes the logic for when ResolvedChannels just changed.

Declaration
private void OnResolvedChannelsChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

This method is invoked right after the value of ResolvedChannels is changed.

OnResolvedChannelsChanged(int, int)

Executes the logic for when ResolvedChannels just changed.

Declaration
private void OnResolvedChannelsChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

This method is invoked right after the value of ResolvedChannels is changed.

OnResolvedChannelsChanging(int)

Executes the logic for when ResolvedChannels is changing.

Declaration
private void OnResolvedChannelsChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of ResolvedChannels is changed.

OnResolvedChannelsChanging(int, int)

Executes the logic for when ResolvedChannels is changing.

Declaration
private void OnResolvedChannelsChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

This method is invoked right before the value of ResolvedChannels is changed.

OnResolvedRateChanged(double)

Executes the logic for when ResolvedRate just changed.

Declaration
private void OnResolvedRateChanged(double value)
Parameters
Type Name Description
double value

The new property value that was set.

Remarks

This method is invoked right after the value of ResolvedRate is changed.

OnResolvedRateChanged(double, double)

Executes the logic for when ResolvedRate just changed.

Declaration
private void OnResolvedRateChanged(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that was replaced.

double newValue

The new property value that was set.

Remarks

This method is invoked right after the value of ResolvedRate is changed.

OnResolvedRateChanging(double)

Executes the logic for when ResolvedRate is changing.

Declaration
private void OnResolvedRateChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

This method is invoked right before the value of ResolvedRate is changed.

OnResolvedRateChanging(double, double)

Executes the logic for when ResolvedRate is changing.

Declaration
private void OnResolvedRateChanging(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that is being replaced.

double newValue

The new property value being set.

Remarks

This method is invoked right before the value of ResolvedRate is changed.

OnSampleCountChanged(long)

Executes the logic for when SampleCount just changed.

Declaration
private void OnSampleCountChanged(long value)
Parameters
Type Name Description
long value

The new property value that was set.

Remarks

This method is invoked right after the value of SampleCount is changed.

OnSampleCountChanged(long, long)

Executes the logic for when SampleCount just changed.

Declaration
private void OnSampleCountChanged(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that was replaced.

long newValue

The new property value that was set.

Remarks

This method is invoked right after the value of SampleCount is changed.

OnSampleCountChanging(long)

Executes the logic for when SampleCount is changing.

Declaration
private void OnSampleCountChanging(long value)
Parameters
Type Name Description
long value

The new property value being set.

Remarks

This method is invoked right before the value of SampleCount is changed.

OnSampleCountChanging(long, long)

Executes the logic for when SampleCount is changing.

Declaration
private void OnSampleCountChanging(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that is being replaced.

long newValue

The new property value being set.

Remarks

This method is invoked right before the value of SampleCount is changed.

OpenOutlet(int)

Declaration
private void OpenOutlet(int channelCount)
Parameters
Type Name Description
int channelCount

PushVector(Vector<double>)

Declaration
private void PushVector(Vector<double> v)
Parameters
Type Name Description
Vector<double> v

ReaderLoop()

Declaration
private void ReaderLoop()

Start()

Starts the background LSL reader thread. Only valid in Inlet mode.

Declaration
public void Start()

Stop()

Stops the background reader thread. Only valid in Inlet mode.

Declaration
public void Stop()

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IDisposable
IAsyncDisposable

Search documentation

Start typing to search the documentation.