Class Muovi

A BaseBlock that streams high-density surface EMG (HD-sEMG), EEG, or IMU data from one or more Muovi probes connected through an OT Bioelettronica SyncStation.

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.

Minimal JSON configuration streaming two probes in EMG mode with IMU:

{
  "Name": "HD-EMG",
  "Type": "Muovi",
  "DesiredRate": 100,
  "Params": [ "1", "3", "emg" ]
}

Params accepts zero-based probe indices and optional keywords: "emg", "emg_lowgain" / "lowgain", "eeg", and "imu". If no indices are specified, probe 0 is used by default.

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

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

The Muovi probe is a wireless, wearable, high-density biosignal acquisition device manufactured by OT Bioelettronica (Turin, Italy). Each probe features a 32-electrode grid and a 9-axis IMU. Up to four probes can be synchronised through a single SyncStation base unit, which exposes a TCP server at 192.168.76.1:54320.

Firmware documentation and protocol specifications are available from the manufacturer at https://otbioelettronica.it/en/download/#55-171-wpfd-muovi.

Supported signal modes:

ModeSample rate / gain
Emg2 000 Hz, gain ×8 (286.1 nV/bit, ±9.375 mV range)
EmgLowGain2 000 Hz, gain ×4 (572.2 nV/bit, ±18.75 mV range)
Eeg500 Hz, EEG-optimised front-end

Output modes:

  • Matrix push — when DesiredRate is lower than the nominal sample rate, the reader thread accumulates NominalRate / DesiredRate samples and publishes a MathNet.Numerics.LinearAlgebra.Matrix<T> directly; no upstream timer is required.
  • Vector timer — when DesiredRate equals the nominal rate, the reader decodes every sample and a timer tick publishes the latest MathNet.Numerics.LinearAlgebra.Vector<T>.

Protocol overview (SyncStation v2.8):

The configuration packet consists of a START byte encoding the number of CONTROL bytes that follow (one per enabled probe), plus a CRC-8 trailer. The SyncStation allocates frame bandwidth only for probes whose CONTROL bytes are present, so the total raw columns per sample equals enabledProbes × 38 + 6 (38 channels per probe plus 6 SyncStation accessory channels). Each TCP burst contains exactly 18 consecutive samples.

Constructors

Muovi(string, double)

Initialises a new instance of the Muovi class with default settings.

Declaration
public Muovi(string name = "Muovi", double desiredRate = 100)
Parameters
Type Name Description
string name

Display name for this block instance.

double desiredRate

Desired output rate in Hz. If lower than the probe's nominal rate, multiple samples are batched into a MathNet.Numerics.LinearAlgebra.Matrix<T>. If equal, single-sample MathNet.Numerics.LinearAlgebra.Vector<T> mode is used.

Fields

SubSamplingRate

Number of samples the SyncStation packs into each TCP burst. This value is fixed in firmware and cannot be changed.

Declaration
private const int SubSamplingRate = 18
Field Value
Type Description
int

SyncStationExtraCh

Number of accessory channels appended by the SyncStation after all probe data.

Declaration
private const int SyncStationExtraCh = 6
Field Value
Type Description
int

SyncStationIp

Default IP address of the SyncStation Wi-Fi access point.

Declaration
private const string SyncStationIp = "192.168.76.1"
Field Value
Type Description
string

SyncStationPort

TCP port exposed by the SyncStation firmware.

Declaration
private const int SyncStationPort = 54320
Field Value
Type Description
int

_bytesPerPacket

Declaration
private int _bytesPerPacket
Field Value
Type Description
int

_bytesPerSample

Declaration
private int _bytesPerSample
Field Value
Type Description
int

_client

Declaration
private TcpClient? _client
Field Value
Type Description
TcpClient

_conversionFactor

Declaration
private double _conversionFactor
Field Value
Type Description
double

_hasEmg

Indicates whether electrode data is available (always true while streaming).

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

_hasImu

Indicates whether IMU data is available (mirrors StreamImu while streaming).

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

_isStreaming

Declaration
private volatile bool _isStreaming
Field Value
Type Description
bool

_lastRamp

Declaration
private short _lastRamp
Field Value
Type Description
short

_latestImu

Declaration
private volatile Vector<double>? _latestImu
Field Value
Type Description
Vector<double>

_latestSample

Declaration
private volatile Vector<double>? _latestSample
Field Value
Type Description
Vector<double>

_matrixMode

Declaration
private bool _matrixMode
Field Value
Type Description
bool

_nominalRate

Declaration
private int _nominalRate
Field Value
Type Description
int

_rampInitialized

Declaration
private bool _rampInitialized
Field Value
Type Description
bool

_readerThread

Declaration
private Thread? _readerThread
Field Value
Type Description
Thread

_reading

Declaration
private volatile bool _reading
Field Value
Type Description
bool

_sampleReady

Declaration
private volatile bool _sampleReady
Field Value
Type Description
bool

_samplesPerBatch

Declaration
private int _samplesPerBatch
Field Value
Type Description
int

_stream

Declaration
private NetworkStream? _stream
Field Value
Type Description
NetworkStream

_totalRawColumns

Declaration
private int _totalRawColumns
Field Value
Type Description
int

Properties

ChannelLabels

All output channel labels in order (EMG/EEG then IMU, repeated per probe).

Declaration
public List<string> ChannelLabels { get; private set; }
Property Value
Type Description
List<string>

ChannelsPerProbeOutput

Number of output channels per probe: 32 electrode channels, plus optionally 4 IMU channels.

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

DumpFilePrefix

Recordings from this block are named <block>_muovi.csv.

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

EmgChannelLabels

Electrode-only channel labels, used to populate the EMG/EEG scope legend.

Declaration
public List<string> EmgChannelLabels { get; private set; }
Property Value
Type Description
List<string>

ForceMatrixMode

Explicit override for the publish strategy, set from the JSON "matrix" / "vector" param. When null (default), the mode is auto-derived from DesiredRate vs the probe's nominal rate (legacy behaviour): batch into a MathNet.Numerics.LinearAlgebra.Matrix<T> when more than one sample falls in an output period, otherwise publish single MathNet.Numerics.LinearAlgebra.Vector<T> samples. When set, it forces the mode:

  • true — always publish a per-packet MathNet.Numerics.LinearAlgebra.Matrix<T> (every acquired sample is kept; correct for high-rate display/recording).
  • false — always publish decimated single MathNet.Numerics.LinearAlgebra.Vector<T> samples at DesiredRate.

Must be set before Connect().

Declaration
public bool? ForceMatrixMode { get; set; }
Property Value
Type Description
bool?

HasEmg

Indicates whether electrode data is available (always true while streaming).

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

HasImu

Indicates whether IMU data is available (mirrors StreamImu while streaming).

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

ImuChannelLabels

IMU-only channel labels, used to populate the IMU scope legend.

Declaration
public List<string> ImuChannelLabels { get; private set; }
Property Value
Type Description
List<string>

IsStreaming

Indicates whether the block is currently connected to the SyncStation and streaming data.

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

MaxInputs

Gets the maximum number of input connections allowed for this block.

Declaration
public override int MaxInputs { get; }
Property Value
Type Description
int
Overrides
BaseBlock.MaxInputs
Remarks

Override in derived classes to specify input requirements. Default is 1 (most blocks accept exactly one input). Use MaxValue for blocks that accept unlimited inputs (e.g., Joiner).

MinInputs

Gets the minimum number of input connections required for this block.

Declaration
public override int MinInputs { get; }
Property Value
Type Description
int
Overrides
BaseBlock.MinInputs
Remarks

Override in derived classes to specify input requirements. Default is 1 (most blocks require exactly one input). Source blocks (devices, generators) should return 0.

OutputChannels

Total number of output channels across all enabled probes. Equals ProbeIndices.Count × ChannelsPerProbeOutput.

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

ProbeIndices

Zero-based indices of the Muovi probes to enable on the SyncStation. The index corresponds to the physical slot on the SyncStation (0–3 for standard Muovi probes, 4–15 for Muovi+ and other OT Bioelettronica devices). Verify the correct index against the LED indicators on the SyncStation.

Declaration
public List<int> ProbeIndices { get; }
Property Value
Type Description
List<int>

ScopeEmg

Scope monitor for real-time visualisation of the electrode (EMG / EEG) channels. Bind to a ScopeMonitorView in the UI layer.

Declaration
public ScopeMonitor ScopeEmg { get; }
Property Value
Type Description
ScopeMonitor

ScopeImu

Scope monitor for real-time visualisation of the IMU quaternion channels. Only populated when StreamImu is true.

Declaration
public ScopeMonitor ScopeImu { get; }
Property Value
Type Description
ScopeMonitor

SignalMode

Gets or sets the signal acquisition mode for all enabled probes. Must be set before calling Connect().

Declaration
public MuoviSignalMode SignalMode { get; set; }
Property Value
Type Description
MuoviSignalMode

The default is Emg.

StreamImu

Gets or sets whether the four IMU quaternion channels (W, X, Y, Z) per probe are included in the output vector. Must be set before calling Connect().

Declaration
public bool StreamImu { get; set; }
Property Value
Type Description
bool

StreamInfo

Observable telemetry counters (frames collected, packets lost, pipeline status) suitable for binding in a device card view.

Declaration
public MuoviStreamInfo StreamInfo { get; }
Property Value
Type Description
MuoviStreamInfo

Methods

BuildChannelLabels()

Rebuilds ChannelLabels, EmgChannelLabels, and ImuChannelLabels based on the current ProbeIndices, SignalMode, and StreamImu settings.

Declaration
private void BuildChannelLabels()

CheckRamp(byte[], int)

Validates the per-sample ramp counter embedded in the last raw column of each frame. Sets DataLoss when a gap is detected and resets it when consecutive clean samples arrive.

Declaration
private void CheckRamp(byte[] frame, int offset)
Parameters
Type Name Description
byte[] frame

The raw byte buffer.

int offset

Byte offset of the current sample within frame.

Remarks

The SyncStation ramp counter increments by 256 per firmware packet (not per sample). A gap of 257 at the 16-bit wrap boundary is normal; gaps ≥ 258 indicate packet loss.

ConfigureInput(IServiceProvider, JsonModel)

Factory method that creates and configures a Muovi instance from a JSON pipeline definition.

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

The application's dependency injection service provider.

JsonModel m

The JSON model containing Name, DesiredRate, Path (for CSV recording), and Params (probe indices and mode keywords).

Returns
Type Description
Muovi

A fully configured Muovi block ready to be connected.

Remarks

Recognised Params values:

  • Integer values — interpreted as zero-based probe slot indices.
  • "emg" — standard EMG mode (default).
  • "emg_lowgain" or "lowgain" — EMG with reduced gain.
  • "eeg" — EEG acquisition mode at 500 Hz.
  • "imu" — include IMU quaternion channels in output.

Connect()

Opens a TCP connection to the SyncStation, sends the configuration packet, and starts the background reader thread.

Declaration
public void Connect()
Remarks

Set SignalMode, StreamImu, and ProbeIndices before calling this method. The SyncStation begins transmitting data immediately after the configuration packet is acknowledged. The method is a no-op if the block is already streaming — call Disconnect() first to reconfigure.

Exceptions
Type Condition
SocketException

Thrown if the TCP connection to the SyncStation cannot be established (e.g. device not powered on or Wi-Fi not connected).

ConnectAsync()

Asynchronously connects to the SyncStation on a background thread.

Declaration
public Task ConnectAsync()
Returns
Type Description
Task

A task that completes when the connection is established and streaming has started.

DecodeSampleInline(byte[], int)

Decodes a single sample from the raw byte frame into the latest MathNet.Numerics.LinearAlgebra.Vector<T> and optional IMU vector (vector / timer mode).

Declaration
private void DecodeSampleInline(byte[] frame, int offset)
Parameters
Type Name Description
byte[] frame

The accumulation buffer containing raw bytes.

int offset

Byte offset of the sample within frame.

Disconnect()

Stops the reader thread, sends a shutdown packet to the SyncStation, and closes the TCP connection.

Declaration
public void Disconnect()
Remarks

Safe to call even if the block is not currently streaming (no-op in that case). The shutdown packet (0x00 + CRC) instructs the SyncStation firmware to stop transmitting.

Dispose()

Releases all resources: pauses and disposes both scope monitors, disconnects from the SyncStation, and flushes the CSV dumper.

Declaration
public override void Dispose()
Overrides
BaseBlock.Dispose()

ExtractElectrode(Vector<double>)

Extracts only the electrode channels from a full output vector that may contain interleaved IMU channels, producing a contiguous EMG/EEG-only vector for ScopeEmg.

Declaration
private Vector<double> ExtractElectrode(Vector<double> full)
Parameters
Type Name Description
Vector<double> full

The full output vector including both electrode and IMU channels.

Returns
Type Description
Vector<double>

A vector containing only electrode channels. If StreamImu is false, returns full directly without copying.

ExtractElectrodeMatrix(Matrix<double>)

Matrix counterpart of ExtractElectrode(Vector<double>): returns a [rows × (probes·electrodeChannels)] sub-matrix containing only the electrode columns, stripping the interleaved IMU columns. When StreamImu is false the matrix is returned unchanged (no copy).

Declaration
private Matrix<double> ExtractElectrodeMatrix(Matrix<double> full)
Parameters
Type Name Description
Matrix<double> full
Returns
Type Description
Matrix<double>

OnHasEmgChanged(bool)

Executes the logic for when HasEmg just changed.

Declaration
private void OnHasEmgChanged(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 HasEmg is changed.

OnHasEmgChanged(bool, bool)

Executes the logic for when HasEmg just changed.

Declaration
private void OnHasEmgChanged(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 HasEmg is changed.

OnHasEmgChanging(bool)

Executes the logic for when HasEmg is changing.

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

The new property value being set.

Remarks

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

OnHasEmgChanging(bool, bool)

Executes the logic for when HasEmg is changing.

Declaration
private void OnHasEmgChanging(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 HasEmg is changed.

OnHasImuChanged(bool)

Executes the logic for when HasImu just changed.

Declaration
private void OnHasImuChanged(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 HasImu is changed.

OnHasImuChanged(bool, bool)

Executes the logic for when HasImu just changed.

Declaration
private void OnHasImuChanged(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 HasImu is changed.

OnHasImuChanging(bool)

Executes the logic for when HasImu is changing.

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

The new property value being set.

Remarks

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

OnHasImuChanging(bool, bool)

Executes the logic for when HasImu is changing.

Declaration
private void OnHasImuChanging(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 HasImu is changed.

OnReceive(object, object)

Called by the upstream timer block. In vector mode, publishes the most recently decoded sample to downstream blocks and scope monitors.

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

The timer block that triggered this callback.

object tNow

The current pipeline timestamp.

Overrides
BaseBlock.OnReceive(object, object)
Remarks

This method is a no-op in matrix mode, where data is published directly from PublishMatrixBatch(byte[], int).

PublishMatrixBatch(byte[], int)

Decodes a batch of consecutive samples into a MathNet.Numerics.LinearAlgebra.Matrix<T> and publishes it downstream (matrix / push mode).

Declaration
private void PublishMatrixBatch(byte[] buf, int batchOffset)
Parameters
Type Name Description
byte[] buf

The accumulation buffer containing raw bytes.

int batchOffset

Byte offset of the first sample in the batch.

ReaderLoop()

Background thread loop that continuously reads from the TCP stream, accumulates bytes into complete frames, and dispatches decoded data to the pipeline.

Declaration
private void ReaderLoop()
Remarks

The SyncStation sends data in bursts of SubSamplingRate (18) samples. TCP may fragment or coalesce these bursts, so the reader uses an accumulation buffer and processes as many complete frames as are available after each read.

SendConfiguration()

Builds and sends the SyncStation configuration packet over the open TCP stream.

Declaration
private void SendConfiguration()
Remarks

Packet format per OT Bioelettronica SyncStation protocol v2.8:

  1. START byte A: [0][REC_ON=0][SIZE4..SIZE0][GO=1] where SIZE is the count of CONTROL bytes that follow.
  2. CONTROL bytes (one per enabled probe): [DEV3..DEV0][EMG/EEG][MODE1][MODE0][EN=1].
  3. CRC-8 trailer computed over all preceding bytes.

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IDisposable
IAsyncDisposable

See Also

Search documentation

Start typing to search the documentation.