Jump to content

Guigetmsg help


Rambo
 Share

Recommended Posts

Hi, im working in a little app. Its a Ping sender.

The functionality is very simple: You select the IPs you want to ping to, press Start button and the app will ping to these address until you stop. But here is the main problem, i dont know how to set the app to continue making pings forever until you press "Stop button". Help will be appreciated

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
Guicreate ("Centinela" , 400, 300 )
GUISetState()
$IP1="172.16.0.2"
$IP2="172.16.0.3"
$IP3="172.16.0.4"
$IP4="172.16.0.5"
$IP5="172.16.0.6"
$IP6="172.16.0.7"
$IP7="172.16.0.8"
$box1 = GUICtrlCreateCheckbox($IP1, 50, 30, 120, 20)
$box2 = GUICtrlCreateCheckbox($IP2, 50, 50, 120, 20)
$box3 = GUICtrlCreateCheckbox($IP3, 50, 70, 120, 20)
$box4 = GUICtrlCreateCheckbox($IP4, 50, 90, 120, 20)
$box5 = GUICtrlCreateCheckbox($IP5, 50, 110, 120, 20)
$box6 = GUICtrlCreateCheckbox($IP6, 50, 130, 120, 20)
$box7 = GUICtrlCreateCheckbox($IP7, 50, 150, 120, 20)
$boton1 = GUICtrlCreateButton( "Start" , 150 , 250)
$boton2 = GUICtrlCreateButton( "Stop" , 250 , 250)
While 1
While 1
$state1 = GUICtrlRead($box1)
$state2 = GUICtrlRead($box2)
$state3 = GUICtrlRead($box3)
$state4 = GUICtrlRead($box4)
$state5 = GUICtrlRead($box5)
$state6 = GUICtrlRead($box6)
$state7 = GUICtrlRead($box7)
    $msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then Exit

If $msg = $boton1 Then
    GUICtrlSetState($box1, $GUI_DISABLE)
    GUICtrlSetState($box2, $GUI_DISABLE)
    GUICtrlSetState($box3, $GUI_DISABLE)
    GUICtrlSetState($box4, $GUI_DISABLE)
    GUICtrlSetState($box5, $GUI_DISABLE)
    GUICtrlSetState($box6, $GUI_DISABLE)
    GUICtrlSetState($box7, $GUI_DISABLE)
    Call ("pin")



Elseif $msg = $boton2 Then
    Exitloop
Endif
WEnd
    GUICtrlSetState($box1, $GUI_ENABLE)
    GUICtrlSetState($box2, $GUI_ENABLE)
    GUICtrlSetState($box3, $GUI_ENABLE)
    GUICtrlSetState($box4, $GUI_ENABLE)
    GUICtrlSetState($box5, $GUI_ENABLE)
    GUICtrlSetState($box6, $GUI_ENABLE)
    GUICtrlSetState($box7, $GUI_ENABLE)
Wend
Func pin()

        If $state1 = 1 Then
        GUICtrlCreateLabel( "Haciendo ping a 172.16.0.2 ..." , 100 , 230)
        $pin = Ping ( "209.85.229.103" )

            Sleep(3000)
            If $pin = @error or $pin = 0 Then
            GUICtrlCreateLabel("ERROR", 250 , 30)
        Else
            GUICtrlCreateLabel( $pin & " ms", 250 , 30)
            Endif
        EndIf

            If $state2 = 1 Then
        GUICtrlCreateLabel( "Haciendo ping a 172.16.0.3 ..." , 100 , 230)
        $pin = Ping ( "209.85.229.103" )
        Sleep(3000)
            If $pin = @error or $pin = 0 Then
            GUICtrlCreateLabel("ERROR", 250 , 50)
        Else
            GUICtrlCreateLabel( $pin & " ms", 250 , 50)
            Endif
        EndIf

            If $state3 = 1 Then
        GUICtrlCreateLabel( "Haciendo ping a 172.16.0.4 ..." , 100 , 230)
        $pin = Ping ( "109.85.229.103" )
        Sleep(3000)
            If $pin = @error or $pin = 0 Then
            GUICtrlCreateLabel("ERROR", 250 , 70)
            Else
            GUICtrlCreateLabel( $pin & " ms", 250 , 70)
            Endif
        EndIf

            If $state4 = 1 Then
        GUICtrlCreateLabel( "Haciendo ping a 172.16.0.5 ..." , 100 , 230)
        $pin = Ping ( "109.85.229.103" )
        Sleep(3000)
            If $pin = @error or $pin = 0 Then
            GUICtrlCreateLabel("ERROR", 250 , 90)
        Else
            GUICtrlCreateLabel( $pin & " ms", 250 , 90)
            Endif
        EndIf

            If $state5 = 1 Then
        GUICtrlCreateLabel( "Haciendo ping a 172.16.0.6 ..." , 100 , 230)
        $pin = Ping ( "109.85.229.103" )
        Sleep(3000)
            If $pin = @error or $pin = 0 Then
            GUICtrlCreateLabel("ERROR", 250 , 110)
        Else
            GUICtrlCreateLabel( $pin & " ms", 250 , 110)
            Endif
        EndIf

            If $state6 = 1 Then
        GUICtrlCreateLabel( "Haciendo ping a 172.16.0.7 ..." , 100 , 230)
        $pin = Ping ( "109.85.229.103" )
        Sleep(3000)
            If $pin = @error or $pin = 0 Then
            GUICtrlCreateLabel("ERROR", 250 , 130)
        Else
            GUICtrlCreateLabel( $pin & " ms", 250 , 130)
            Endif
            Endif

            If $state7 = 1 Then
        GUICtrlCreateLabel( "Haciendo ping a 172.16.0.8 ..." , 100 , 230)
        $pin = Ping ( "109.85.229.103" )
        Sleep(3000)
            If $pin = @error or $pin = 0 Then
            GUICtrlCreateLabel("ERROR", 250 , 150)
        Else
            GUICtrlCreateLabel( $pin & " ms", 250 , 150)
            Endif
            Endif

EndFunc

Note: I replaced $IPx with google´s (109.85.229.103) to make tests

Link to comment
Share on other sites

Here's a suggestion, though there are lots of ways it can be done.

First remove all those sleeps from your pin function.

Second, instead of calling pin when you press start add this line

AdlibRegister("pin",9000) run pin every 9 seconds

Third change your code so that when you press stop don't exitloop but instead turn off adlib

AdlibUnregister("pin")

and enable the controls again.

Something like this

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
GUICreate("Centinela", 400, 300)
GUISetState()
$IP1 = "172.16.0.2"
$IP2 = "172.16.0.3"
$IP3 = "172.16.0.4"
$IP4 = "172.16.0.5"
$IP5 = "172.16.0.6"
$IP6 = "172.16.0.7"
$IP7 = "172.16.0.8"
$box1 = GUICtrlCreateCheckbox($IP1, 50, 30, 120, 20)
$box2 = GUICtrlCreateCheckbox($IP2, 50, 50, 120, 20)
$box3 = GUICtrlCreateCheckbox($IP3, 50, 70, 120, 20)
$box4 = GUICtrlCreateCheckbox($IP4, 50, 90, 120, 20)
$box5 = GUICtrlCreateCheckbox($IP5, 50, 110, 120, 20)
$box6 = GUICtrlCreateCheckbox($IP6, 50, 130, 120, 20)
$box7 = GUICtrlCreateCheckbox($IP7, 50, 150, 120, 20)
$boton1 = GUICtrlCreateButton("Start", 150, 250)
$boton2 = GUICtrlCreateButton("Stop", 250, 250)

While 1
    $state1 = GUICtrlRead($box1)
    $state2 = GUICtrlRead($box2)
    $state3 = GUICtrlRead($box3)
    $state4 = GUICtrlRead($box4)
    $state5 = GUICtrlRead($box5)
    $state6 = GUICtrlRead($box6)
    $state7 = GUICtrlRead($box7)
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then Exit

    If $msg = $boton1 Then
    GUICtrlSetState($box1, $GUI_DISABLE)
    GUICtrlSetState($box2, $GUI_DISABLE)
    GUICtrlSetState($box3, $GUI_DISABLE)
    GUICtrlSetState($box4, $GUI_DISABLE)
    GUICtrlSetState($box5, $GUI_DISABLE)
    GUICtrlSetState($box6, $GUI_DISABLE)
    GUICtrlSetState($box7, $GUI_DISABLE)
    AdlibRegister("pin",10000)

    ElseIf $msg = $boton2 Then
        AdlibUnRegister("pin")

    GUICtrlSetState($box1, $GUI_ENABLE)
    GUICtrlSetState($box2, $GUI_ENABLE)
    GUICtrlSetState($box3, $GUI_ENABLE)
    GUICtrlSetState($box4, $GUI_ENABLE)
    GUICtrlSetState($box5, $GUI_ENABLE)
    GUICtrlSetState($box6, $GUI_ENABLE)
    GUICtrlSetState($box7, $GUI_ENABLE)
    EndIf
WEnd

Func pin()

    If $state1 = 1 Then
    GUICtrlCreateLabel("Haciendo ping a 172.16.0.2 ...", 100, 230)
    $pin = Ping("209.85.229.103")

    ;Sleep(3000)
    If $pin = @error Or $pin = 0 Then
    GUICtrlCreateLabel("ERROR", 250, 30)
    Else
    GUICtrlCreateLabel($pin & " ms", 250, 30)
    EndIf
    EndIf

    If $state2 = 1 Then
    GUICtrlCreateLabel("Haciendo ping a 172.16.0.3 ...", 100, 230)
    $pin = Ping("209.85.229.103")
    ;Sleep(3000)
    If $pin = @error Or $pin = 0 Then
    GUICtrlCreateLabel("ERROR", 250, 50)
    Else
    GUICtrlCreateLabel($pin & " ms", 250, 50)
    EndIf
    EndIf

    If $state3 = 1 Then
    GUICtrlCreateLabel("Haciendo ping a 172.16.0.4 ...", 100, 230)
    $pin = Ping("109.85.229.103")
    ;Sleep(3000)
    If $pin = @error Or $pin = 0 Then
    GUICtrlCreateLabel("ERROR", 250, 70)
    Else
    GUICtrlCreateLabel($pin & " ms", 250, 70)
    EndIf
    EndIf

    If $state4 = 1 Then
    GUICtrlCreateLabel("Haciendo ping a 172.16.0.5 ...", 100, 230)
    $pin = Ping("109.85.229.103")
    ;Sleep(3000)
    If $pin = @error Or $pin = 0 Then
    GUICtrlCreateLabel("ERROR", 250, 90)
    Else
    GUICtrlCreateLabel($pin & " ms", 250, 90)
    EndIf
    EndIf

    If $state5 = 1 Then
    GUICtrlCreateLabel("Haciendo ping a 172.16.0.6 ...", 100, 230)
    $pin = Ping("109.85.229.103")
    ;Sleep(3000)
    If $pin = @error Or $pin = 0 Then
    GUICtrlCreateLabel("ERROR", 250, 110)
    Else
    GUICtrlCreateLabel($pin & " ms", 250, 110)
    EndIf
    EndIf

    If $state6 = 1 Then
    GUICtrlCreateLabel("Haciendo ping a 172.16.0.7 ...", 100, 230)
    $pin = Ping("109.85.229.103")
    ;Sleep(3000)
    If $pin = @error Or $pin = 0 Then
    GUICtrlCreateLabel("ERROR", 250, 130)
    Else
    GUICtrlCreateLabel($pin & " ms", 250, 130)
    EndIf
    EndIf

    If $state7 = 1 Then
    GUICtrlCreateLabel("Haciendo ping a 172.16.0.8 ...", 100, 230)
    $pin = Ping("109.85.229.103")
    ;Sleep(3000)
    If $pin = @error Or $pin = 0 Then
    GUICtrlCreateLabel("ERROR", 250, 150)
    Else
    GUICtrlCreateLabel($pin & " ms", 250, 150)
    EndIf
    EndIf

EndFunc ;==>pin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks, it works!

Only one thing, i put those sleeps because the app is going too fast. I suppose i have to make a Call for every ping action:

AdlibRegister("pin1",9000)

AdlibRegister("pin2",9000)

AdlibRegister("pin3",9000)

and so on...

Link to comment
Share on other sites

Thanks, it works!

Only one thing, i put those sleeps because the app is going too fast. I suppose i have to make a Call for every ping action:

AdlibRegister("pin1",9000)

AdlibRegister("pin2",9000)

AdlibRegister("pin3",9000)

and so on...

I think it's better to simplify the script before you get problems as more and more requirements are added.

See what you make of this which is just your script compressed and a bit of tinkering. I hope you don't mind the meddling.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

GUICreate("Centinela", 400, 300)
GUISetState()
Global $IP[7] = ["172.16.0.2", "172.16.0.3", "172.16.0.4", "172.16.0.5", "172.16.0.6", "172.16.0.7", "172.16.0.8"]
Global $box[7], $label[7]
For $n = 0 To 6
    $box[$n] = GUICtrlCreateCheckbox($IP[$n], 50, 30 + 20 * $n, 120, 20)
    $label[$n] = GUICtrlCreateLabel("   ms", 250, 30 + 20 * $n, 200)
Next
$boton1 = GUICtrlCreateButton("Start", 150, 250)
$boton2 = GUICtrlCreateButton("Stop", 250, 250)
$lblStatus = GUICtrlCreateLabel("----------Haciendo currently idle-----------", 100, 230)
Global $count = 0;
While 1

    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then Exit

    If $msg = $boton1 Then
    For $n = 0 To 6
    GUICtrlSetState($box[$n], $GUI_DISABLE)
    Next
        pin()
    AdlibRegister("pin", 4000)

    ElseIf $msg = $boton2 Then
    $stopped = True
    For $n = 0 To 6
    GUICtrlSetState($box[$n], $GUI_ENABLE)
    Next
    EndIf
WEnd

Func pin()

    If GUICtrlRead($box[$count]) = 1 Then
    GUICtrlSetData($lblStatus, "Haciendo ping a " & $IP[$count])
    $pin = Ping($IP[$count])

    If $pin = @error Or $pin = 0 Then
    GUICtrlSetData($label[$count], "ERROR")
    Else
    GUICtrlSetData($label[$count], $pin & " ms")
    EndIf
    EndIf
 
 ;GUICtrlSetData($lblStatus,"----------Haciendo currently idle-----------")
    $count += 1
    If $count > 6 Then $count = 0
EndFunc ;==>pin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

And another little problem...

I introduced a list ($list) but the data is writed one under other. I want to put time, IP and ping together in one single line

GUICtrlSetData($list, @Hour & ":" & @MIN & ":" & @SEC & " | " & $IP[$count] & " | " & $pin)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Date.au3>

GUICreate("Centinela", 400, 500)
$list = GUICtrlCreateList("" , 10 , 380, 380 , 100  )
GUICtrlSetLimit(-1, 200)
GUICtrlSetColor(-1, 0xff0000) ; red text
GUISetState()

$tempname = @MDAY & @mon & @Year & "errorlog.txt" ; save errors to log
Global $IP[7] = ["172.16.0.2", "172.16.0.3", "172.16.0.4", "172.16.0.5", "172.16.0.6", "172.16.0.7", "172.16.0.8"]
Global $box[7], $label[7] , $errors[7]
For $n = 0 To 6
    $box[$n] = GUICtrlCreateCheckbox($IP[$n], 50, 30 + 20 * $n, 120, 20)
    $label[$n] = GUICtrlCreateLabel("   ms", 250, 30 + 20 * $n, 200)
Next
$boton1 = GUICtrlCreateButton("Start", 110, 250)
$boton2 = GUICtrlCreateButton("Stop", 210, 250)
Global $count = 0;
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then Exit

    If $msg = $boton1 Then
    For $n = 0 To 6
    GUICtrlSetState($box[$n], $GUI_DISABLE)
    Next
        pin()
    AdlibRegister("pin", 4000)

    ElseIf $msg = $boton2 Then
    $stopped = True
    For $n = 0 To 6
    GUICtrlSetState($box[$n], $GUI_ENABLE)
    Next
    EndIf
WEnd

Func pin()

    If GUICtrlRead($box[$count]) = 1 Then
      $pin = Ping($IP[$count])
      GUICtrlSetData($list, @Hour & ":" & @MIN & ":" & @SEC & " | " & $IP[$count] & " | " & $pin) ; print in the list time,IP and ping
      $errors[$count] = 0

    If $pin = @error Or $pin = 0 Then ; cant do ping
    GUICtrlSetData($label[$count], "ERROR")
    GUICtrlSetData($list, @Hour & ":" & @MIN & ":" & @SEC & " | " & $IP[$count] & " | " & "ERROR") ; print in the list time, IP and ERROR
    $errors[$count] += 1 ; increase counter
    Filewrite( $tempname , @Hour & ":" & @MIN & ":" & @SEC & " | " & $IP[$count] & " | " & @CRLF) ; write error to the log
        If $errors[$count] = 3 Then ; on 3 errors
            Filewrite( $tempname , @Hour & ":" & @MIN & ":" & @SEC & " | " & "ALARM ON " & $IP[$count]  & @CRLF) ; write alarm!
            $errors[$count] = 0
         msgbox( 1 , "Alarm" , "3 consecutive errors for " & $IP[$count] ) ; activate alarm
        Endif
        Else
    GUICtrlSetData($label[$count], $pin & " ms")
    EndIf
    EndIf

 ;GUICtrlSetData($lblStatus,"----------Haciendo currently idle-----------")
    $count += 1
    If $count > 6 Then $count = 0
EndFunc ;==>pin

Thanks

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