Tendo Posted July 25, 2023 Share Posted July 25, 2023 I have written this, its automating setting up a Planet industrial switch! when the router is booting there are couple of wait times and several hit enter to continue moments. I have logged the output and seem to have the right wait times. But cannot get the enter key to be sent! Is there anything am missing here? expandcollapse popupGUICtrlSetData($guiInfoLabel,"Phase 2: Booting the Planet IGS-12040MT.") ;Send Enter and then wait 15 seconds for IGS-12040MT to reach the password prompt $timeout=3000 $searchString="/switch/" scanInput($hComPort,$searchString,$timeout,5) Sleep(20000) logInfo("20 seconds awaiting Enter prompt"&@CRLF) ;Scan for text indicating the IGS-12040MT has finished booting $timeout=3000 $searchString="Press ENTER " scanInput($hComPort,$searchString,$timeout,5) sleep(1000) Send("{ENTER}") logInfo("Enter key pressed!"&@CRLF) ;Scan for Username and Password $timeout=3000 $searchString="Username:" scanInput($hComPort,$searchString,$timeout,5) if @error Then Return SetError(2,@ScriptLineNumber,"Timeout while searching input data for the string "&$searchString & ", contact IT @ "&$supportEmail&" for further assistance."&@CRLF&" Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout & @CRLF & "Loops: 5") ;Send $timeout=3000 $input = $defaultUser Sleep(1000) _COMSendString($hComPort, $input&@LF& _ ) Send("{Enter}") $readString = collectInput($hComPort,$timeout) if @error Then Return SetError(2,@ScriptLineNumber,"No Username input data in the given time period, contact IT @ "&$supportEmail&" for further assistance."&@CRLF&"Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout) logInfo("Username entered==> " &$input& " <== " &@CRLF) ;Verify $searchString="Password: " If StringinStr($readString,$searchString) == 0 THEN return SetError(6,@ScriptLineNumber,"Unable to login to Planet IGS-12040MT, searching for string "&$searchString & ", contact IT @ "&$supportEmail&" for further assistance") $timeout=3000 $input=$defaultPass ;scanInput($hComPort,$searchString,$timeout,5) _COMSendString($hComPort, $input&@LF) Send("{Enter}") $readString = collectInput($hComPort,$timeout) if @error Then Return SetError(2,@ScriptLineNumber,"No Password input data in the given time period, contact IT @ "&$supportEmail&" for further assistance."&@CRLF&"Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout) logInfo("Password entered==> " &$input& " <== " &@CRLF) Link to comment Share on other sites More sharing options...
ioa747 Posted July 25, 2023 Share Posted July 25, 2023 (edited) use WinActivate("TheRightWin") before send enter Edited July 25, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
Tendo Posted July 25, 2023 Author Share Posted July 25, 2023 The script runs in the background! Connects to the switch via a serial connection on COM5 port at specified speed. All this is not visible. But should be like opening a putty session and typing in commands... In my case do you think I need to specify the use WinActivate("COM5 - PuTTY") Link to comment Share on other sites More sharing options...
ioa747 Posted July 26, 2023 Share Posted July 26, 2023 if we take it in reverse. put ConsoleWrite(WinGetTitle("[ACTIVE]") & @CRLF) before each Send("{Enter}") to see where the enter goes I know that I know nothing Link to comment Share on other sites More sharing options...
Tendo Posted July 26, 2023 Author Share Posted July 26, 2023 Thanks for sticking with me.... I still cant the Enter key sent, My log shows its hit at the right time in the script however doing the next text scan doesn't proceed which probably means the enter key isn't being sent/hit. This brings me to my next question is there a way to verify that the hit keyboard strokes? Link to comment Share on other sites More sharing options...
ioa747 Posted July 26, 2023 Share Posted July 26, 2023 can you post the the entire script I think you don't need to send enter. but embed it in the function _COMSendString($hComPort, @LF ) @LF act as enter I know that I know nothing Link to comment Share on other sites More sharing options...
Tendo Posted July 27, 2023 Author Share Posted July 27, 2023 Here is entire function I have tried the option of @LF as suggested but still getting the same result. expandcollapse popupFunc IGS12040MTProgramming($hComPort, $iPort) Local $input Local $readString Local $timeout Local $searchString Local $response GUICtrlSetData($guiInfoLabel,"Phase 2: Booting the Planet IGS-12040MT.") ;Send Enter and then wait 15 seconds for IGS-12040MT to reach the password prompt ;Sleep(1000) $timeout=3000 $searchString="/switch/" scanInput($hComPort,$searchString,$timeout,25) Sleep(20000) logInfo("20 seconds awaiting Enter prompt"&@CRLF) ;Scan for text indicating the IGS-12040MT has finished booting $timeout=3000 $searchString="Press ENTER " scanInput($hComPort,$searchString,$timeout,5) ;Sleep(1000) _ComSendString($hComPort, @LF) logInfo("Enter key pressed!"&@CRLF) ;Scan for Username and Password $timeout=$moment $searchString="Username:" scanInput($hComPort,$searchString,$timeout,5) if @error Then Return SetError(2,@ScriptLineNumber,"Timeout while searching input data for the string "&$searchString & ", contact IT @ "&$supportEmail&" for further assistance."&@CRLF&" Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout & @CRLF & "Loops: 5") ;Send $timeout=3000 $input = $defaultUser Sleep(1000) _COMSendString($hComPort, $input&@LF& _ ) $readString = collectInput($hComPort,$timeout) if @error Then Return SetError(2,@ScriptLineNumber,"No Username input data in the given time period, contact IT @ "&$supportEmail&" for further assistance."&@CRLF&"Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout) logInfo("Username entered==> " &$input& " <== " &@CRLF) ;Verify $searchString="Password: " If StringinStr($readString,$searchString) == 0 THEN return SetError(6,@ScriptLineNumber,"Unable to login to Planet IGS-12040MT, searching for string "&$searchString & ", contact IT @ "&$supportEmail&" for further assistance") $timeout=3000 $input=$defaultPass ;scanInput($hComPort,$searchString,$timeout,5) _COMSendString($hComPort, $input&@LF) $readString = collectInput($hComPort,$timeout) if @error Then Return SetError(2,@ScriptLineNumber,"No Password input data in the given time period, contact IT @ "&$supportEmail&" for further assistance."&@CRLF&"Error: " & @error & @CRLF & "comPort: " & $iPort & @CRLF & "Timeout: " &$timeout) logInfo("Password entered==> " &$input& " <== " &@CRLF) Link to comment Share on other sites More sharing options...
Solution ioa747 Posted July 28, 2023 Solution Share Posted July 28, 2023 8 hours ago, Tendo said: I have tried the option of @LF as suggested but still getting the same result. then try with @CR or @CRLF On 7/27/2023 at 1:46 AM, ioa747 said: can you post the the entire script This is not the entire script With this I can't figure out which window or application the script interacts with When you run it, until what point do you reach? communicates with the PlanetSwitch? Is the terminal window visible? Where do you want to put the enter? Can you target it with Au3Info's cross? Tendo 1 I know that I know nothing Link to comment Share on other sites More sharing options...
Tendo Posted July 28, 2023 Author Share Posted July 28, 2023 Thank you for you help. Using @CR solves the issue I am able to proceed and login further, will continue developing the rest of the script. Appreciate your time and support! ioa747 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now