#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 Author: FattysFTW Script Function: AutoIt script which creates a graphical interface which is then used to control the CAYMAN wire stripper via pulling data from an excel sheet, located at a path input by the user. The data from this excel sheet is then cross-referenced with data input by the user. #ce ---------------------------------------------------------------------------- ; Script Start: #include #include #include #include #RequireAdmin Global $TotalBins = 6 ; GUI Initialize: #include #include #include #include #include #include #include #Region ### START Koda GUI section ### Form=Z:\Anthony\CAYMAN Automator\Testing\Automator_GUI.kxf Global $Form1 = GUICreate("Cayman Automator", 570, 260, 187, 125) Global $Job1 = GUICtrlCreateInput("1", 48, 32, 121, 21) Global $Job2 = GUICtrlCreateInput("2", 48, 64, 121, 21) Global $Job3 = GUICtrlCreateInput("3", 48, 96, 121, 21) Global $Job4 = GUICtrlCreateInput("4", 48, 128, 121, 21) Global $Job5 = GUICtrlCreateInput("5", 48, 160, 121, 21) Global $Job6 = GUICtrlCreateInput("6", 48, 192, 121, 21) Global $BinLabel = GUICtrlCreateLabel("Schlueniger Wire Stripper Automation Script Version 2.1", 40, 8, 300, 17, $SS_CENTER) Global $BinLabel1 = GUICtrlCreateLabel("Bin 1:", 8, 32, 28, 17) Global $BinLabel2 = GUICtrlCreateLabel("Bin 2:", 8, 64, 28, 17) Global $BinLabel3 = GUICtrlCreateLabel("Bin 3:", 8, 96, 28, 17) Global $BinLabel4 = GUICtrlCreateLabel("Bin 4:", 8, 128, 28, 17) Global $BinLabel5 = GUICtrlCreateLabel("Bin 5:", 8, 160, 28, 17) Global $BinLabel6 = GUICtrlCreateLabel("Bin 6:", 8, 192, 28, 17) Global $WireTypeInput = GUICtrlCreateCombo("Wire060", 192, 32, 150, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_VSCROLL)) GUICtrlSetData(-1, "Wire061|Wire062|Wire064|Wire081|Wire082|Wire084|Wire100|Wire101|Wire102|Wire104|Wire106|Wire109|Wire120|Wire121|Wire122|Wire1221|Wire124|Wire125|Wire126|Wire128|Wire129|Wire139|Wire140|Wire141|Wire142|Wire143|Wire144|Wire145|Wire146|Wire148|Wire149|Wire150|Wire151|Wire152|Wire153|Wire157|Wire158|Wire160|Wire161|Wire162|Wire1621|Wire163|Wire164|Wire165|Wire166|Wire167|Wire168|Wire169|Wire170|Wire171|Wire172|Wire175|Wire176|Wire177|Wire178|Wire179|Wire180|Wire181|Wire182|Wire183|Wire185|Wire188|Wire192|Wire202|Wire220|Wire221|Wire222|Wire223") Global $StartBtn = GUICtrlCreateButton("Start", 192, 192, 150, 25) Global $Progress1 = GUICtrlCreateProgress(192, 160, 150, 17) Global $ProgressLabel = GUICtrlCreateLabel("Script Progress:", 192, 136, 180, 17) Global $MoveOneBtn = GUICtrlCreateButton("Move One Slot", 192, 64, 150, 25) Global $PathInput = GUICtrlCreateInput("C:\Users\Public\Cayman\ImpExp\Cayman_export.xlsx", 8, 224, 550, 21) Global $ScriptRunning = GUICtrlCreateLabel(" Script Not Running", 192, 104, 150, 17, $SS_CENTER) GUICtrlSetBkColor(-1, 0xFF0000) Global $Instructions1 = GUICtrlCreateLabel("Instructions for use:", 360, 32, 300, 17) Global $Instructions2 = GUICtrlCreateLabel("· Export Wirelist from Cayman", 360, 48, 300, 17) Global $Instructions3 = GUICtrlCreateLabel("· Input job numbers for each bin", 360, 64, 300, 17) Global $Instructions4 = GUICtrlCreateLabel("· Input the filepath to the exported wirelist", 360, 80, 300, 17) Global $Instructions4 = GUICtrlCreateLabel("· Select wiretype", 360, 96, 300, 17) Global $Instructions5 = GUICtrlCreateLabel("· Open arduino script Step_ToMetal", 360, 112, 300, 17) Global $Instructions6 = GUICtrlCreateLabel("· Start script", 360, 128, 300, 17) Global $Instructions7 = GUICtrlCreateLabel("· Start stripping process", 360, 144, 300, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $Path = GUICtrlRead($PathInput) ; GUI Input cases: While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ; if the GUI is closed, ExitLoop ; close it Case $StartBtn ; if the start button is pressed, GUICtrlSetData($ScriptRunning, " Script Running") ; change the running indicator, GUICtrlSetBkColor($ScriptRunning, 0x00FF00) Cayman() ; run the main program, ClearGUI() ; reset the progress bar & running indicator Case $MoveOneBtn ; if the move one button is pressed, MotorStepOne() ; move the motor one slot Case $PathInput ; if the excel file path is changed, Global $Path = GUICtrlRead($PathInput) ; reload it EndSwitch WEnd GUIDelete() ; main program: Func Cayman() ; Set variables for user inputs here & pull data from excel sheet ExcelRead() Global $jobBin = [GUICtrlRead($Job1), GUICtrlRead($Job2), GUICtrlRead($Job3), GUICtrlRead($Job4), GUICtrlRead($Job5), GUICtrlRead($Job6)] ; Put the input job numbers in an array where the array slot (0-5) is able to be called and returns a string of the job number Global $iWire = 0 Global $excelTotalWire = UBound($excelWireType)-1 ; grab the number of values in the array of wire types, aka the total number of wires & the number of rows in the excel sheet Global $currentBin = 1 ; Takes all wires from excel sheet and puts only the ones which will be run into 2 new arrays Global $iCount1 = 0 Global $iCount2 = 0 Global $wireType[1] Global $wireJob[1] While $iCount1 <= $excelTotalWire if $excelWireType[$iCount1] = GUICtrlRead($WireTypeInput) Then _ArrayInsert($wireType, $iCount2, $excelWireType[$iCount1]) _ArrayInsert($wireJob, $iCount2, $excelWireJob[$iCount1]) $iCount2 +=1 EndIf $iCount1 +=1 WEnd Global $totalWire = UBound($wireType)-1 ; For testing purposes: ; MsgBox($MB_SYSTEMMODAL, "AutoIt script for CAYMAN", "$wireJob: "&$wireJob[$iWire] & @CRLF & "$jobBin: "&$jobBin[$currentBin]) ; MsgBox($MB_SYSTEMMODAL, "AutoIt script for CAYMAN", "This is line 1" & @CRLF & @error & @CRLF & "This is line 3") ; _ArrayDisplay($excelWireType, "Excel type Array Data:") ; _ArrayDisplay($wireType, "Running type Array Data:") ; _ArrayDisplay($wireJob, "Running job Array Data:") ; #cs --------------------------------------------------------------------------------------------------------- ; Comment section for testing purposes so that loop does not run forever without arduino hooked up While $iWire < $totalWire ; While the wire we are on is less than the total number of wires, While $wireJob[$iWire] <> $jobBin[$currentBin-1] ; if the current bin is not equal to the bin we want MotorStepOne() ; move the motor until we are on the correct bin ; Sleep(20000) ; wait for the motor to move ; For testing purposes: comment out MotorStepOne & sleep() and uncomment the message below to not run the motor, or comment out sleep and uncomment this to use messagebox to move motor instead of timer MsgBox($MB_SYSTEMMODAL, "AutoIt script for CAYMAN", "This wire's job: " & $wireJob[$iWire] & @CRLF & "This wire's bin: " & $jobBin[$currentBin] & @CRLF & "Current Bin: " & $currentBin) $currentBin +=1 if $currentBin = 7 Then ; if we return to the first bin $currentBin = 1 ; reset the index EndIf WEnd WinWait("[CLASS:#32770]") ; Wait for a CAYMAN popup dialogue, Local $popupText = ControlGetText("[CLASS:#32770]","","[CLASSNN:Static4]") ; Pull the text from the popup, if $popupText = "HotStamp Timeout." Then ; if it's a hotstamp error popup $iWire = $totalWire ; end the while loop, WinActivate("[CLASS:#32770]") ; Target & close the CAYMAN popup Send("{F1}") ; and here is where a light would turn on and the program would break ; IF WE HAD ONE ElseIf $popupText = "Waste piece will now be ejected." Then ; if it's a waste piece popup WinActivate("[CLASS:#32770]") ; Target & close the CAYMAN popup Send("{F1}") ElseIf $popupText = "Quantity complete." Then ; if it's a popup saying the wire is done GUICtrlSetData($Progress1, ($iWire/$totalWire)*100) ; update the progress bar WinActivate("[CLASS:#32770]") ; Target & close the CAYMAN popup Send("{F1}") $iWire +=1 ; Index the wire EndIf WEnd ; #ce --------------------------------------------------------------------------------------------------------- EndFunc ; Arduino control function: Func MotorStepOne() ; Move the motor one position using the arduino script WinWait("Step_ToMetal | Arduino 1.8.5") WinActivate("Step_ToMetal | Arduino 1.8.5", "") Send("^u") WinActivate("Cayman Automator", "") EndFunc ; Clear GUI function: Func ClearGUI() GUICtrlSetData($Progress1, 0) ; Set progress bar to 0 GUICtrlSetData($ScriptRunning, " Script Not Running") ; Change label to NOT running GUICtrlSetBkColor($ScriptRunning, 0xFF0000) ; Change label color to red EndFunc ; Read excel file at $Path function: Func ExcelRead() $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oExcel, $Path) Global $excelWireType = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("K:K"), 2) Global $excelWireJob = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("D:D"), 2) _Excel_Close($oExcel, false, true) EndFunc