Class CommandSender

A BaseBlock that sends UDP command strings to ESP-based IMU sensor nodes to control which data streams are active.

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.

JSON pipeline configuration:

{
  "Name": "ESP-Control",
  "Type": "CommandSender",
  "Params": [ "192.168.1.100", "5000" ]
}

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

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

The command protocol is a simple ASCII string sent over UDP: {StreamType}{DeviceNumber}{on|off}, for example ROT1on or ACC3off.

This block does not receive any pipeline data — it is a pure command sender. The host IP and port can be configured via JSON or changed at runtime through the CommandSenderViewModel.

Constructors

CommandSender(string, string, int)

Initialises a new CommandSender instance.

Declaration
public CommandSender(string name = "CommandSender", string host = "192.168.1.1", int port = 5000)
Parameters
Type Name Description
string name

Display name for this block.

string host

Target ESP host IP address.

int port

Target UDP port number.

Fields

_isConnected

Declaration
private bool _isConnected
Field Value
Type Description
bool

_udpClient

Declaration
private UdpClient? _udpClient
Field Value
Type Description
UdpClient

Properties

Host

Target ESP host IP address.

Declaration
public string Host { get; set; }
Property Value
Type Description
string

Info

Observable status information for UI binding.

Declaration
public CommandSenderInfo Info { get; }
Property Value
Type Description
CommandSenderInfo

IsConnected

Whether the UDP client currently has an endpoint bound.

Declaration
public bool IsConnected { 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.

Port

Target UDP port number.

Declaration
public int Port { get; set; }
Property Value
Type Description
int

Methods

ConfigureInput(IServiceProvider, JsonModel)

Factory method that creates a CommandSender from a JSON pipeline definition.

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

The application's dependency injection service provider.

JsonModel m

JSON model. Params must contain exactly two entries: [hostIP, port].

Returns
Type Description
CommandSender

A configured CommandSender block.

Exceptions
Type Condition
ArgumentException

Thrown if Params does not contain exactly two entries.

Connect()

Opens the UDP connection to the target ESP node. If already connected, the old client is closed first.

Declaration
public void Connect()
Exceptions
Type Condition
SocketException

The host could not be resolved.

Disconnect()

Closes the UDP client without disposing the block, so it can be reconnected to a different host or port.

Declaration
public void Disconnect()

Dispose()

Closes the UDP client and releases resources.

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

GetJsonParams()

The two values ConfigureInput reads back, in its order: host, then port.

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

OnReceive(object, object)

This block does not process pipeline data. No-op.

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

SendCommand(EspStreamType, int, bool)

Sends a command to start or stop a specific data stream on a specific device.

Declaration
public Task SendCommand(EspStreamType streamType, int deviceNumber, bool enable)
Parameters
Type Name Description
EspStreamType streamType

The sensor stream to control.

int deviceNumber

The 1-based device index on the ESP network.

bool enable

true to start the stream, false to stop it.

Returns
Type Description
Task

A task that completes when the UDP datagram has been sent.

Exceptions
Type Condition
InvalidOperationException

Thrown if Connect() has not been called.

SendRaw(string)

Sends a raw string command (for custom or future protocol extensions).

Declaration
public Task SendRaw(string rawCommand)
Parameters
Type Name Description
string rawCommand

The ASCII command string to send.

Returns
Type Description
Task

A task that completes when the datagram has been sent.

TryConnect()

Attempts to connect, reporting failure through Info instead of throwing.

Declaration
public bool TryConnect()
Returns
Type Description
bool

true if the endpoint was bound.

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IAsyncDisposable
IDisposable

Search documentation

Start typing to search the documentation.