Skip to content

Commit 84ba40a

Browse files
committed
Fix infinite loop in P_CloseDevice and correct typos during pressure control.
- Fixed a potential infinite loop in `P_CloseDevice` (MIES_PressureControl.ipf) where the loop condition could remain true indefinitely if no matching headstage was found. Replaced the unsafe `do-while` loop with a bounded `for` loop. - Corrected spelling of `OngoingPessurePulse` to `OngoingPressurePulse` in [MIES_PressureControl.ipf](cci:7://file:///Users/timjarsky/MIES/Packages/MIES/MIES_PressureControl.ipf:0:0-0:0) and [MIES_WaveDataFolderGetters.ipf](cci:7://file:///Users/timjarsky/MIES/Packages/MIES/MIES_WaveDataFolderGetters.ipf:0:0-0:0) to ensure consistency in dimension labels.
1 parent a14309c commit 84ba40a

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

Packages/MIES/MIES_PressureControl.ipf

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -473,18 +473,20 @@ static Function P_CloseDevice(string device)
473473
variable i, j
474474

475475
numDevices = ItemsInList(ListOfDevicesToClose)
476+
variable numLocked = ItemsInList(ListOfLockedDA_Ephys)
476477
for(i = 0; i < numDevices; i += 1) // for all the devices used for pressure regulation
477478
// find device ID
478-
do
479+
for(j = 0; j < numLocked; j += 1)
479480
device = StringFromList(j, ListOfLockedDA_Ephys)
480481
DeviceToClose = StringFromList(i, ListOfDevicesToClose)
481482

482483
ListOfHeadstagesUsingDevice = P_HeadstageUsingDevice(device, DeviceToClose)
483-
j += 1
484-
while(cmpstr("", ListOfHeadstagesUsingDevice) == 0)
485-
j = 0
486-
headStage = NumberFromList(0, ListOfHeadstagesUsingDevice)
487-
P_CloseDeviceLowLevel(device, DeviceToClose, headstage)
484+
if(cmpstr("", ListOfHeadstagesUsingDevice) != 0)
485+
headStage = NumberFromList(0, ListOfHeadstagesUsingDevice)
486+
P_CloseDeviceLowLevel(device, DeviceToClose, headstage)
487+
break
488+
endif
489+
endfor
488490
endfor
489491
End
490492

@@ -1050,8 +1052,8 @@ static Function P_DataAcq(string device, variable headStage)
10501052
HW_StopAcq(hwType, deviceID, flags = HARDWARE_ABORT_ON_ERROR)
10511053

10521054
// record onset of data acquisition
1053-
pressureDataWv[][%OngoingPessurePulse] = 0 // ensure that only one headstage is recorded as having an ongoing pressure pulse
1054-
pressureDataWv[headStage][%OngoingPessurePulse] = 1 // record headstage with ongoing pressure pulse
1055+
pressureDataWv[][%OngoingPressurePulse] = 0 // ensure that only one headstage is recorded as having an ongoing pressure pulse
1056+
pressureDataWv[headStage][%OngoingPressurePulse] = 1 // record headstage with ongoing pressure pulse
10551057

10561058
if(hwType == HARDWARE_ITC_DAC)
10571059
HW_ITC_PrepareAcq(deviceID, UNKNOWN_MODE, dataFunc = P_GetITCData, configFunc = P_GetITCChanConfig)
@@ -1128,7 +1130,7 @@ Function P_ITC_FIFOMonitorProc(STRUCT WMBackgroundStruct &s)
11281130

11291131
if(!moreData)
11301132
HW_StopAcq(hwType, deviceID)
1131-
pressureDataWv[][%OngoingPessurePulse] = 0
1133+
pressureDataWv[][%OngoingPressurePulse] = 0
11321134
print "Pressure pulse is complete"
11331135
return 1
11341136
endif
@@ -1162,7 +1164,7 @@ static Function P_FindDeviceExecutingPP(string &device, variable &deviceID, vari
11621164
device = StringFromList(i, ListOfLockedDevices)
11631165
WAVE pressureDataWv = P_GetPressureDataWaveRef(device)
11641166
for(headStage = 0; headstage < NUM_HEADSTAGES; headStage += 1)
1165-
if(pressureDataWv[headStage][%OngoingPessurePulse])
1167+
if(pressureDataWv[headStage][%OngoingPressurePulse])
11661168
deviceID = pressureDataWv[headStage][%DAC_DevID]
11671169
return 1
11681170
endif

Packages/MIES/MIES_WaveDataFolderGetters.ipf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5021,7 +5021,7 @@ static Function SetPressureWaveDimLabels(WAVE wv)
50215021
// "good" as it is
50225022
SetDimLabel COLS, 26, TimeOfLastRSlopeCheck, wv
50235023
SetDimLabel COLS, 27, LastPressureCommand, wv
5024-
SetDimLabel COLS, 28, OngoingPessurePulse, wv
5024+
SetDimLabel COLS, 28, OngoingPressurePulse, wv
50255025
SetDimLabel COLS, 29, LastVcom, wv
50265026
SetDimLabel COLS, 30, ManSSPressure, wv
50275027
SetDimLabel COLS, 31, ManPPPressure, wv

0 commit comments

Comments
 (0)