$debug evtEvent = {} evtEvent.description = "Identify & measure resistance of Opto Heater connections" evtEvent.params = { {"resiMax","resistance",15000}} function evtEvent.DoIt(iEventType,resiMax) -- Opto-Heater connection monitoring routine -- -- Jose Alonso -- 3 April 2007 -- -- start with list of Heater connections, J1-xxx J1-xxy -- ... -- J1-zzz J1-zza -- -- (use single adapter at J1 plugged into LEMO Heater connector) -- -- Start routine assuming no connections made -- Measure resistance of each pair -- If <15K flag this pair as "changed" -- continue through list of nets -- at end, if any changes have occurred, write out window on screen -- and to output file -- Beep for attention and wait for action -- On acknowledgement, continue or stop and write file -- on continue, reset "changed" bits to establish new "std" config -- and loop through measurements again. -- if iEventType == 1 then longString = "\n" -- initialize output string -- -- get header information -- iHeaderOK = 2 while iHeaderOK ~= 1 do iHeaderOK = 1 iSide = MessageBox("Opto-Heater Hookup... Side","A","C") if iSide == 1 then aSide = "A" else aSide = "C" end -- iSide iSQP = MessageBox("Quadrant","{1,2}","{3,4}","{5,6}","{7,8}") if iSQP == 1 then aSQP = "12" elseif iSQP == 2 then aSQP = "34" elseif iSQP == 3 then aSQP = "56" else aSQP = "78" end -- if iSQP fileName = "Opto_Htr_meas_"..aSide..aSQP.."_" aComment = "Opto-Heater Hookup Test and Measurement\n\n" -- ask if header is OK iHeadOK = MessageBox("FileName = "..fileName,"OK","Try again","Abort") if iHeadOK == 2 then iHeaderOK = 2 -- try again elseif iHeadOK == 3 then return -- abort end -- iHeadOK end -- while iHeaderOK -- generate header for output aHeader = "_____________________________________________________\n\n"..aComment.."\n" aDate = date() aHeader = aHeader..fileName.."\n\n".."Date "..aDate.."\n\n_________\n\n" longString = longString..aHeader -- --*************************************************** -- -- entry on Start Test -- elseif iEventType == 2 then -- -- set up arrays: -- name[] = name of circuit, per OptoHeatingConnections.xls sheet -- point1[] = first point of nth network -- point2[] = second point of nth network -- setResis[] = preset (or REset resistance of this network) presets to open cct -- name = {} name[1] = "OSP-NTC-1-Left-Top" name[2] = "OSP-NTC-2-Right-Top" name[3] = "OSP-NTC-3-Left-Bottom" name[4] = "OSP-NTC-4-Right-Bottom" name[5] = "OSP-Heater-1-Left-Top" name[6] = "OSP-Heater-2-Right-Top" name[7] = "OSP-Heater-3-Left-Bottom" name[8] = "OSP-Heater-4-Right-Bottom" name[9] = "ISP-NTC-1-Left" name[10] = "ISP-NTC-2-Right" name[11] = "ISP-Heater-1-Left" name[12] = "ISP-Heater-2-Right" name[13] = "Drains" -- point1 = {} point1[1] = "J1-002" point1[2] = "J1-004" point1[3] = "J1-006" point1[4] = "J1-008" point1[5] = "J1-027" point1[6] = "J1-028" point1[7] = "J1-030" point1[8] = "J1-031" point1[9] = "J1-015" point1[10] = "J1-017" point1[11] = "J1-037" point1[12] = "J1-038" point1[13] = "J1-001" -- point2 = {} point2[1] = "J1-003" point2[2] = "J1-005" point2[3] = "J1-007" point2[4] = "J1-009" point2[5] = "J1-029" point2[6] = "J1-029" point2[7] = "J1-032" point2[8] = "J1-032" point2[9] = "J1-016" point2[10] = "J1-018" point2[11] = "J1-039" point2[12] = "J1-039" point2[13] = "J1-014" -- setResis = {} -- assume NTC has 10 K resistance, open will be higher than setpoint setResis[1] = 100000 setResis[2] = 100000 setResis[3] = 100000 setResis[4] = 100000 setResis[5] = 100000 setResis[6] = 100000 setResis[7] = 100000 setResis[8] = 100000 setResis[9] = 100000 setResis[10] = 100000 setResis[11] = 100000 setResis[12] = 100000 setResis[13] = 100000 -- -- -- -- begin looping through networks looking for changes -- -- iLoop = 1 while iLoop == 1 do -- changeVal = 0 while changeVal == 0 do networkIndex = 1 typeLine = "\n New scan\n" while networkIndex <= 13 do pt1 = point1[networkIndex] pt2 = point2[networkIndex] measRes, error = GetResistanceMeasurement(pt1,pt2) if measRes >= 100000 then measRes = 100000 -- assume open is 100K end -- compare with setpoint setpoint = setResis[networkIndex] diff = abs(setpoint - measRes) if diff >= 500 then -- a change has definitely happened if measRes == 100000 then smeas = "Open" elseif measRes > 1000 then ameas = measRes/1000 smeas = format("%4.2f",ameas) smeas = smeas.."K" else smeas = format("%4.2f",measRes) end if setpoint == 100000 then sset = "Open" elseif setpoint > 1000 then aset = setpoint/1000 sset = format("%4.2f",aset) sset = sset.."K" else sset = format("%4.2f",setpoint) end typeLine = typeLine..name[networkIndex].." from "..sset.." to "..smeas.."\n" changeVal = changeVal + 1 setResis[networkIndex] = measRes -- reset resistance value to new meas end -- if diff networkIndex = networkIndex + 1 end -- while networkIndex end -- while changeVal --- loop above (forever) until something changes longString = longString..typeLine PlaySound(349,.6,100) PlaySound(277,.6,100) iNext = MessageBox(typeLine.."\n What next?","Go on", "Exit") if iNext == 2 then iLoop = 2 end -- if iNext end -- while iLoop DumpFile() end -- ifIEvent end -- function main -- ************************************************ function DumpFile() -- write longString to C and H drives -- -- -- file name convention -- e.g. PairCernSQP_YsOpto_A78-OP-A7_L_RUN001_2006-02-21.txt -- (filename generated at start of run) iDate = date("%Y-%m-%d") fname = fileName..iDate fpath = "/DOS/touch1/#/"..fname..".txt" -- writes to "C:" drive, DOS/touch1/# MessageBox(fname,"Write File") -- check if file exists local fHandle,sErrr fHandle,sErrr = readfrom(fpath) if fHandle == nil then --file doesn't exist, create it writeto(fpath) writeto() end fHandle,sErrr = appendto(fpath) if sErrr ~= nil then MessageBox("Problem writing file "..fileName..sErrr) else write(longString) writeto() end -- -- duplicate above process, writing to "H" drive -- -- -- RemountDrive("H") fpathH = "/mnt/H/"..fname..".txt" -- writes to "H:" drive -- check if file exists fHandle,sErrr = readfrom(fpathH) if fHandle == nil then --file doesn't exist, create it writeto(fpathH) writeto() end fHandle,sErrr = appendto(fpathH) if sErrr ~= nil then MessageBox("Problem writing file "..fileName..sErrr) else write(longString) writeto() end -- that's all end