royalmarine Posted May 1, 2012 Share Posted May 1, 2012 (edited) hi guys, trying to set a ping function to check for a device available. here's my code so far if Ping($targetIP, 250) = 0 Then $NetworkDevice = False sleep(3000) Else msgbox(0, '', 'device reachable') sleep(3000) EndIf however, I'm having mixed results from this, so i want to add in a count. lets say it tries to ping 5 times. and if less than 3 of these are successful, then it says the device is not reachable. if 3 or more are successful, then i want it to say the device is reachable. so, i think something like this would work Ping($targetIP, 250) if Not @error Then $Count +=1 if $count <3 Then msgbox(0. ''. 'device not reachable') else if $Count >=3 Then msgbox(0,'', 'device reachable') EndIf EndIf but i can't seem to figure out what I'm doing wrong with it.. any suggestions would be amazing! Edited May 1, 2012 by royalmarine Link to comment Share on other sites More sharing options...
royalmarine Posted May 1, 2012 Author Share Posted May 1, 2012 ok, after reading over my code, clearly I'm doing it wrong. the count will obviously return a fail twice then success after since the count increases etc... so i think i need a for loop in there to do the ping 5 times, each time increasing the count. once its done 5 times, return the result, and then reset the count back to 0... can anyone possibly help a bit with this? I've never used a for loop in auto it Link to comment Share on other sites More sharing options...
royalmarine Posted May 1, 2012 Author Share Posted May 1, 2012 (edited) ok, this is what I've tried so far, think I'm close as I'm not getting any error's, just it always comes back with a fail. Local $Count $TargetIP = "192.168.1.2" While 1 $Count1 = 0 $Count2 = 0 Do Ping($targetIP, 250) If Ping($TargetIP, 250) = 0 Then $Count1 +=1 ElseIf Ping($TargetIP, 250) = 1 Then $Count1 +=1 $Count2 +=1 EndIf Until $Count1 = 5 If $Count2 <3 Then MsgBox(0, '', 'fail') Else MsgBox(0, '', 'Success') EndIf WEnd Edited May 1, 2012 by royalmarine Link to comment Share on other sites More sharing options...
royalmarine Posted May 1, 2012 Author Share Posted May 1, 2012 ok, think I've fixed this. I've altered it like this Local $Count $TargetIP = "192.168.1.2" While 1 $Count1 = 0 $Count2 = 0 Do Ping($targetIP, 250) If Ping($TargetIP, 250) = 0 Then ; ping fails $Count1 +=1 Else ; ping doesn't fail $Count1 +=1 $Count2 +=1 EndIf Until $Count1 = 5 If $Count2 <3 Then MsgBox(0, '', 'fail') Else MsgBox(0, '', 'Success') EndIf it works. when i disconnect the device from network it fails. when i connect it, msgbox reports success. I've also added @error to my msgbox and I'm getting a result of 0 when the device is on and a result of 4 when the device is off. Link to comment Share on other sites More sharing options...
royalmarine Posted May 2, 2012 Author Share Posted May 2, 2012 one last thing to add, i forgot to rest the $count1 and $count2 back to 0 once the loop had completed. once i did this, it works fine Link to comment Share on other sites More sharing options...
BrewManNH Posted May 2, 2012 Share Posted May 2, 2012 Edit button broken? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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