Class StimParamsLayer
Layer that wraps an IStimulationCore and a StimParamsConfigController. Computes pulse widths from normalized inputs and forwards stimulation to the core. Also exposes dotted-key parameter access and an optional BASIC capability.
Inheritance
Namespace: Wss.CalibrationModule
Assembly: WSS_Core_Interface.dll
Syntax
public sealed class StimParamsLayer : IStimParamsCore, IStimulationCore
Constructors
StimParamsLayer(IStimulationCore, string)
Constructs the layer over an existing core and a params context path.
Declaration
public StimParamsLayer(IStimulationCore core, string pathOrDir)
Parameters
| Type | Name | Description |
|---|---|---|
| IStimulationCore | core | Initialized stimulation core to wrap. |
| string | pathOrDir | Params file path or directory. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
Methods
AddOrUpdateStimParam(string, float)
Adds or updates a stimulation parameter at the specified dotted key.
Declaration
public void AddOrUpdateStimParam(string key, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Parameter key (e.g., "stim.ch.1.defaultPA"). |
| float | value | Value to assign. |
Dispose()
Declaration
public void Dispose()
GetAllStimParams()
Returns all numeric stimulation parameters as a flat dictionary of dotted keys and float values.
Declaration
public Dictionary<string, float> GetAllStimParams()
Returns
| Type | Description |
|---|---|
| Dictionary<string, float> |
GetChannelAmp(int)
Gets the default amplitude (PA) stored for the channel.
Declaration
public float GetChannelAmp(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch |
Returns
| Type | Description |
|---|---|
| float |
GetChannelAmpMode(int)
Gets the configured amplitude-control mode, warning and falling back to PW when invalid.
Declaration
public string GetChannelAmpMode(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch |
Returns
| Type | Description |
|---|---|
| string |
GetChannelDefault(int)
Gets the non-controlled axis default (PA when PW mode, PW when PA mode).
Declaration
public float GetChannelDefault(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | 1-based logical channel. |
Returns
| Type | Description |
|---|---|
| float | Default value expressed in the non-controlled axis units (µs for PA mode). |
GetChannelDefaultPW(int)
Gets the default pulse width used when PA mode is active.
Declaration
public int GetChannelDefaultPW(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch |
Returns
| Type | Description |
|---|---|
| int |
GetChannelIPI(int)
Gets inter-pulse interval (IPI) for a channel in mili seconds.
Declaration
public int GetChannelIPI(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch |
Returns
| Type | Description |
|---|---|
| int |
GetChannelMax(int)
Gets the active-control maximum (µs when PW mode, mA when PA mode).
Declaration
public float GetChannelMax(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | 1-based logical channel. |
Returns
| Type | Description |
|---|---|
| float | Maximum value in the active axis units (µs for PW mode). |
GetChannelMin(int)
Gets the active-control minimum (µs when PW mode, mA when PA mode).
Declaration
public float GetChannelMin(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | 1-based logical channel. |
Returns
| Type | Description |
|---|---|
| float | Minimum value in the active axis units (µs for PW mode). |
GetChannelPAMax(int)
Gets maximum PA (mA) for the channel.
Declaration
public float GetChannelPAMax(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch |
Returns
| Type | Description |
|---|---|
| float |
GetChannelPAMin(int)
Gets minimum PA (mA) for the channel.
Declaration
public float GetChannelPAMin(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch |
Returns
| Type | Description |
|---|---|
| float |
GetChannelPWMax(int)
Gets maximum pulse width for a channel in micro seconds.
Declaration
public int GetChannelPWMax(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch |
Returns
| Type | Description |
|---|---|
| int |
GetChannelPWMin(int)
Gets minimum pulse width for a channel in micro seconds.
Declaration
public int GetChannelPWMin(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch |
Returns
| Type | Description |
|---|---|
| int |
GetCoreConfigController()
Gets the JSON-backed stimulation configuration controller currently used by this core.
Declaration
public CoreConfigController GetCoreConfigController()
Returns
| Type | Description |
|---|---|
| CoreConfigController | The active CoreConfigController instance that provides read/write access to stimulation parameters and constants loaded from the configuration file. |
Remarks
Returned reference is live, not a copy and thread safe.
GetStimIntensity(int)
Returns the most recently computed stimulation intensity for the channel. For PW-driven systems, this is the last pulse width (µs) sent by StimulateNormalized(int, float).
Declaration
public float GetStimIntensity(int channel)
Parameters
| Type | Name | Description |
|---|---|---|
| int | channel | 1-based logical channel. |
Returns
| Type | Description |
|---|---|
| float | Most recent intensity value (µs or mA depending on mode). |
GetStimParam(string)
Retrieves a stimulation parameter value.
Declaration
public float GetStimParam(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Parameter key (e.g., "stim.ch.1.maxPW"). |
Returns
| Type | Description |
|---|---|
| float | Parameter value as float. |
GetStimParamsConfigController()
Returns the parameters/configuration controller for stimulation params.
Declaration
public StimParamsConfigController GetStimParamsConfigController()
Returns
| Type | Description |
|---|---|
| StimParamsConfigController | The active StimParamsConfigController. |
Initialize()
Initializes the core: loads JSON config, prepares buffers, and begins connecting to the transport. Non-blocking; call Tick() to advance state.
Declaration
public void Initialize()
IsChannelInRange(int)
Checks whether a channel index is within the valid range.
Declaration
public bool IsChannelInRange(int ch)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch |
Returns
| Type | Description |
|---|---|
| bool |
LoadConfigFile()
Reloads the stimulation JSON configuration from disk into memory.
Declaration
public void LoadConfigFile()
LoadParamsJson()
Reloads the current context file (same path used at construction or the last Load(path)). Reinstantiates the config to re-read JSON from disk, then ensures channel template exists.
Declaration
public void LoadParamsJson()
LoadParamsJson(string)
Loads a new context file. If path is a directory,
uses "stimParams.json" within it. Replaces the active config and backfills the template.
Declaration
public void LoadParamsJson(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | Absolute/relative file path or directory. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If the path is null or whitespace. |
Ready()
True when the core is ready to accept start stimulation.
Declaration
public bool Ready()
Returns
| Type | Description |
|---|---|
| bool |
SaveParamsJson()
Persists the current stimulation params to disk using the underlying config's Save(). Thread-safe via the config layer.
Declaration
public void SaveParamsJson()
SetAllChannelsAmpMode(string)
Sets the amplitude-control mode for every channel in one call.
Declaration
public void SetAllChannelsAmpMode(string mode)
Parameters
| Type | Name | Description |
|---|---|---|
| string | mode |
SetChannelAmp(int, float)
Sets the default amplitude (PA) for a channel. Used when PW is the controlled axis.
Declaration
public void SetChannelAmp(int ch, float mA)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | |
| float | mA |
SetChannelAmpMode(int, string)
Sets the amplitude-control mode ("PW" or "PA") for the specified channel.
Declaration
public void SetChannelAmpMode(int ch, string mode)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | |
| string | mode |
SetChannelDefault(int, float)
Sets the non-controlled axis default (PA when PW mode, PW when PA mode).
Declaration
public void SetChannelDefault(int ch, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | 1-based logical channel. |
| float | value | Default value expressed in the non-controlled axis units (µs for PA mode). |
SetChannelDefaultPW(int, int)
Sets the default pulse width used when PA is the controlled axis.
Declaration
public void SetChannelDefaultPW(int ch, int us)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | |
| int | us |
SetChannelIPI(int, int)
Sets inter-pulse interval (IPI) for the specified channel in mili seconds.
Declaration
public void SetChannelIPI(int ch, int ms)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | |
| int | ms |
SetChannelMax(int, float)
Sets the active-control maximum for a channel (µs when PW mode, mA when PA mode).
Declaration
public void SetChannelMax(int ch, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | 1-based logical channel. |
| float | value | Maximum value in the active axis units (µs for PW mode). |
SetChannelMin(int, float)
Sets the active-control minimum for a channel (µs when PW mode, mA when PA mode).
Declaration
public void SetChannelMin(int ch, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | 1-based logical channel. |
| float | value | Minimum value in the active axis units (µs for PW mode). |
SetChannelPAMax(int, float)
Sets maximum PA (mA) for the specified channel.
Declaration
public void SetChannelPAMax(int ch, float mA)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | |
| float | mA |
SetChannelPAMin(int, float)
Sets minimum PA (mA) for the specified channel.
Declaration
public void SetChannelPAMin(int ch, float mA)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | |
| float | mA |
SetChannelPWMax(int, int)
Sets maximum pulse width for the specified channel in micro seconds.
Declaration
public void SetChannelPWMax(int ch, int us)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | |
| int | us |
SetChannelPWMin(int, int)
Sets minimum pulse width for the specified channel in micro seconds.
Declaration
public void SetChannelPWMin(int ch, int us)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | |
| int | us |
Shutdown()
Stops streaming, attempts to zero outputs, disconnects transport, and releases resources. Safe to call multiple times.
Declaration
public void Shutdown()
StartStim(WssTarget)
Starts stimulation on the target and launches streaming when ready.
Declaration
public void StartStim(WssTarget t)
Parameters
| Type | Name | Description |
|---|---|---|
| WssTarget | t |
Started()
True when device transport is started or streaming.
Declaration
public bool Started()
Returns
| Type | Description |
|---|---|
| bool |
StimulateAnalog(int, int, float, int)
Caches per-channel amplitude, pulse width, and IPI. No I/O here; the streaming loop pushes cached values to the device.
Declaration
public void StimulateAnalog(int ch, int pw, float amp, int ipi)
Parameters
| Type | Name | Description |
|---|---|---|
| int | ch | |
| int | pw | |
| float | amp | Amplitude (mA domain; mapped to device scale during streaming). |
| int | ipi |
StimulateNormalized(int, float)
Computes a pulse width from a normalized value in [0,1] using per-channel parameters (minPW, maxPW, amp, IPI) and forwards the result to the core. Implementations clamp the input to [0,1] and cache the last PW sent.
Declaration
public void StimulateNormalized(int channel, float value01)
Parameters
| Type | Name | Description |
|---|---|---|
| int | channel | 1-based logical channel. |
| float | value01 |
StopStim(WssTarget)
Stops stimulation on the target and, if streaming, stops the background loop.
Declaration
public void StopStim(WssTarget t)
Parameters
| Type | Name | Description |
|---|---|---|
| WssTarget | t |
Tick()
Advances the internal state machine (e.g., Connecting → SettingUp → Ready → Streaming). Call regularly from the main loop.
Declaration
public void Tick()
TryGetBasic(out IBasicStimulation)
Exposes the optional BASIC capability if available from the wrapped core.
Returns true and sets basic if supported.
Declaration
public bool TryGetBasic(out IBasicStimulation basic)
Parameters
| Type | Name | Description |
|---|---|---|
| IBasicStimulation | basic | Out parameter for the BASIC interface. |
Returns
| Type | Description |
|---|---|
| bool |
|
TryGetStimParam(string, out float)
Attempts to retrieve a stimulation parameter value without throwing.
Declaration
public bool TryGetStimParam(string key, out float value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Parameter key. |
| float | value | Output value if found. |
Returns
| Type | Description |
|---|---|
| bool | True if the parameter exists. |
ZeroOutStim(WssTarget)
Sends a zero-out command. Does not alter cached values.
Declaration
public void ZeroOutStim(WssTarget t)
Parameters
| Type | Name | Description |
|---|---|---|
| WssTarget | t |