-;\r
-; AutoIt Version: 3.0\r
-; Language: English\r
-; Platform: Win9x/NT\r
-; Author: Benny Linnik (b.linnik@gsi.de)\r
-;\r
-; Script Function:\r
-; Reads MAPS running data from an Excel file and\r
-\r
-\r
-; set external parameters\r
-#include <String.au3>\r
-#include <GUIConstants.au3>\r
-#include <WindowsConstants.au3>\r
-#include <StaticConstants.au3>\r
-#Include <GuiEdit.au3>\r
-#include <Date.au3>\r
-#include "Mimosa32.au3"\r
-#include "Mimosa32Ter.au3"\r
-#include "Mimosa34.au3"\r
-\r
-$programversion = "0.7"\r
-$FileName = IniRead ( "config.ini", "experimental setup", "ExcelPath", "H:\dennis doering\Arbeitsprogramme\Mimosa34\LaborbuchMi34.xls" ) ; read path to Excel file\r
-$systemtemp = IniRead ( "config.ini", "experimental setup", "SystemTemperature", "20" ) ; current temperatur of the system\r
-$chipversion = IniRead ( "config.ini", "experimental setup", "ChipVersion", "Mi34" ) ; current chip generation in the system\r
-$chipinstalled = IniRead ( "config.ini", "experimental setup", "ChipInstalled", "5" ) ; chip number currently mounted into the system\r
-$radSource = IniRead ( "config.ini", "experimental setup", "RadSource", "none" ) ; current radioactive source of the system\r
-\r
-$excelLineBegin = "46" ; Change this to the range of cells you want to be processed\r
-$excelLineEnd = "500"\r
-Global $vref = 650 ; Initial vref, will be adjusted during runtime\r
-\r
-;create virtual functions\r
-Func GotoMiTab()\r
- Call ( $chipversion & "_GotoMiTab" )\r
-EndFunc\r
-\r
-Func GetVref()\r
- Return Call ( $chipversion & "_GetVref" )\r
-EndFunc\r
-\r
-Func SetVref($vref)\r
- Call ( $chipversion & "_SetVref", $vref )\r
-EndFunc\r
-\r
-Func SetMiParameter($matrix, $vref)\r
- Call ( $chipversion & "_SetMiParameter", $matrix, $vref )\r
-EndFunc\r
-\r
-Func SelectBoard()\r
- Call ( $chipversion & "_SelectBoard" )\r
-EndFunc\r
-\r
-$CellRange = "A" & $excelLineBegin &":N"& $excelLineEnd\r
-\r
-; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)\r
-Local $answer = MsgBox(4, "Run script?", "Preparing to do all runs in range " & $CellRange & @CRLF & _\r
- "of file " & $FileName & " with " & @CRLF & _\r
- "Temperatur: " & $systemtemp & " °C" & @CRLF & _\r
- "Radioactive source: " & $radSource & @CRLF & _\r
- "Chip: " & $chipversion & " (" & $chipinstalled & ")"& @CRLF & _\r
- "If you run this script, daq.exe will be closed and the current run aborted, proceed?")\r
-\r
-\r
-; Check the user's answer to the prompt (see the help file for MsgBox return values)\r
-; If "No" was clicked (7) then exit the script\r
-If $answer = 7 Then\r
- Exit\r
-EndIf\r
-\r
-If Not FileExists($FileName) Then ; Just a check to be sure..\r
- MsgBox(16, "Excel Data Test", "Error: Can't find file " & $FileName)\r
- Exit\r
-EndIf\r
-\r
-$oExcelDoc = ObjGet($FileName) ; Get an Excel Object from an existing filename\r
-\r
-If (Not @error) And IsObj($oExcelDoc) Then ; Check again if everything went well\r
- ; NOTE: $oExcelDoc is a "Workbook Object", not Excel itself!\r
- $oDocument = $oExcelDoc.Worksheets(1) ; We use the 'Default' worksheet\r
- $aArray = $oDocument.range($CellRange).value ; Retrieve the cell values from given range\r
- ;$oExcelDoc.Close ; Close the Excel document\r
- ; The data should now be in the 2-dimensional array: $aArray\r
-\r
- If IsArray($aArray) And UBound($aArray, 0) > 0 Then ; Check if we retrieved any data\r
- ;Msgbox (0,"Excel Data Test","Debugging information for retrieved cells:" & @CRLF & _\r
- ; "Number of dimensions: " & UBound($aArray,0) & @CRLF & _\r
- ; "Size of first dimension: " & Ubound($aArray,1) & @CRLF & _\r
- ; "Size of second dimension: " & Ubound($aArray,2))\r
- ; "Size of second dimension: " & Ubound($aArray,2))\r
-\r
- ; The next lines are just for debugging purposes, it puts all cell values into\r
- ; a string to display in a MsgBox.\r
- ; Note: you can't use a FOR..IN loop for a multi-dimensional array!\r
-;~ ; debugging read data\r
-;~ $string=""\r
-;~ for $x=0 to ubound($aArray,1)-1\r
-;~ for $y=0 to ubound ($aArray,2)-1\r
-;~ $string=$string & "(" & $x & "," & $y & ")=" & $aArray[$x][$y] & @CRLF\r
-;~ Next\r
-;~ Next\r
-;~ Msgbox(0,"Excel Data Test","Debug information: Read Cell contents: " & @CRLF & $string)\r
-\r
- $totallexcelines=UBound($aArray, 2)\r
- $totalruns = 0\r
- For $run = 0 To UBound($aArray, 2) - 1\r
- If ($aArray[4][$run] == $systemtemp And $aArray[6][$run] == $chipinstalled And "Mi"&$aArray[2][$run] == $chipversion And $aArray[10][$run] == $radSource And $aArray[0][$run] == "") Then\r
- $totalruns = $totalruns + 1\r
- EndIf\r
- Next\r
- Local $answer = MsgBox(4, "Total runs", "Number of suitable runs found at the moment: " & $totalruns )\r
- If $answer = 7 Then\r
- Exit\r
- EndIf\r
-\r
- If ProcessExists("daq.exe") = True Then\r
- ProcessClose("daq.exe")\r
- ProcessWaitClose("daq.exe")\r
- EndIf\r
-\r
- If ProcessExists("i2c_ms_gui.exe") = True Then\r
- ProcessClose("i2c_ms_gui.exe")\r
- ProcessWaitClose("i2c_ms_gui.exe")\r
- EndIf\r
-\r
- Run("C:\ccmos_daq\v3.5.10\daq_v3.5.10.bat", "C:\ccmos_daq\v3.5.10\")\r
- WinWait("Debug")\r
- ControlClick("Debug", "", "[TEXT:Messages Clear]")\r
- Sleep(100)\r
- ControlClick("Debug", "", "[TEXT:Board Testing]")\r
- Sleep(2000)\r
- $i = 0\r
- Do\r
- $text = WinGetText("[CLASS:TDebugFrm]", "")\r
- $texthex = _StringToHex($text)\r
- If ($texthex == "4D657373616765730A5072696E7420426F6172647320526567730A0D0A3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D0D0A426F6172642049643D302074657374207374617274696E67202E2E2E0D0A3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D0D0A0D0A53746F70206163717569736974696F6E202E2E2E0D0A41445220434F554E54455220412074657374696E67202E2E2E0D0A41445220434F554E54455220412030204572726F72730D0A52414D20412074657374696E67202E2E2E0D0A52414D20412030204572726F72730D0A52414D20422074657374696E67202E2E2E0D0A52414D20422030204572726F72730D0A52414D20432074657374696E67202E2E2E0D0A52414D20432030204572726F72730D0A52414D20442074657374696E67202E2E2E0D0A52414D20442030204572726F72730D0A0D0A3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D0D0A426F6172642049643D312074657374207374617274696E67202E2E2E0D0A3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D0D0A0D0A53746F70206163717569736974696F6E202E2E2E0D0A41445220434F554E54455220412074657374696E67202E2E2E0D0A41445220434F554E54455220412030204572726F72730D0A52414D20412074657374696E67202E2E2E0D0A52414D20412030204572726F72730D0A52414D20422074657374696E67202E2E2E0D0A52414D20422030204572726F72730D0A52414D20432074657374696E67202E2E2E0D0A52414D20432030204572726F72730D0A52414D20442074657374696E67202E2E2E0D0A52414D20442030204572726F72730D0A0A555342322042616E647769647468204D65617375726D656E740A426F6172642054657374696E670A536F66747761726520496E697469616C697A6174696F6E0A4D6573736167657320436C6561720A") Then\r
- EndIf\r
- Sleep(500)\r
- $i = $i + 1\r
- If ($i > 20) Then\r
- MsgBox(16, "Message", "USB Boards could be not OK! Please check the Debug output.")\r
- Exit\r
- EndIf\r
- Until 1\r
- If StringRegExp ( $text, "[1-9]+ Errors" ) Then ; for some reasons the previous check sometimes doesn't work.\r
- MsgBox(16, "Message", "USB Boards could be not OK! Please check the Debug output.")\r
- Exit\r
- EndIf\r
-\r
-\r
- WinClose("Debug")\r
- WinWaitClose("Debug", 1000)\r
- $aArray = 0\r
- $totalrealruns=0\r
-\r
- For $run = 0 To $totallexcelines-1\r
-\r
- $currentrange="A"& $excelLineBegin+$run & ":N" & $excelLineBegin+$run\r
- $oExcelDoc = ObjGet($FileName) ; if doc was closed and object destroyed -> reopen it. A possibility to check if object exists would come handy here....\r
- $oDocument = $oExcelDoc.Worksheets(1) ; We use the 'Default' worksheet\r
- $currentline=$oDocument.range($currentrange).value\r
- If ($currentline[4][0] == $systemtemp And $currentline[6][0] == $chipinstalled And "Mi"&$currentline[2][0] == $chipversion And $currentline[10][0] == $radSource And $currentline[0][0] == "") Then\r
- $clock = $currentline[11][0] ; save needed clock\r
- If $clock == "" Then\r
- $clock = "100"\r
- $currentline[11][0] = "100"\r
- EndIf\r
- $runnum = $currentline[3][0] ; save runnumber\r
- $matrix = $currentline[9][0] ; save matrix\r
- $eventnum = $currentline[5][0] ; save number of events to save\r
- If $eventnum == "" Then\r
- $eventnum = 100000\r
- $currentline[5][0] = "100000"\r
- EndIf\r
-\r
- CheckWindowExist()\r
- SelectBoard()\r
- CheckIfBoardOK()\r
- GotoDebugTab()\r
-\r
- If ($clock == "100") Then\r
- ControlCommand($chipsoftware[0], "", "[TEXT:Intern]", "Check")\r
- ;If (Not ControlCommand("I2C control Software for Mimosa32", "", "[TEXT:Intern]", "IsChecked")) Then\r
- ;Msgbox (16,"Message","Could not set clock to intern")\r
- ;EndIf\r
- Else\r
- ShellExecuteWait ("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'SOURce1:FREQuency:Fixed " & $clock & "Mhz'", "", "", @SW_HIDE)\r
- ShellExecuteWait ("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'SOURce1:VOLTage:HIGH 3.3'", "", "", @SW_HIDE)\r
- ShellExecuteWait ("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'SOURce1:VOLTage:LOW 0'", "", "", @SW_HIDE)\r
- ShellExecuteWait ("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'OUTPut1:STATe ON'", "", "", @SW_HIDE)\r
- Sleep(500)\r
- ControlCommand("I2C control Software for Mimosa32", "", "[TEXT:Extern]", "Check")\r
- ;If (Not ControlCommand("I2C control Software for Mimosa32", "", "[TEXT:Extern]", "IsChecked")) Then\r
- ;Msgbox (16,"Message","Could not set clock to extern")\r
- ;EndIf\r
- EndIf\r
-\r
- GotoMiTab()\r
- SetMiParameter($matrix, $vref)\r
- ProgramMi()\r
-\r
- If WinExists("CMOS USB DAQ V3.5.10") = True Then\r
- ;WinActivate("CMOS USB DAQ V3.5.10")\r
- Else\r
- Run("C:\ccmos_daq\v3.5.10\daq_v3.5.10.bat", "C:\ccmos_daq\v3.5.10\")\r
- EndIf\r
- WinWait("CMOS USB DAQ V3.5.10")\r
-\r
- For $i = 0 To 20\r
- ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabLeft")\r
- Next\r
- $i = 0\r
- While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TTabSheet1") <> "Run Parameters")\r
- If ($i > 20) Then\r
- MsgBox(0, "Message", "CMOS USB DAQ V3.5.10 RUN tab not found in DAQ software!")\r
- Exit\r
- EndIf\r
- ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabRight")\r
- $i = $i + 1\r
- Sleep(100)\r
- WEnd\r
-\r
- ControlSetText("CMOS USB DAQ V3.5.10", "", "TEdit23", "")\r
- Sleep(100)\r
- ControlFocus("CMOS USB DAQ V3.5.10", "", "TEdit23")\r
- ;Send($runnum)\r
- ControlSend("CMOS USB DAQ V3.5.10", "", "TEdit23", $runnum)\r
-\r
- ControlSetText("CMOS USB DAQ V3.5.10", "", "TEdit22", "")\r
- Sleep(100)\r
- ControlFocus("CMOS USB DAQ V3.5.10", "", "TEdit22")\r
-;~ Send($eventnum)\r
- ControlSend("CMOS USB DAQ V3.5.10", "", "TEdit22", $eventnum)\r
- ControlFocus("CMOS USB DAQ V3.5.10", "", "TEdit23")\r
-\r
- Sleep(1000)\r
- $starttime = _NowCalc()\r
-\r
- ControlClick("CMOS USB DAQ V3.5.10", "", "[TEXT:Start Run;CLASS:TButton]")\r
- ;WinWaitActive("Avertissement") ;Force overwrite\r
- ;ControlClick("Avertissement", "", "TButton2")\r
-\r
- Sleep(500)\r
- If (WinExists("Avertissement")) Then\r
- MsgBox(16, "Message", "Stopping. Could overwrite data!")\r
- Exit\r
- EndIf\r
-\r
-\r
- $i = 0\r
- While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TTabSheet1") <> "Local Monitoring")\r
- If ($i > 20) Then\r
- MsgBox(0, "Message", "CMOS USB DAQ V3.5.10 Local Monitoring tab not found in DAQ software!")\r
- Exit\r
- EndIf\r
- ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabRight")\r
- $i = $i + 1\r
- Sleep(100)\r
- WEnd\r
-\r
- Sleep(1000)\r
-\r
- $avg = ControlGetText("CMOS USB DAQ V3.5.10", "", "[TEXT:DispAvg;CLASS:TEdit]")\r
- For $i = 0 To 20\r
- ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabLeft")\r
- Next\r
- $i = 0\r
- While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TTabSheet1") <> "Run Parameters")\r
- If ($i > 20) Then\r
- MsgBox(0, "Message", "CMOS USB DAQ V3.5.10 RUN tab not found in DAQ software!")\r
- Exit\r
- EndIf\r
- ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabRight")\r
- $i = $i + 1\r
- Sleep(100)\r
- WEnd\r
- $j = 0\r
- If ($avg > 2300 Or $avg < 1700) Then\r
- Do\r
- ControlClick("CMOS USB DAQ V3.5.10", "", "[TEXT:Stop Run;CLASS:TButton]")\r
- ;WinActivate("I2C control Software for Mimosa32")\r
- $vref = GetVref()\r
- ;$vref = ControlGetText("I2C control Software for Mimosa32", "", "TEdit11")\r
- $diff = $avg - 2000\r
- Select\r
- Case Abs($diff) > 600\r
- $vref = $vref + SGN($diff) * 100\r
- Case Else\r
- $vref = $vref +SGN($diff) * 50\r
- EndSelect\r
- If ($vref > 1000 Or $vref < 300) Then\r
- MsgBox(0, "Message", "Stopped, vref value needs to be too low (<300) or too high (>1000), please check manually!")\r
- Exit\r
- EndIf\r
-\r
- ;ControlSetText("I2C control Software for Mimosa32", "", "TEdit11", $vref)\r
- ;ControlClick("I2C control Software for Mimosa32", "", "[TEXT:Prog All Analog;CLASS:TButton]")\r
- SetVref($vref)\r
- ProgramMi()\r
- ;WinActivate("CMOS USB DAQ V3.5.10")\r
- WinWait("CMOS USB DAQ V3.5.10")\r
- Sleep(1000)\r
- ControlClick("CMOS USB DAQ V3.5.10", "", "[TEXT:Start Run;CLASS:TButton]")\r
- WinWait("Avertissement")\r
- ControlClick("Avertissement", "", "TButton2")\r
-\r
-\r
- $i = 0\r
- While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TTabSheet1") <> "Local Monitoring")\r
- If ($i > 20) Then\r
- MsgBox(0, "Message", "CMOS USB DAQ V3.5.10 Local Monitoring tab not found in DAQ software!")\r
- Exit\r
- EndIf\r
- ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabRight")\r
- $i = $i + 1\r
- Sleep(100)\r
- WEnd\r
-\r
- Sleep(1000)\r
-\r
- $avg = ControlGetText("CMOS USB DAQ V3.5.10", "", "[TEXT:DispAvg;CLASS:TEdit]")\r
- For $i = 0 To 20\r
- ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabLeft")\r
- Next\r
- $i = 0\r
- While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TTabSheet1") <> "Run Parameters")\r
- If ($i > 20) Then\r
- MsgBox(0, "Message", "CMOS USB DAQ V3.5.10 RUN tab not found in DAQ software!")\r
- Exit\r
- EndIf\r
- ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabRight")\r
- $i = $i + 1\r
- Sleep(100)\r
- WEnd\r
-\r
- $j = $j + 1\r
- If ($j > 7) Then\r
- ControlClick("CMOS USB DAQ V3.5.10", "", "[TEXT:Stop Run;CLASS:TButton]")\r
- MsgBox(0, "Message", "VRef could not be set properly")\r
- Exit\r
- EndIf\r
-\r
- Until ($avg < 2300 And $avg > 1700)\r
- EndIf\r
-\r
- While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TEdit18") < $eventnum)\r
- Sleep(10000)\r
- ;If EnvGet('SESSIONNAME') <> "Console" Then\r
- ;ShowWarning()\r
- ;EndIf\r
- ;WinWait("CMOS USB DAQ V3.5.10")\r
- WEnd\r
- WinWait("CMOS USB DAQ V3.5.10")\r
- ControlClick("CMOS USB DAQ V3.5.10", "", "[TEXT:Stop Run;CLASS:TButton]")\r
- ;If ($clock <> "100") Then\r
- ; ShellExecuteWait("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'OUTPut1:STATe Off'", "", "", @SW_HIDE)\r
- ;EndIf\r
-\r
- $currentline[0][0] = @MDAY & "." & @MON & "." & @YEAR\r
- $currentline[8][0] = $vref\r
- $calcmin = _DateDiff('s', $starttime, _NowCalc()) ; n for minites, s for seconds\r
- $currentline[13][0] = "Automated run, performed by V." & $programversion & " runtime in minutes: " & $calcmin\r
-\r
- $oExcelDoc = ObjGet($FileName) ; if doc was closed and object destroyed -> reopen it. A possibility to check if object exists would come handy here....\r
- $oDocument = $oExcelDoc.Worksheets(1) ; We use the 'Default' worksheet\r
- $oDocument.range($currentrange).value = $currentline\r
- $oExcelDoc.Windows(1).Visible = True ; Otherwise the worksheet window will be saved 'hidden'\r
- $oExcelDoc.Save ; Save the workbook\r
-\r
- $oExcelDoc.saved = 1\r
- $totalrealruns = $totalrealruns + 1\r
- EndIf\r
- Next\r
- ShellExecuteWait("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'OUTPut1:STATe Off'", "", "", @SW_HIDE)\r
- MsgBox(0, "Sucess!", "All runs (" & $totalrealruns & ") ended without errors." & @CRLF & _\r
- "Please check the Excel sheet and the results for errors.")\r
-\r
- Else\r
- MsgBox(0, "Excel Data Test", "Error: Could not retrieve data from cell range: " & $CellRange)\r
- EndIf\r
-\r
-Else\r
- MsgBox(0, "Excel Data Test", "Error: Could not open " & $FileName & " as an Excel Object.")\r
-EndIf\r
-\r
-$oExcelDoc = 0\r
-\r
-\r
-Func SGN($i)\r
- Return ($i>0)-($i<0)\r
- EndFunc ;==>SGN\r
-\r
- Func CheckValues($vref, $matrix, $runnum, $eventnum, $clock)\r
- Return 0\r
-EndFunc\r
+;
+; AutoIt Version: 3.0
+; Language: English
+; Platform: Win9x/NT
+; Author: Benny Linnik (b.linnik@gsi.de)
+;
+; Script Function:
+; Reads MAPS running data from an Excel file and
+
+
+; set external parameters
+#include <String.au3>
+#include <GUIConstants.au3>
+#include <WindowsConstants.au3>
+#include <StaticConstants.au3>
+#Include <GuiEdit.au3>
+#include <Date.au3>
+#include "Mimosa32.au3"
+#include "Mimosa32Ter.au3"
+#include "Mimosa34.au3"
+
+$programversion = "0.7"
+$FileName = IniRead ( "config.ini", "experimental setup", "ExcelPath", "H:\dennis doering\Arbeitsprogramme\Mimosa34\LaborbuchMi34.xls" ) ; read path to Excel file
+$systemtemp = IniRead ( "config.ini", "experimental setup", "SystemTemperature", "20" ) ; current temperatur of the system
+$chipversion = IniRead ( "config.ini", "experimental setup", "ChipVersion", "Mi34" ) ; current chip generation in the system
+$chipinstalled = IniRead ( "config.ini", "experimental setup", "ChipInstalled", "5" ) ; chip number currently mounted into the system
+$radSource = IniRead ( "config.ini", "experimental setup", "RadSource", "none" ) ; current radioactive source of the system
+
+$excelLineBegin = "46" ; Change this to the range of cells you want to be processed
+$excelLineEnd = "500"
+Global $vref = 650 ; Initial vref, will be adjusted during runtime
+
+;create virtual functions
+Func GotoMiTab()
+ Call ( $chipversion & "_GotoMiTab" )
+EndFunc
+
+Func GetVref()
+ Return Call ( $chipversion & "_GetVref" )
+EndFunc
+
+Func SetVref($vref)
+ Call ( $chipversion & "_SetVref", $vref )
+EndFunc
+
+Func SetMiParameter($matrix, $vref)
+ Call ( $chipversion & "_SetMiParameter", $matrix, $vref )
+EndFunc
+
+Func SelectBoard()
+ Call ( $chipversion & "_SelectBoard" )
+EndFunc
+
+$CellRange = "A" & $excelLineBegin &":N"& $excelLineEnd
+
+; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
+Local $answer = MsgBox(4, "Run script?", "Preparing to do all runs in range " & $CellRange & @CRLF & _
+ "of file " & $FileName & " with " & @CRLF & _
+ "Temperatur: " & $systemtemp & " °C" & @CRLF & _
+ "Radioactive source: " & $radSource & @CRLF & _
+ "Chip: " & $chipversion & " (" & $chipinstalled & ")"& @CRLF & _
+ "If you run this script, daq.exe will be closed and the current run aborted, proceed?")
+
+
+; Check the user's answer to the prompt (see the help file for MsgBox return values)
+; If "No" was clicked (7) then exit the script
+If $answer = 7 Then
+ Exit
+EndIf
+
+If Not FileExists($FileName) Then ; Just a check to be sure..
+ MsgBox(16, "Excel Data Test", "Error: Can't find file " & $FileName)
+ Exit
+EndIf
+
+$oExcelDoc = ObjGet($FileName) ; Get an Excel Object from an existing filename
+
+If (Not @error) And IsObj($oExcelDoc) Then ; Check again if everything went well
+ ; NOTE: $oExcelDoc is a "Workbook Object", not Excel itself!
+ $oDocument = $oExcelDoc.Worksheets(1) ; We use the 'Default' worksheet
+ $aArray = $oDocument.range($CellRange).value ; Retrieve the cell values from given range
+ ;$oExcelDoc.Close ; Close the Excel document
+ ; The data should now be in the 2-dimensional array: $aArray
+
+ If IsArray($aArray) And UBound($aArray, 0) > 0 Then ; Check if we retrieved any data
+ ;Msgbox (0,"Excel Data Test","Debugging information for retrieved cells:" & @CRLF & _
+ ; "Number of dimensions: " & UBound($aArray,0) & @CRLF & _
+ ; "Size of first dimension: " & Ubound($aArray,1) & @CRLF & _
+ ; "Size of second dimension: " & Ubound($aArray,2))
+ ; "Size of second dimension: " & Ubound($aArray,2))
+
+ ; The next lines are just for debugging purposes, it puts all cell values into
+ ; a string to display in a MsgBox.
+ ; Note: you can't use a FOR..IN loop for a multi-dimensional array!
+;~ ; debugging read data
+;~ $string=""
+;~ for $x=0 to ubound($aArray,1)-1
+;~ for $y=0 to ubound ($aArray,2)-1
+;~ $string=$string & "(" & $x & "," & $y & ")=" & $aArray[$x][$y] & @CRLF
+;~ Next
+;~ Next
+;~ Msgbox(0,"Excel Data Test","Debug information: Read Cell contents: " & @CRLF & $string)
+
+ $totallexcelines=UBound($aArray, 2)
+ $totalruns = 0
+ For $run = 0 To UBound($aArray, 2) - 1
+ If ($aArray[4][$run] == $systemtemp And $aArray[6][$run] == $chipinstalled And "Mi"&$aArray[2][$run] == $chipversion And $aArray[10][$run] == $radSource And $aArray[0][$run] == "") Then
+ $totalruns = $totalruns + 1
+ EndIf
+ Next
+ Local $answer = MsgBox(4, "Total runs", "Number of suitable runs found at the moment: " & $totalruns )
+ If $answer = 7 Then
+ Exit
+ EndIf
+
+ If ProcessExists("daq.exe") = True Then
+ ProcessClose("daq.exe")
+ ProcessWaitClose("daq.exe")
+ EndIf
+
+ If ProcessExists("i2c_ms_gui.exe") = True Then
+ ProcessClose("i2c_ms_gui.exe")
+ ProcessWaitClose("i2c_ms_gui.exe")
+ EndIf
+
+ Run("C:\ccmos_daq\v3.5.10\daq_v3.5.10.bat", "C:\ccmos_daq\v3.5.10\")
+ WinWait("Debug")
+ ControlClick("Debug", "", "[TEXT:Messages Clear]")
+ Sleep(100)
+ ControlClick("Debug", "", "[TEXT:Board Testing]")
+ Sleep(2000)
+ $i = 0
+ Do
+ $text = WinGetText("[CLASS:TDebugFrm]", "")
+ $texthex = _StringToHex($text)
+ If ($texthex == "4D657373616765730A5072696E7420426F6172647320526567730A0D0A3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D0D0A426F6172642049643D302074657374207374617274696E67202E2E2E0D0A3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D0D0A0D0A53746F70206163717569736974696F6E202E2E2E0D0A41445220434F554E54455220412074657374696E67202E2E2E0D0A41445220434F554E54455220412030204572726F72730D0A52414D20412074657374696E67202E2E2E0D0A52414D20412030204572726F72730D0A52414D20422074657374696E67202E2E2E0D0A52414D20422030204572726F72730D0A52414D20432074657374696E67202E2E2E0D0A52414D20432030204572726F72730D0A52414D20442074657374696E67202E2E2E0D0A52414D20442030204572726F72730D0A0D0A3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D0D0A426F6172642049643D312074657374207374617274696E67202E2E2E0D0A3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D0D0A0D0A53746F70206163717569736974696F6E202E2E2E0D0A41445220434F554E54455220412074657374696E67202E2E2E0D0A41445220434F554E54455220412030204572726F72730D0A52414D20412074657374696E67202E2E2E0D0A52414D20412030204572726F72730D0A52414D20422074657374696E67202E2E2E0D0A52414D20422030204572726F72730D0A52414D20432074657374696E67202E2E2E0D0A52414D20432030204572726F72730D0A52414D20442074657374696E67202E2E2E0D0A52414D20442030204572726F72730D0A0A555342322042616E647769647468204D65617375726D656E740A426F6172642054657374696E670A536F66747761726520496E697469616C697A6174696F6E0A4D6573736167657320436C6561720A") Then
+ EndIf
+ Sleep(500)
+ $i = $i + 1
+ If ($i > 20) Then
+ MsgBox(16, "Message", "USB Boards could be not OK! Please check the Debug output.")
+ Exit
+ EndIf
+ Until 1
+ If StringRegExp ( $text, "[1-9]+ Errors" ) Then ; for some reasons the previous check sometimes doesn't work.
+ MsgBox(16, "Message", "USB Boards could be not OK! Please check the Debug output.")
+ Exit
+ EndIf
+
+
+ WinClose("Debug")
+ WinWaitClose("Debug", 1000)
+ $aArray = 0
+ $totalrealruns=0
+
+ For $run = 0 To $totallexcelines-1
+
+ $currentrange="A"& $excelLineBegin+$run & ":N" & $excelLineBegin+$run
+ $oExcelDoc = ObjGet($FileName) ; if doc was closed and object destroyed -> reopen it. A possibility to check if object exists would come handy here....
+ $oDocument = $oExcelDoc.Worksheets(1) ; We use the 'Default' worksheet
+ $currentline=$oDocument.range($currentrange).value
+ If ($currentline[4][0] == $systemtemp And $currentline[6][0] == $chipinstalled And "Mi"&$currentline[2][0] == $chipversion And $currentline[10][0] == $radSource And $currentline[0][0] == "") Then
+ $clock = $currentline[11][0] ; save needed clock
+ If $clock == "" Then
+ $clock = "100"
+ $currentline[11][0] = "100"
+ EndIf
+ $runnum = $currentline[3][0] ; save runnumber
+ $matrix = $currentline[9][0] ; save matrix
+ $eventnum = $currentline[5][0] ; save number of events to save
+ If $eventnum == "" Then
+ $eventnum = 100000
+ $currentline[5][0] = "100000"
+ EndIf
+
+ CheckWindowExist()
+ SelectBoard()
+ CheckIfBoardOK()
+ GotoDebugTab()
+
+ If ($clock == "100") Then
+ ControlCommand($chipsoftware[0], "", "[TEXT:Intern]", "Check")
+ ;If (Not ControlCommand("I2C control Software for Mimosa32", "", "[TEXT:Intern]", "IsChecked")) Then
+ ;Msgbox (16,"Message","Could not set clock to intern")
+ ;EndIf
+ Else
+ ShellExecuteWait ("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'SOURce1:FREQuency:Fixed " & $clock & "Mhz'", "", "", @SW_HIDE)
+ ShellExecuteWait ("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'SOURce1:VOLTage:HIGH 3.3'", "", "", @SW_HIDE)
+ ShellExecuteWait ("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'SOURce1:VOLTage:LOW 0'", "", "", @SW_HIDE)
+ ShellExecuteWait ("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'OUTPut1:STATe ON'", "", "", @SW_HIDE)
+ Sleep(500)
+ ControlCommand("I2C control Software for Mimosa32", "", "[TEXT:Extern]", "Check")
+ ;If (Not ControlCommand("I2C control Software for Mimosa32", "", "[TEXT:Extern]", "IsChecked")) Then
+ ;Msgbox (16,"Message","Could not set clock to extern")
+ ;EndIf
+ EndIf
+
+ GotoMiTab()
+ SetMiParameter($matrix, $vref)
+ ProgramMi()
+
+ If WinExists("CMOS USB DAQ V3.5.10") = True Then
+ ;WinActivate("CMOS USB DAQ V3.5.10")
+ Else
+ Run("C:\ccmos_daq\v3.5.10\daq_v3.5.10.bat", "C:\ccmos_daq\v3.5.10\")
+ EndIf
+ WinWait("CMOS USB DAQ V3.5.10")
+
+ For $i = 0 To 20
+ ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabLeft")
+ Next
+ $i = 0
+ While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TTabSheet1") <> "Run Parameters")
+ If ($i > 20) Then
+ MsgBox(0, "Message", "CMOS USB DAQ V3.5.10 RUN tab not found in DAQ software!")
+ Exit
+ EndIf
+ ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabRight")
+ $i = $i + 1
+ Sleep(100)
+ WEnd
+
+ ControlSetText("CMOS USB DAQ V3.5.10", "", "TEdit23", "")
+ Sleep(100)
+ ControlFocus("CMOS USB DAQ V3.5.10", "", "TEdit23")
+ ;Send($runnum)
+ ControlSend("CMOS USB DAQ V3.5.10", "", "TEdit23", $runnum)
+
+ ControlSetText("CMOS USB DAQ V3.5.10", "", "TEdit22", "")
+ Sleep(100)
+ ControlFocus("CMOS USB DAQ V3.5.10", "", "TEdit22")
+;~ Send($eventnum)
+ ControlSend("CMOS USB DAQ V3.5.10", "", "TEdit22", $eventnum)
+ ControlFocus("CMOS USB DAQ V3.5.10", "", "TEdit23")
+
+ Sleep(1000)
+ $starttime = _NowCalc()
+
+ ControlClick("CMOS USB DAQ V3.5.10", "", "[TEXT:Start Run;CLASS:TButton]")
+ ;WinWaitActive("Avertissement") ;Force overwrite
+ ;ControlClick("Avertissement", "", "TButton2")
+
+ Sleep(500)
+ If (WinExists("Avertissement")) Then
+ MsgBox(16, "Message", "Stopping. Could overwrite data!")
+ Exit
+ EndIf
+
+
+ $i = 0
+ While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TTabSheet1") <> "Local Monitoring")
+ If ($i > 20) Then
+ MsgBox(0, "Message", "CMOS USB DAQ V3.5.10 Local Monitoring tab not found in DAQ software!")
+ Exit
+ EndIf
+ ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabRight")
+ $i = $i + 1
+ Sleep(100)
+ WEnd
+
+ Sleep(1000)
+
+ $avg = ControlGetText("CMOS USB DAQ V3.5.10", "", "[TEXT:DispAvg;CLASS:TEdit]")
+ For $i = 0 To 20
+ ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabLeft")
+ Next
+ $i = 0
+ While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TTabSheet1") <> "Run Parameters")
+ If ($i > 20) Then
+ MsgBox(0, "Message", "CMOS USB DAQ V3.5.10 RUN tab not found in DAQ software!")
+ Exit
+ EndIf
+ ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabRight")
+ $i = $i + 1
+ Sleep(100)
+ WEnd
+ $j = 0
+ If ($avg > 2300 Or $avg < 1700) Then
+ Do
+ ControlClick("CMOS USB DAQ V3.5.10", "", "[TEXT:Stop Run;CLASS:TButton]")
+ ;WinActivate("I2C control Software for Mimosa32")
+ $vref = GetVref()
+ ;$vref = ControlGetText("I2C control Software for Mimosa32", "", "TEdit11")
+ $diff = $avg - 2000
+ Select
+ Case Abs($diff) > 600
+ $vref = $vref + SGN($diff) * 100
+ Case Else
+ $vref = $vref +SGN($diff) * 50
+ EndSelect
+ If ($vref > 1000 Or $vref < 300) Then
+ MsgBox(0, "Message", "Stopped, vref value needs to be too low (<300) or too high (>1000), please check manually!")
+ Exit
+ EndIf
+
+ ;ControlSetText("I2C control Software for Mimosa32", "", "TEdit11", $vref)
+ ;ControlClick("I2C control Software for Mimosa32", "", "[TEXT:Prog All Analog;CLASS:TButton]")
+ SetVref($vref)
+ ProgramMi()
+ ;WinActivate("CMOS USB DAQ V3.5.10")
+ WinWait("CMOS USB DAQ V3.5.10")
+ Sleep(1000)
+ ControlClick("CMOS USB DAQ V3.5.10", "", "[TEXT:Start Run;CLASS:TButton]")
+ WinWait("Avertissement")
+ ControlClick("Avertissement", "", "TButton2")
+
+
+ $i = 0
+ While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TTabSheet1") <> "Local Monitoring")
+ If ($i > 20) Then
+ MsgBox(0, "Message", "CMOS USB DAQ V3.5.10 Local Monitoring tab not found in DAQ software!")
+ Exit
+ EndIf
+ ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabRight")
+ $i = $i + 1
+ Sleep(100)
+ WEnd
+
+ Sleep(1000)
+
+ $avg = ControlGetText("CMOS USB DAQ V3.5.10", "", "[TEXT:DispAvg;CLASS:TEdit]")
+ For $i = 0 To 20
+ ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabLeft")
+ Next
+ $i = 0
+ While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TTabSheet1") <> "Run Parameters")
+ If ($i > 20) Then
+ MsgBox(0, "Message", "CMOS USB DAQ V3.5.10 RUN tab not found in DAQ software!")
+ Exit
+ EndIf
+ ControlCommand("CMOS USB DAQ V3.5.10", "", "TPageControl1", "TabRight")
+ $i = $i + 1
+ Sleep(100)
+ WEnd
+
+ $j = $j + 1
+ If ($j > 7) Then
+ ControlClick("CMOS USB DAQ V3.5.10", "", "[TEXT:Stop Run;CLASS:TButton]")
+ MsgBox(0, "Message", "VRef could not be set properly")
+ Exit
+ EndIf
+
+ Until ($avg < 2300 And $avg > 1700)
+ EndIf
+
+ While (ControlGetText("CMOS USB DAQ V3.5.10", "", "TEdit18") < $eventnum)
+ Sleep(10000)
+ ;If EnvGet('SESSIONNAME') <> "Console" Then
+ ;ShowWarning()
+ ;EndIf
+ ;WinWait("CMOS USB DAQ V3.5.10")
+ WEnd
+ WinWait("CMOS USB DAQ V3.5.10")
+ ControlClick("CMOS USB DAQ V3.5.10", "", "[TEXT:Stop Run;CLASS:TButton]")
+ ;If ($clock <> "100") Then
+ ; ShellExecuteWait("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'OUTPut1:STATe Off'", "", "", @SW_HIDE)
+ ;EndIf
+
+ $currentline[0][0] = @MDAY & "." & @MON & "." & @YEAR
+ $currentline[8][0] = $vref
+ $calcmin = _DateDiff('s', $starttime, _NowCalc()) ; n for minites, s for seconds
+ $currentline[13][0] = "Automated run, performed by V." & $programversion & " runtime in minutes: " & $calcmin
+
+ $oExcelDoc = ObjGet($FileName) ; if doc was closed and object destroyed -> reopen it. A possibility to check if object exists would come handy here....
+ $oDocument = $oExcelDoc.Worksheets(1) ; We use the 'Default' worksheet
+ $oDocument.range($currentrange).value = $currentline
+ $oExcelDoc.Windows(1).Visible = True ; Otherwise the worksheet window will be saved 'hidden'
+ $oExcelDoc.Save ; Save the workbook
+
+ $oExcelDoc.saved = 1
+ $totalrealruns = $totalrealruns + 1
+ EndIf
+ Next
+ ShellExecuteWait("C:\Programme\PuTTY\plink.exe", "-ssh cerberus /home/maps/bin/vxi11_cmd 192.168.10.152 'OUTPut1:STATe Off'", "", "", @SW_HIDE)
+ MsgBox(0, "Sucess!", "All runs (" & $totalrealruns & ") ended without errors." & @CRLF & _
+ "Please check the Excel sheet and the results for errors.")
+
+ Else
+ MsgBox(0, "Excel Data Test", "Error: Could not retrieve data from cell range: " & $CellRange)
+ EndIf
+
+Else
+ MsgBox(0, "Excel Data Test", "Error: Could not open " & $FileName & " as an Excel Object.")
+EndIf
+
+$oExcelDoc = 0
+
+
+Func SGN($i)
+ Return ($i>0)-($i<0)
+ EndFunc ;==>SGN
+
+ Func CheckValues($vref, $matrix, $runnum, $eventnum, $clock)
+ Return 0
+EndFunc