Jump to content

trying to make loop more efficient


Recommended Posts

Hi all - I have created a simple script that turn on cctv software (contacam)  when my phone does not ping back (when I'm out of range of home network)

#include <MsgBoxConstants.au3>
$iPing = 0

For $i = 5 To 1 Step -1 ; this 5 loops cycle is just for testing - please ignnore - when complete it will be an endless loop

Example()

Sleep(120000)

Next

Func Example()
    ; Ping the phone.
    $iPing = Ping("192.168.1.102")

    If $iPing Then ; If a value greater than 0 was returned then turn off camera.
        _endCCTV()
    Else
        _startCCTV() ; If a value of 0 was returned then turn on camera.
    EndIf
EndFunc   ;==>Example



Func _startCCTV()
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "on")
    Sleep(10000)
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "50")

EndFunc

Func _endCCTV()

    ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "0")
    Sleep(10000)
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "off")
EndFunc

 

 

the problem I have is that in this format the script run the bat file that turn on the camera (or off) everytime the ping runs but obviously once the ping returns 0 and the camera starts I only want to run the bat on ping NOT 0 (turn off camera) 

any ideas/advice?

Edited by mmoalem
Link to post
Share on other sites
  • Developers

Just keep track of the current status of the camera.
How do you run the script? is it scheduled each x minutes? In that case you could write that current status to an INI file and retrieve at the start of the script.

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.
  :)

Link to post
Share on other sites

thanks - guess that can work - but was wondering about splitting the loop into two - one looped function check ping for 0 when its true it turns camera on and than runs another looped function that check ping for NOT 0 and if thats true it turns camera off andf than runs the first function. this will avoid having ini files but not sure how best to execute interweaving loops that run each other...

Link to post
Share on other sites

Would have to agree with @Jos here, just do this, it’s not so bad.

#include <MsgBoxConstants.au3>
$iPing = 0, $bCamera=False

For $i = 5 To 1 Step -1 ; this 5 loops cycle is just for testing - please ignnore - when complete it will be an endless loop

Example()

Sleep(120000)

Next

Func Example()
    ; Ping the phone.
    $iPing = Ping("192.168.1.102")

    If $iPing Then ; If a value greater than 0 was returned then turn off camera.
        _endCCTV()
    Else
        _startCCTV() ; If a value of 0 was returned then turn on camera.
    EndIf
EndFunc   ;==>Example


Func _startCCTV()

If Not $bCamera Then    
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "on")
    Sleep(10000)
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "50")
    $bCamera=True
EndIf
    
EndFunc

Func _endCCTV()

If $bCamera Then
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "0")
    Sleep(10000)
    ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "off")
    $bCamera=False
EndIf
    
EndFunc

*Not tested - assumes endless looping - assumes the script is started locally (i.e. with camera off).

Code hard, but don’t hard code...

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Vikramjeet
      include-once #include <File.au3> #include <Excel.au3> #include <String.au3> #include <MsgBoxConstants.au3> Local $file = "TEST.log" FileOpen($file, 0) $TTLPax = 1 For $i = _FileCountLines($file) - $TTLPax to _FileCountLines($file) $line = FileReadLine($file, $i) Global $TktNo = StringMid($line, 8, 13) ; reads 13 characters from $Line starting from the 8th character msgbox(0,'',$TktNo) ; This is just for me to debug For $NoOfPax = 1 to 2 local $TTLSeg = 2 msgbox(0,'',$TTLSeg) msgbox(0,'',"7ABC"& $TktNo &"'N"& $NoOfPax &".1'C1,2'S1,2'B") ; This makes 7ABC1234567890123'N1.1'C1,2'S1,2'B ;But in the next loop I want the value to be 7ABC1234567890333'N2.1'C1,2'S1,2'B Next ExitLoop Next *TEST
      JAMES BAKER
        1.NYC-23JAN
        2.TJ 1234567890123
        3.TJ 1234567890333
      I am reading a file with last 5 lines as above. I want to be able to loop through and pick the values as follows
      1- Pick 1234567890123
      2- Use it to build a format with N1.1
      3- Pick 1234567890333
      2- Use it to build a format with N2.1
      Need help with the loop. Thank You
       
       
    • By Vikramjeet
      For $A1 = 12 To 11 + $Total For $B1 = 1 To ($oExcel.Application.Cells($A1,6).Value) ; This value is from the Excel file. It can be from 1 - 9. For $N1 = 7 To ??? ; This is based on the value of $B1 ((1 = 7, 2 = 17, 3 = 27, 4 = 37, 5 = 47) Send("-"& ($oExcel.Application.Cells($A1,$N1).Value) &"/"& ($oExcel.Application.Cells($A1,$N1+1).Value)) Sleep(400) Send("{ENTER}") Sleep(700) Next Next Next I am not able to figure how to loop $N1 as follows
      If the Value of $B1 = 1 then $N1 = 7
      If the Value of $B1 = 2 then $N1 = 17
      If the Value of $B1 = 3 then $N1 = 27
      If the Value of $B1 = 4 then $N1 = 37  
      The value of $N1 comes from $B1 where 1 = 7, 2 = 17, 3 = 27, 4 = 37, 5 = 47)
      Thank You
    • By ssah8
      So im creating a bot that logs in on a website. The website got a dropdown menu, and I have to choose the right one to login (Student)
      #include <IE.au3>
      #inculude <Inet.au3>
      $oIE = _IECreate("<snip>")
      $Name = _IEGetObjByName($oIE, "ssusername")
      $Pass = _IEGetObjByName($oIE, "sspassword")
      $dropdown = _IEGetObjByName($oIE, "usertype")
      _IEPropertySet($Name, 'innerText', 'censored')
      _IEPropertySet($Pass, 'innerText', 'censored')
      _IEPropertySet($dropdown, 'innerText', 'Student') <------ How do I make the dropdown list select "Student"?
       
       
    • By ThePoro
      Hi everyone.
      I want to ask about this : 
      I want it runs from 1 to 100 and It opens 10 firefox profiles then access youtube. After I close a firefox window, the loop runs and wait for another window close until loop ends
      I have a loop like this.
      Func launch() Local $from = Int(GUICtrlRead($input1)) Local $to = Int(GUICtrlRead($input2)) If $to <> "" Then While $from <= $to Local $profile = $to _RunDos("start firefox.exe -p " & $profile & " -no-remote youtube.com") $to=$to+1 WEnd Else Local $profile = $to _RunDos("start firefox.exe -p " & $profile & " -no-remote youtube.com") EndIf EndFunc Is there any solution?
      Thank you!
    • By Rhidlor
      First off, the project I'm working on revolves around AS/400 "Client Access software", it's foundation is directly influenced by the thread linked at the bottom of this post. Moving on, to explain the problem I'm facing; my project utilizes an infinite While loop and automatically performs semi-hard coded monotonous tasks to save users time and effort, the problem is, occasionally and unexpectedly "Display Messages" will popup and the core script will continue executing instead of dismissing said message and the script "breaks". As a countermeasure I've added some code to the While loop in an effort to intervene and dismiss these display messages before the core script has a chance to do anything... however it doesn't work. I hope I didn't do too bad of a job explaining that. 
      So I think my question is: How can I temporarily "pause" the core script when these messages spontaneously appear?
      The only other solution I thought of would be to check if a display message has appeared before executing every line of code but that obviously isn't very practical.
      Any and all help is greatly appreciated!
      Thanks
       
      ;Loop to keep script running and handle display messages While 1 dismiss_display_messages() Sleep(50) WEnd ;Function to dismiss display messages Func dismiss_display_messages() If $ps.SearchText("Display Messages") Then $ps.SendKeys("[enter]", 8, 1) ;This while loop waits until the display message has disappeared to resume the core script While $ps.SearchText("Display Messages") Sleep(100) WEnd EndIf EndFunc  
       
×
×
  • Create New...