diff --git a/Packages/MIES/MIES_AmplifierInteraction.ipf b/Packages/MIES/MIES_AmplifierInteraction.ipf index 6df74fc957..3e7dc54873 100644 --- a/Packages/MIES/MIES_AmplifierInteraction.ipf +++ b/Packages/MIES/MIES_AmplifierInteraction.ipf @@ -1097,7 +1097,7 @@ Function AI_SendToAmp(device, headStage, mode, func, value, [checkBeforeWrite, u string str ASSERT(func > MCC_BEGIN_INVALID_FUNC && func < MCC_END_INVALID_FUNC, "MCC function constant is out for range") - ASSERT(headStage >= 0 && headStage < NUM_HEADSTAGES, "invalid headStage index") + ASSERT(IsValidHeadstage(headstage), "invalid headStage index") AI_AssertOnInvalidClampMode(mode) if(ParamIsDefault(checkBeforeWrite)) diff --git a/Packages/MIES/MIES_ForeignFunctionInterface.ipf b/Packages/MIES/MIES_ForeignFunctionInterface.ipf index 056ed44318..d27507472b 100644 --- a/Packages/MIES/MIES_ForeignFunctionInterface.ipf +++ b/Packages/MIES/MIES_ForeignFunctionInterface.ipf @@ -72,3 +72,15 @@ Function/WAVE FFI_GetAvailableMessageFilters() return wv End + +/// @brief Set the headstage/cell electrode name +Function FFI_SetCellElectrodeName(string device, variable headstage, string name) + + DAP_AbortIfUnlocked(device) + ASSERT(IsValidHeadstage(headstage), "Invalid headstage index") + ASSERT(H5_IsValidIdentifier(name), "Name of the electrode/headstage needs to be a valid HDF5 identifier") + + WAVE/T cellElectrodeNames = GetCellElectrodeNames(device) + + cellElectrodeNames[headstage] = name +End diff --git a/Packages/MIES/MIES_MiesUtilities_Checks.ipf b/Packages/MIES/MIES_MiesUtilities_Checks.ipf index f4d0441a69..910b037c46 100644 --- a/Packages/MIES/MIES_MiesUtilities_Checks.ipf +++ b/Packages/MIES/MIES_MiesUtilities_Checks.ipf @@ -56,3 +56,11 @@ Function IsValidSamplingMultiplier(multiplier) return IsFinite(multiplier) && WhichListItem(num2str(multiplier), DAP_GetSamplingMultiplier()) != -1 End + +/// @brief Check if the given headstage index is valid +/// +/// UTF_NOINSTRUMENTATION +threadsafe Function IsValidHeadstage(variable headstage) + + return IsInteger(headstage) && headstage >= 0 && headstage < NUM_HEADSTAGES +End diff --git a/Packages/MIES/MIES_MiesUtilities_Config.ipf b/Packages/MIES/MIES_MiesUtilities_Config.ipf index 87a4e0aa85..cfabba2a96 100644 --- a/Packages/MIES/MIES_MiesUtilities_Config.ipf +++ b/Packages/MIES/MIES_MiesUtilities_Config.ipf @@ -60,7 +60,7 @@ End threadsafe Function/S GetDefaultElectrodeName(headstage) variable headstage - ASSERT_TS(headstage >= 0 && headstage < NUM_HEADSTAGES, "Invalid headstage") + ASSERT_TS(IsValidHeadstage(headstage), "Invalid headstage") return num2str(headstage) End diff --git a/Packages/MIES/MIES_MiesUtilities_Logbook.ipf b/Packages/MIES/MIES_MiesUtilities_Logbook.ipf index d7afd86f7b..bd8ecff6ef 100644 --- a/Packages/MIES/MIES_MiesUtilities_Logbook.ipf +++ b/Packages/MIES/MIES_MiesUtilities_Logbook.ipf @@ -1041,7 +1041,7 @@ threadsafe Function/WAVE GetLastSettingEachRAC(numericalValues, sweepNo, setting variable i, numSweeps - ASSERT_TS(headstage >= 0 && headstage < NUM_HEADSTAGES, "Invalid headstage") + ASSERT_TS(IsValidHeadstage(headstage), "Invalid headstage") WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo) if(!WaveExists(sweeps) || DimSize(sweeps, ROWS) == 0) @@ -1083,7 +1083,7 @@ threadsafe Function/WAVE GetLastSettingTextEachRAC(numericalValues, textualValue variable i, numSweeps - ASSERT_TS(headstage >= 0 && headstage < NUM_HEADSTAGES, "Invalid headstage") + ASSERT_TS(IsValidHeadstage(headstage), "Invalid headstage") WAVE/Z sweeps = AFH_GetSweepsFromSameRACycle(numericalValues, sweepNo) if(!WaveExists(sweeps) || DimSize(sweeps, ROWS) == 0) @@ -1258,7 +1258,7 @@ threadsafe Function/WAVE GetLastSettingEachSCI(numericalValues, sweepNo, setting variable i, numSweeps - ASSERT_TS(headstage >= 0 && headstage < NUM_HEADSTAGES, "Invalid headstage") + ASSERT_TS(IsValidHeadstage(headstage), "Invalid headstage") WAVE/Z sweeps = AFH_GetSweepsFromSameSCI(numericalValues, sweepNo, headstage) if(!WaveExists(sweeps) || DimSize(sweeps, ROWS) == 0) @@ -1300,7 +1300,7 @@ threadsafe Function/WAVE GetLastSettingTextEachSCI(numericalValues, textualValue variable i, numSweeps - ASSERT_TS(headstage >= 0 && headstage < NUM_HEADSTAGES, "Invalid headstage") + ASSERT_TS(IsValidHeadstage(headstage), "Invalid headstage") WAVE/Z sweeps = AFH_GetSweepsFromSameSCI(numericalValues, sweepNo, headstage) if(!WaveExists(sweeps) || DimSize(sweeps, ROWS) == 0) diff --git a/Packages/MIES/MIES_PressureControl.ipf b/Packages/MIES/MIES_PressureControl.ipf index d17df4e778..2d451ab731 100644 --- a/Packages/MIES/MIES_PressureControl.ipf +++ b/Packages/MIES/MIES_PressureControl.ipf @@ -2207,7 +2207,7 @@ Function P_SetPressureMode(device, headStage, pressureMode, [pressure]) variable pressureMode variable pressure - ASSERT(headstage < NUM_HEADSTAGES && headStage >= 0, "Select headstage number between 0 and 7") + ASSERT(IsValidHeadstage(headStage), "Select headstage number between 0 and 7") ASSERT(pressureMode >= PRESSURE_METHOD_ATM && pressureMode <= PRESSURE_METHOD_MANUAL, "Select a pressure mode between -1 and 4") WAVE PressureDataWv = P_GetPressureDataWaveRef(device) diff --git a/Packages/tests/Basic/UTF_Utils_Checks.ipf b/Packages/tests/Basic/UTF_Utils_Checks.ipf index 68624b92e7..a4dc0d3148 100644 --- a/Packages/tests/Basic/UTF_Utils_Checks.ipf +++ b/Packages/tests/Basic/UTF_Utils_Checks.ipf @@ -438,3 +438,12 @@ static Function CheckMatchAgainstWildCardPatterns() End /// @} + +static Function TestIsValidHeadstageWorking() + + CHECK_EQUAL_VAR(IsValidHeadstage(0), 1) + CHECK_EQUAL_VAR(IsValidHeadstage(1), 1) + CHECK_EQUAL_VAR(IsValidHeadstage(NUM_HEADSTAGES - 1), 1) + CHECK_EQUAL_VAR(IsValidHeadstage(NaN), 0) + CHECK_EQUAL_VAR(IsValidHeadstage(1.5), 0) +End diff --git a/Packages/tests/HardwareBasic/UTF_BasicHardwareTests.ipf b/Packages/tests/HardwareBasic/UTF_BasicHardwareTests.ipf index 6e2e6339fc..0734bb1985 100644 --- a/Packages/tests/HardwareBasic/UTF_BasicHardwareTests.ipf +++ b/Packages/tests/HardwareBasic/UTF_BasicHardwareTests.ipf @@ -2471,10 +2471,8 @@ End static Function TestCustomElectrodeNamesInNWB_preAcq(string device) - WAVE/T cellElectrodeNames = GetCellElectrodeNames(device) - // must be valid HDF5 identifiers - cellElectrodeNames[0] = "Electric Dreams of Voltage" - cellElectrodeNames[1] = "Electric Dreams of Current" + FFI_SetCellElectrodeName(device, 0, "Electric Dreams of Voltage") + FFI_SetCellElectrodeName(device, 1, "Electric Dreams of Current") End // UTF_TD_GENERATOR DeviceNameGeneratorMD1