maloysius Posted February 26, 2019 Posted February 26, 2019 Hi all, I work for a POS company and I am trying to make a program that checks to see if the POS is connected to the server data. If it isn't, I want the program to send out a constant ping to the server until it is successful, and then restart the POS. This is the function I am using for the pinging currently: Func _WaitForIP($sIP) Do Sleep(10) Until Ping($sIP) <> 0 WinClose("DataDeputy") Run("C:\DDWIN\ddprint.exe") Run("C:\DDWIN\pos.exe") EndFunc And then I call it using this: _WaitForIP("10.0.0.100") I have tried about 10 quadrillion different things but I just can't get it to keep sending out the ping until it's successful, then run the script after the Until command. Does anyone have any ideas or advice they can throw at me?? Thank you in advance!
Moderators JLogan3o13 Posted February 26, 2019 Moderators Posted February 26, 2019 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Moderators JLogan3o13 Posted February 26, 2019 Moderators Posted February 26, 2019 Did you try it like this: While Not Ping($sIP) Sleep(100) WEnd "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
maloysius Posted February 26, 2019 Author Posted February 26, 2019 Oh! My apologies. I appreciate it! Unfortunately, it doesn't seem to have worked. It very well may be a disconnect with some of my other coding. Perhaps some context might help my case. Here is the full program: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> $StartTimer = TimerInit() CheckWindow() Func ConnectToData() WinClose("There was no valid data found.") ProcessClose("pos.exe") ProcessClose("ddprint.exe") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("DataDeputy", 546, 335, 192, 124) GUISetIcon("C:\Windows\Oculus.ico", -1) $Pic1 = GUICtrlCreatePic("C:\DataDeputy\Digital-Dining-Logo.jpg", 64, 16, 172, 100) $Label1 = GUICtrlCreateLabel("This machine has lost connection to the data.", 32, 152, 482, 33) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") $Label2 = GUICtrlCreateLabel("Attempting to reconnect...", 144, 200, 274, 33) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") $Pic2 = GUICtrlCreatePic("C:\DataDeputy\opos logo.jpg", 304, 32, 172, 60) $Label3 = GUICtrlCreateLabel("If the problem persists, check your network cables, your network equipment, and", 40, 264, 474, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Label4 = GUICtrlCreateLabel("your server. If still unable to connect, please call the help desk.", 40, 288, 469, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### _WaitForIP("10.0.0.100") $StartTimer = TimerInit() CheckWindow() EndFunc Func _WaitForIP($sIP) While Not Ping($sIP) Sleep(100) WEnd WinClose("DataDeputy") Run("C:\DDWIN\ddprint.exe") Run("C:\DDWIN\pos.exe") EndFunc Func CheckWindow() While 1 If TimerDiff($StartTimer) > 10000 Then If WinExists("There was no valid data found.") Then ConnectToData() EndIf Sleep(10) EndIf WEnd EndFunc Essentially, the program starts and it waits for a window to show up with the title "There is no valid data found" to pop up. Once it does, it closes the POS programs and pops up a window to explain that it's attempting to reconnect. It gets to this point just fine where it displays the window and everything. Aferwards, no matter what I do, I can't get it to do anything. I basically want it to constantly recheck the ping to the server (10.0.0.100) to see if it's back up. If the ping is successful, I want it to close the window, reopen the programs, and revert back to the CheckWindow function loop to stay open in the background to see if it happens again. As far as I can tell, everything seems like as it should be. Pullin' my hair out here. I'm sure it's something simple I'm just overthinking!
AdamUL Posted February 26, 2019 Posted February 26, 2019 Here is a function that I wrote to check that a server is online. If _ServerOnline("10.0.0.100") Then WinClose("DataDeputy") Run("C:\DDWIN\ddprint.exe") Run("C:\DDWIN\pos.exe") EndIf Func _ServerOnline($sServerName, $iTriesMax = 100, $iSuccessMax = 10, $iTimeout = 250) ;Checks to see if a server is online. If StringRegExp($iTriesMax, "(?-i)\s|Default|-1") Then $iTriesMax = 100 If StringRegExp($iSuccessMax, "(?-i)\s|Default|-1") Then $iSuccessMax = 10 If StringRegExp($iTimeout, "(?-i)\s|Default|-1") Then $iTimeout = 250 Local $iTries = 0 Local $iRoundTripTime Local $iPingError Local $iSuccess = 0 Do ;Connect to the server $iSuccessMax times. Do ;Try to connect to the server up to $iTriesMax times. $iTries += 1 $iRoundTripTime = Ping($sServerName, $iTimeout) $iPingError = @error If Not $iPingError Then Sleep(10) Until Not $iPingError Or $iTries = $iTriesMax If $iTries = $iTriesMax And $iPingError Then ExitLoop ;Exit loop when unable to connect to server $iTriesMax tries. $iSuccess += 1 Until $iSuccess = $iSuccessMax If $iSuccess = 0 Then Return SetError(1, 0, False) Return SetExtended($iRoundTripTime, True) EndFunc ;==>_ServerOnline Adam
maloysius Posted February 26, 2019 Author Posted February 26, 2019 Thank you very much for the input Adam! How would I implement this into my code? I am afraid I am a bit of a newbie at AutoIt still, but it looks like this function you've created does not stop until the server is online, correct? Or until it reaches the maximum amount of tries? I have tried to implement it and for some reason it's still hanging on the window, as though it's waiting for some kind of input or stuck in a loop or something and never even gets to the point where it's trying to check for a ping....not quite sure what's going on here :(
maloysius Posted February 26, 2019 Author Posted February 26, 2019 Here is the changed code, still unfortunately doing the same thing. I've racking my brain trying to find out where it hangs up, or if it's even hanging up and I just have an incorrect direct somewhere. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> $StartTimer = TimerInit() CheckWindow() Func _ServerOnline($sServerName, $iTriesMax = 100, $iSuccessMax = 10, $iTimeout = 250) ;Checks to see if a server is online. If StringRegExp($iTriesMax, "(?-i)\s|Default|-1") Then $iTriesMax = 100 If StringRegExp($iSuccessMax, "(?-i)\s|Default|-1") Then $iSuccessMax = 10 If StringRegExp($iTimeout, "(?-i)\s|Default|-1") Then $iTimeout = 250 Local $iTries = 0 Local $iRoundTripTime Local $iPingError Local $iSuccess = 0 Do ;Connect to the server $iSuccessMax times. Do ;Try to connect to the server up to $iTriesMax times. $iTries += 1 $iRoundTripTime = Ping($sServerName, $iTimeout) $iPingError = @error If Not $iPingError Then Sleep(10) Until Not $iPingError Or $iTries = $iTriesMax If $iTries = $iTriesMax And $iPingError Then ExitLoop ;Exit loop when unable to connect to server $iTriesMax tries. $iSuccess += 1 Until $iSuccess = $iSuccessMax If $iSuccess = 0 Then Return SetError(1, 0, False) Return SetExtended($iRoundTripTime, True) EndFunc ;==>_ServerOnline Func ConnectToData() WinClose("There was no valid data found.") ProcessClose("pos.exe") ProcessClose("ddprint.exe") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("DataDeputy", 546, 335, 192, 124) GUISetIcon("C:\Windows\Oculus.ico", -1) $Pic1 = GUICtrlCreatePic("C:\DataDeputy\Digital-Dining-Logo.jpg", 64, 16, 172, 100) $Label1 = GUICtrlCreateLabel("This machine has lost connection to the data.", 32, 152, 482, 33) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") $Label2 = GUICtrlCreateLabel("Attempting to reconnect...", 144, 200, 274, 33) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") $Pic2 = GUICtrlCreatePic("C:\DataDeputy\opos logo.jpg", 304, 32, 172, 60) $Label3 = GUICtrlCreateLabel("If the problem persists, check your network cables, your network equipment, and", 40, 264, 474, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Label4 = GUICtrlCreateLabel("your server. If still unable to connect, please call the help desk at 503-646-1383.", 40, 288, 469, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### If _ServerOnline("10.0.0.100") Then WinClose("DataDeputy") Run("C:\DDWIN\ddprint.exe") Run("C:\DDWIN\pos.exe") CheckWindow() ElseIf _ServerOnline("10.0.0.100") EndIf $StartTimer = TimerInit() CheckWindow() EndFunc Func CheckWindow() While 1 If TimerDiff($StartTimer) > 10000 Then If WinExists("There was no valid data found.") Then ConnectToData() EndIf Sleep(10) EndIf WEnd EndFunc
maloysius Posted February 26, 2019 Author Posted February 26, 2019 It's like it creates the GUI window and then it just doesn't do anything after that. Is there anything in the GUI code that would pause the flow of the script??
AdamUL Posted February 26, 2019 Posted February 26, 2019 It looks like you do not have a message loop or any on event functions for you GUI. This is causing you GUI to be unresponsive. Look in the help file on GUIs and figure out which mode you want to use. Also, the _ServerOnline may block the GUI due to it having its own internal look. Adam
maloysius Posted February 26, 2019 Author Posted February 26, 2019 Oooh! That would certainly be part of the problem then. I added in this and it's still doing the same thing...maybe it's in the wrong order or something? This should be what I need to make that GUI active from what I can see in the help file..... While 1 $nMsg = GUIGetMsg() If _ServerOnline("10.0.0.100") Then WinClose("DataDeputy") Run("C:\DDWIN\ddprint.exe") Run("C:\DDWIN\pos.exe") ExitLoop ElseIf EndIf Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Label1 Case $Label2 EndSwitch WEnd
Dwalfware Posted February 27, 2019 Posted February 27, 2019 Something like this? to mod for you $ii = 50 ; Set how many loops till giving up If _WaitForIP($sIP) = 0 Then WinClose("DataDeputy") Run("C:\DDWIN\ddprint.exe") Run("C:\DDWIN\pos.exe") Endif Func _WaitForIP($sIP) While 1 $Ping = Ping($sIP) IF $Ping = 0 or @error then Return 0 Else Return $Ping Endif If $xi = $ii then Return 0 Endif $xi = $xi +1 Wend EndFunc
Dwalfware Posted February 27, 2019 Posted February 27, 2019 (edited) or maybe something like this expandcollapse popupLocal $ii = 50 ; Set how many loops till giving up _Start() Func _Start() Local $PingTested = _WaitForIP($sIP) EndFunc If $PingTested <> 0 Then WinClose("DataDeputy") Run("C:\DDWIN\ddprint.exe") Run("C:\DDWIN\pos.exe") Consolewrite"Ping ok" & @CRLF) Exit Endif If $PingTested = "A" Then Consolewrite"Ping Error - Restarting" & @CRLF) _Start() Endif If $PingTested = "B" Then Consolewrite"Ping Timeout - Restart" & @CRLF) _Start() Endif Func _WaitForIP($sIP) While 1 $Ping = Ping($sIP) IF $Ping = 0 or @error then Return "A" Else Return $Ping Endif If $xi = $ii then Return "B" Endif $xi = $xi +1 Wend EndFunc Edited February 27, 2019 by Dwalfware
maloysius Posted March 1, 2019 Author Posted March 1, 2019 Dwalfware, thank you very much! That makes a lot of sense, and I think once I figure out what the heck is happening, this will work. However, I am now having a whole new issue........when it shuts down the windows and creates the GUI, it's no longer pausing the script, but it IS erroring out. It says that there is a variable referenced that hasn't been declared. Well, I went through each and every line, made sure to officially declare each variable...and as far as I can tell, nothing in any of the functions is referenced before it's declared. I for the life of me can not figure out what on Earth is happening here. Although, anything happening at all is still an improvement.... Here is the code...does anyone see any undeclared variables???? I sure don't... expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> Local $StartTimer = TimerInit() Local $sIP = "10.0.0.100" Local $xi = 0 Local $ii = 999999 CheckWindow() Func _Start() Local $PingTested = _WaitForIP() EndFunc Func _WaitForIP() While 1 Local $Ping = Ping("10.0.0.100") Sleep(10) If $Ping = 0 or @error then Return "A" ElseIf Return $Ping Endif If $xi = $ii then Return "B" EndIf $xi = $xi +1 WEnd EndFunc Func ConnectToData() WinClose("There was no valid data found.") ProcessClose("pos.exe") ProcessClose("ddprint.exe") #Region ### START Koda GUI section ### Form= Local $Form1 = GUICreate("DataDeputy", 546, 335, 192, 124) GUISetIcon("C:\Windows\Oculus.ico", -1) Local $Pic1 = GUICtrlCreatePic("C:\DataDeputy\Digital-Dining-Logo.jpg", 64, 16, 172, 100) Local $Label1 = GUICtrlCreateLabel("This machine has lost connection to the data.", 32, 152, 482, 33) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") Local $Label2 = GUICtrlCreateLabel("Attempting to reconnect...", 144, 200, 274, 33) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") Local $Pic2 = GUICtrlCreatePic("C:\DataDeputy\opos logo.jpg", 304, 32, 172, 60) Local $Label3 = GUICtrlCreateLabel("If the problem persists, check your network cables, your network equipment, and", 40, 264, 474, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") Local $Label4 = GUICtrlCreateLabel("your server. If still unable to connect, please call the help desk at 503-646-1383.", 40, 288, 469, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Local $nMsg = GUIGetMsg() _Start() If $PingTested <> 0 Then ExitLoop Endif If $PingTested = "A" Then ConsoleWrite( "Ping Error - Restarting" & @CRLF ) _Start() Endif If $PingTested = "B" Then ConsoleWrite( "Ping Timeout - Restart" & @CRLF ) _Start() Endif Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Label1 ExitLoop Case $Label2 EndSwitch WEnd Consolewrite( "Ping ok" & @CRLF ) WinClose("DataDeputy") ShellExecute( "C:\DDWIN\ddprint.exe" ) ShellExecute( "C:\DDWIN\pos.exe" ) $StartTimer = TimerInit() CheckWindow() EndFunc Func CheckWindow() While 1 If TimerDiff($StartTimer) > 10000 Then If WinExists("There was no valid data found.") Then ConnectToData() EndIf Sleep(10) EndIf WEnd EndFunc
Developers Jos Posted March 1, 2019 Developers Posted March 1, 2019 2 minutes ago, maloysius said: Here is the code...does anyone see any undeclared variables???? I sure don't... Run au3check and it will tell you all 3 errors in that code! Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
maloysius Posted March 1, 2019 Author Posted March 1, 2019 How can I run this?? I didn't even know it existed, I see that it's an executable in the AutoIt folder now but it doesn't seem to do anything. Is this something I can run from within the SciTE-Lite editor?
maloysius Posted March 1, 2019 Author Posted March 1, 2019 Ah, never mind, I found it!! Thank you! Sorry, I am still a relative newb to all this
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