Skip to content

Add FFI Functions for Clamp Control#2559

Open
MichaelHuth wants to merge 4 commits into
mainfrom
feature/2559-mh_add_ffi_clamp_control
Open

Add FFI Functions for Clamp Control#2559
MichaelHuth wants to merge 4 commits into
mainfrom
feature/2559-mh_add_ffi_clamp_control

Conversation

@MichaelHuth

Copy link
Copy Markdown
Collaborator

close #2547

@MichaelHuth MichaelHuth self-assigned this Oct 30, 2025
@MichaelHuth MichaelHuth added FFI Foreign Function Interface PatchLink labels Oct 30, 2025
@t-b

t-b commented Oct 30, 2025

Copy link
Copy Markdown
Collaborator

Let's do your usual appraoch here where Luke/Tim can test the FFI functions before we write the tests.

@MichaelHuth MichaelHuth force-pushed the feature/2559-mh_add_ffi_clamp_control branch 2 times, most recently from 2f8e923 to d5bf06c Compare October 30, 2025 19:23
@MichaelHuth

Copy link
Copy Markdown
Collaborator Author

If the current clamp mode for the headstage in MIES is different from the specific calmp mode of an amplifier setting (e.g. auto bridge balance that applies only to IC) then it is ignored by MIES.

@campagnola

Copy link
Copy Markdown
Member

I gave this a try today:

  • I need a way to get the state of the clamp for any mode, not just the currently active mode. I suggest always returning all fields for both modes regardless of the current clamp mode (much simpler, but is there a cost to assembling these structures?). Alternatively, add a mode argument to FFI_GetClampState that can optionally be -1 to request the current mode.
  • missing GetHeadstageActive (or is there another way to get this?)
  • missing SetHoldingPotentialEnable and SetBiasCurrentEnable

@campagnola

Copy link
Copy Markdown
Member

If the current clamp mode for the headstage in MIES is different from the specific calmp mode of an amplifier setting (e.g. auto bridge balance that applies only to IC) then it is ignored by MIES.

That makes sense for any of the TriggerAuto* functions, but all other parameters I would expect to be settable even when the mode is not active (for example, I should be able to set the auto bias parameters before switching to IC)

@t-b

t-b commented Jan 20, 2026

Copy link
Copy Markdown
Collaborator

I think this is on @MichaelHuth plate again.

@t-b t-b assigned t-b and unassigned MichaelHuth Feb 25, 2026
@t-b

t-b commented Feb 25, 2026

Copy link
Copy Markdown
Collaborator

@MichaelHuth I'm also taking over this one.

@t-b t-b assigned MichaelHuth and unassigned t-b Apr 30, 2026
this was previously done directly in the GUI event handler
@MichaelHuth MichaelHuth force-pushed the feature/2559-mh_add_ffi_clamp_control branch from d5bf06c to 93afc3b Compare May 7, 2026 15:33
Copilot AI review requested due to automatic review settings May 7, 2026 15:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new Foreign Function Interface (FFI) entry points intended for external (ACQ4/ZeroMQ) control/inspection of amplifier clamp settings, addressing issue #2547 by avoiding direct GUI element access.

Changes:

  • Added FFI functions to query clamp state and to set/trigger several clamp-related controls (mode, holding potential, bias current, auto bias, headstage active, and auto clamp actions).
  • Introduced DAP_SetClampMode as a shared helper and wired the clamp-mode checkbox handler to use it.
  • Exposed AI_AmpStorageControlToRowLabel for cross-module use and added a range assertion for the AutoBias Vcom parameter.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
Packages/MIES/MIES_ForeignFunctionInterface.ipf Adds clamp-control-related FFI functions, including FFI_GetClampState and several setters/triggers.
Packages/MIES/MIES_DAEphys.ipf Refactors clamp-mode setting into DAP_SetClampMode and uses it from the GUI checkbox handler.
Packages/MIES/MIES_AmplifierInteraction.ipf Adds AutoBias Vcom range assertion and makes AI_AmpStorageControlToRowLabel non-static for use by FFI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf Outdated
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf Outdated
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf Outdated
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf
Comment thread Packages/MIES/MIES_AmplifierInteraction.ipf Outdated
In MIES the range is limited through the corresponding GUi element.
However, when changed externally through a ZeroMQ function call then
the range was not checked.
With AI_GetFunctionConstantForClampMode the relevant function numbers
can be retrieved and with AI_MapFunctionConstantToControl the
corresponding GUI control names.
This gives a list of GUI controls for each clamp mode.
In AI_AmpStorageControlToRowLabel the block was incorrectly sorted in
the case chain.
Copilot AI review requested due to automatic review settings May 8, 2026 14:42
@MichaelHuth MichaelHuth force-pushed the feature/2559-mh_add_ffi_clamp_control branch from f2c45fb to c4e9cc9 Compare May 8, 2026 14:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf Outdated
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf Outdated
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf
Comment thread Packages/MIES/MIES_DAEphys.ipf
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf
@MichaelHuth MichaelHuth force-pushed the feature/2559-mh_add_ffi_clamp_control branch from c4e9cc9 to ddddce4 Compare May 8, 2026 16:48
Copilot AI review requested due to automatic review settings May 8, 2026 17:21
@MichaelHuth MichaelHuth force-pushed the feature/2559-mh_add_ffi_clamp_control branch from ddddce4 to 3b13ea8 Compare May 8, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf Outdated
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf Outdated
Comment thread Packages/MIES/MIES_AmplifierInteraction.ipf
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf
Comment thread Packages/MIES/MIES_ForeignFunctionInterface.ipf
Added the following functions:

FFI_GetCurrentClampState
returns a wave with the current clamp control values

FFI_GetClampState
returns a wave with the all clamp control values

FFI_SetClampMode

FFI_SetHoldingPotential
- allowed only in VC mode

FFI_SetBiasCurrent
- allowed only in IC mode

FFI_SetAutoBias
- allowed only in IC mode

FFI_SetHeadstageActive
- allowed only when no DAQ is running

FFI_GetHeadstageActive
- returns 1 is the given headstage is active, 0 otherwise

FFI_TriggerAutoClampControl
- wraps Pipette, Capacitance and Bridge Balance auto setting in a single call
@MichaelHuth MichaelHuth force-pushed the feature/2559-mh_add_ffi_clamp_control branch from 3b13ea8 to 984406a Compare May 8, 2026 17:56
@MichaelHuth

Copy link
Copy Markdown
Collaborator Author

@campagnola I changed the following:

  • previous FFI_GetClampState is now FFI_GetCurrentClampState
  • New FFI_GetClampState returns now the Amplifier Storage Wave from MIES for the specified headstage with all amplifier settings. The wave has dimension labels and the function has docu.
  • FFI_SetHoldingPotential and FFI_SetBiasCurrent have an additional enable argument that can be 0 (disable) and 1 (enable). When you set enable the value is written first then it is enabled, if you disable then it is first disabled and then the value set.
  • FFI_SetAutoBias uses the same order for value setting and enabling as FFI_SetHoldingPotential and FFI_SetBiasCurrent
  • New FFI_GetHeadstageActive returns 1 or 0, depending if the given headstage is enabled or not.
  • FFI_SetHeadstageActive raises an assertion when attempting to activate a headstage while data acquisition is running
  • For FFI_SetClampMode the clamp mode change is deferred if data acquisition is running until it stopped. If that is problematic I can also add an assertion there for this case.

@MichaelHuth MichaelHuth assigned campagnola and unassigned MichaelHuth May 8, 2026
@t-b

t-b commented May 28, 2026

Copy link
Copy Markdown
Collaborator

@campagnola Friendly ping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FFI Foreign Function Interface PatchLink

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FFI for clamp control

4 participants