Jump to content

Send("{ENTER}") --> key not sent


Go to solution Solved by ioa747,

Recommended Posts

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? 

GUICtrlSetData($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

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

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

Here is entire function 

I have tried the option of @LF as suggested but still getting the same result.

Func 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

  • Solution
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?

I know that I know nothing

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...