mne_rt.OSCSender#

class mne_rt.OSCSender(host: str = '127.0.0.1', port: int = 9000, prefix: str = '/ant', bundle: bool = False)[source]#

Bases: object

Thread-safe OSC client that broadcasts NF feature values.

Sends one UDP packet per NF value (or one bundle per update cycle) to an OSC server at the given host/port. Safe to call from any thread.

Parameters:
hoststr, default “127.0.0.1”

Destination IP address or hostname.

portint, default 9000

Destination UDP port.

prefixstr, default “/ant”

OSC address prefix. Each modality is sent to <prefix>/<modality>.

bundlebool, default False

If True, pack all modality values into a single OSC bundle per update cycle (one UDP packet) instead of one packet per modality.

Raises:
ImportError

If python-osc is not installed (should not occur with a standard ANT install).

Examples

Basic usage:

sender = OSCSender(host="127.0.0.1", port=9000)
sender.send("sensor_power", 0.35)
sender.send_all(["sensor_power", "erd_ers"], [0.35, -12.4])
sender.close()

Custom prefix (maps to /nf/sensor_power):

sender = OSCSender(prefix="/nf")

Added in version 1.0.0.

__init__(host: str = '127.0.0.1', port: int = 9000, prefix: str = '/ant', bundle: bool = False) None[source]#

Methods

__init__([host, port, prefix, bundle])

close()

Close the underlying UDP socket.

send(modality, value)

Send a single NF value immediately.

send_all(modalities, values)

Send all NF values for one update cycle.

send_raw(address, *args)

Send an arbitrary OSC message to a custom address.

Attributes

target

Human-readable target as "host:port".

send(modality: str, value: float) None[source]#

Send a single NF value immediately.

Parameters:
modalitystr

Modality name (e.g. "sensor_power"). Appended to the OSC prefix to form the address.

valuefloat

Current NF feature value.

Notes

The OSC message sent is:

<prefix>/<modality>  float32  <value>
send_all(modalities: Sequence[str], values: Sequence[float]) None[source]#

Send all NF values for one update cycle.

When bundle=True (set in __init__()), packs everything into a single OSC bundle datagram. Otherwise sends one message per modality.

Parameters:
modalitiessequence of str

Active modality names, in order.

valuessequence of float

Corresponding feature values.

Raises:
ValueError

If modalities and values have different lengths.

send_raw(address: str, *args) None[source]#

Send an arbitrary OSC message to a custom address.

Parameters:
addressstr

Full OSC address (e.g. "/my/custom/path").

*args

OSC arguments (int, float, str, bytes).

close() None[source]#

Close the underlying UDP socket.

After calling this method the sender should not be used again.

property target: str#

Human-readable target as "host:port".