Jump to content

how to break infinite loop by an Events ?


Go to solution Solved by Melba23,

Recommended Posts

  • Moderators

PKG.

I recommend reading the Interrupting a running function tutorial in the Wiki - all is explained there. But do come back and ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

PKG,

There is a fully commented example of OnEvent mode interruption in the Wiki tutorial - I see no point in reposting it here. It would be better if you posted the code you tried - then I could see why it did not work for you. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Here is my Code...

#include<GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)

$FL = True

Local $MainForm = GUICreate("Win_App-1", 550, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "WinExit")

Global $MyEditBox = GUICtrlCreateEdit("", 5, 30, 540, 270)
GUICtrlSetBkColor($MyEditBox, 0xFF6347)

Global $RunButton = GUICtrlCreateButton("&Run", 120, 420, 70, 30)
GUICtrlSetOnEvent($RunButton, "DataLoop")

Global $StopButton = GUICtrlCreateButton("&Stop", 200, 420, 70, 30)
GUICtrlSetOnEvent($StopButton, "DataLoop")

GUISetState()

While 1
    Sleep(10)
WEnd
Func WinExit()
    Exit 0
EndFunc   ;==>WinExit

Func StopLoop()
    $FL = False
    EndFunc

Func DataLoop()
    While $FL

        If HotKeySet("A") = 1 Then
            MsgBox(0,"Key","It is A")
        ElseIf HotKeySet("B") = 1 Then
            MsgBox(0,"Key","It is B")
        EndIf
    WEnd
    Return
EndFunc   ;==>DataLoop
 

I want that, when the user click on Run Button then the loop will be started and when the user click on the Stop button then the loop will be stop.
Will you plz show me that what is the error in this Code and how to fix it ? :)

Edited by PKG
Link to comment
Share on other sites

  • Moderators
  • Solution

PKG,

The "flag and wrapper" method is certainly the easiest way in this case - this works for me: ;)

#include<GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

$FL = False

Local $MainForm = GUICreate("Win_App-1", 550, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "WinExit")

Global $MyEditBox = GUICtrlCreateEdit("", 5, 30, 540, 270)
GUICtrlSetBkColor($MyEditBox, 0xFF6347)

Global $RunButton = GUICtrlCreateButton("&Run", 120, 420, 70, 30)
GUICtrlSetOnEvent($RunButton, "Run_DataLoop")

Global $StopButton = GUICtrlCreateButton("&Stop", 200, 420, 70, 30)
GUICtrlSetOnEvent($StopButton, "Run_DataLoop")

GUISetState()

While 1
    Sleep(10)
    ; Look for the flag
    If $FL Then
        ; Run the function
        DataLoop()
    EndIf
WEnd

Func WinExit()
    Exit 0
EndFunc   ;==>WinExit

; This function will always run as the function to interrupt was started from the idle loop
Func Run_DataLoop()
    Switch @GUI_CtrlId
        Case $RunButton
            $FL = True
        Case $StopButton
            $FL = False
    EndSwitch
EndFunc

Func DataLoop()
    ; Look for the flag
    While $FL
        ToolTip("Func Running")
        Sleep(10)
    WEnd
    ; And break out if it is cleared
    ToolTip("Function Stopped")
    Sleep(500)
    ToolTip("")
    Return
EndFunc   ;==>DataLoop
Does it work for you too? :)

 

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

PKG,

Glad I could help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 1 year later...

Hi Melba23,

Thank you for your 'flag and wrapper' script which allows one to terminate/re-start a While1....WEnd infinite loop. :ILA: and your scripts!

However, I find that your script when integrated with mine possibly interferes with my script's pixel searching/testing ability, and so I am wondering if you could tell me what is going wrong and how I could sort it out.

My own script reads pixel colour data at particular screen coordinates, to detect the on/off states of various segments of an on-screen representation of 7-segment LEDs, and then collects this data over 15 such digits  organized horizontally, to capture the digit sequence being displayed. A sort of "real time OCR" applied to a specific display. The script works flawlessly on its own. However it has a While1.....WEnd loop executing every 100 ms, so as to continually read the changing digits and feed them over a COM port to a waiting Arduino. I would like to be able to exit from the loop with a button, without having to terminate the program from its system tray icon.

I am trying to integrate my script within the framework provided by yours, but find that when I do so the script starts making errors in reading digits beyond the third in the sequence.

I have independently checked that the window has not moved in any way, and that the pixel colours have not changed. So I attribute the degraded operation of my script to some interference from your 'flag and wrapper script'.

Any clues as to what it might be?

Thank you ever so much for your time and patience!

Chakko.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Constants.au3>
#include <File.au3>
#include <CommAPI.au3>
#include <CommInterface.au3>
#include <CommUtilities.au3>
#include <CommAPIHelper.au3>
#include <CommAPIConstants.au3>
#include<GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)
Opt("PixelCoordMode", 1) ;1=absolute, 0=relative, 2=client



$FL = False

Local $MainForm = GUICreate("Win_App-1", 550, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "WinExit")

Global $MyEditBox = GUICtrlCreateEdit("", 5, 30, 540, 270)
GUICtrlSetBkColor($MyEditBox, 0xFF6347)

Global $RunButton = GUICtrlCreateButton("&Run", 120, 420, 70, 30)
GUICtrlSetOnEvent($RunButton, "Run_DataLoop")

Global $StopButton = GUICtrlCreateButton("&Stop", 200, 420, 70, 30)
GUICtrlSetOnEvent($StopButton, "Run_DataLoop")

GUISetState()

While 1
    Sleep(10)
    ; Look for the flag
    If $FL Then
        ; Run the function
        DataLoop()
    EndIf
WEnd

Func WinExit()
    Exit 0
EndFunc   ;==>WinExit

; This function will always run as the function to interrupt was started from the idle loop
Func Run_DataLoop()
    Switch @GUI_CtrlId
        Case $RunButton
            $FL = True
        Case $StopButton
            $FL = False
    EndSwitch
EndFunc

Func DataLoop()
    Local $hFile = _CommAPI_OpenCOMPort(4, 115200, 0, 8, 1)
    ; Look for the flag
    While $FL

;---------IAS/MACH-----------

If PixelGetColor (2428,158) > 10000000 Then
Global $sSPDd = "."
Else
    $sSPDd = " "
EndIf

If PixelGetColor (2484,137) > 10000000 Then
Global $sA3 = 1
Else
    $sA3 = 0
EndIf

If PixelGetColor (2493,144) > 10000000 Then
Global $sB3 = 1
Else
    $sB3 = 0
Endif

If PixelGetColor (2493,155) > 10000000 Then
Global $sC3 = 1
Else
    $sC3 = 0
EndIf

If PixelGetColor (2490,160) > 10000000 Then
Global $sD3 = 1
Else
    $sD3 = 0
EndIf

If PixelGetColor (2482,155) > 10000000 Then
Global $sE3 = 1
Else
    $sE3 = 0
EndIf

If PixelGetColor (2482,144) > 10000000 Then
Global $sF3 = 1
Else
    $sF3 = 0
EndIf

If PixelGetColor (2490,148) > 10000000 Then
Global $sG3 = 1
Else
    $sG3 = 0
EndIf

Local $sSPD3=$sA3&$sB3&$sC3&$sD3&$sE3&$sF3&$sG3

If StringCompare ($sSPD3, "1111110") = 0 Then
    Global $sSPDu = 0
ElseIf StringCompare ($sSPD3, "1101101") = 0 Then
    $sSPDu = 2
ElseIf StringCompare ($sSPD3, "1111001") = 0 Then
    $sSPDu = 3
ElseIf StringCompare ($sSPD3, "0110011") = 0 Then
    $sSPDu = 4
ElseIf StringCompare ($sSPD3, "1011011") = 0 Then
    $sSPDu = 5
ElseIf StringCompare ($sSPD3, "1011111") = 0 Then
    $sSPDu = 6
ElseIf StringCompare ($sSPD3, "1110000") = 0 Then
    $sSPDu = 7
ElseIf StringCompare ($sSPD3, "1111111") = 0 Then
    $sSPDu = 8
ElseIf StringCompare ($sSPD3, "1111011") = 0 Then
    $sSPDu = 9
Else
    $sSPDu = 1
    EndIf

;----------------------------------------

If PixelGetColor (2464,137) > 10000000 Then
Global $sA2 = 1
Else
    $sA2 = 0
EndIf

If PixelGetColor (2473,144) > 10000000 Then
Global $sB2 = 1
Else
    $sB2 = 0
Endif

If PixelGetColor (2473,155) > 10000000 Then
Global $sC2 = 1
Else
    $sC2 = 0
EndIf

If PixelGetColor (2470,160) > 10000000 Then
Global $sD2 = 1
Else
    $sD2 = 0
EndIf

If PixelGetColor (2462,155) > 10000000 Then
Global $sE2 = 1
Else
    $sE2 = 0
EndIf

If PixelGetColor (2462,144) > 10000000 Then
Global $sF2 = 1
Else
    $sF2 = 0
EndIf

If PixelGetColor (2470,148) > 10000000 Then
Global $sG2 = 1
Else
    $sG2 = 0
EndIf

Local $sSPD2=$sA2&$sB2&$sC2&$sD2&$sE2&$sF2&$sG2

If StringCompare ($sSPD2, "1111110") = 0 Then
    Global $sSPDt = 0
ElseIf StringCompare ($sSPD2, "1101101") = 0 Then
    $sSPDt = 2
ElseIf StringCompare ($sSPD2, "1111001") = 0 Then
    $sSPDt = 3
ElseIf StringCompare ($sSPD2, "0110011") = 0 Then
    $sSPDt = 4
ElseIf StringCompare ($sSPD2, "1011011") = 0 Then
    $sSPDt = 5
ElseIf StringCompare ($sSPD2, "1011111") = 0 Then
    $sSPDt = 6
ElseIf StringCompare ($sSPD2, "1110000") = 0 Then
    $sSPDt = 7
ElseIf StringCompare ($sSPD2, "1111111") = 0 Then
    $sSPDt = 8
ElseIf StringCompare ($sSPD2, "1111011") = 0 Then
    $sSPDt = 9
Else
    $sSPDt = 1
EndIf

;----------------------------------------

If PixelGetColor (2444,137) > 10000000 Then
Global $sA1 = 1
Else
    $sA1 = 0
EndIf

If PixelGetColor (2453,144) > 10000000 Then
Global $sB1 = 1
Else
    $sB1 = 0
Endif

If PixelGetColor (2453,155) > 10000000 Then
Global $sC1 = 1
Else
    $sC1 = 0
EndIf

If PixelGetColor (2450,160) > 10000000 Then
Global $sD1 = 1
Else
    $sD1 = 0
EndIf

If PixelGetColor (2442,155) > 10000000 Then
Global $sE1 = 1
Else
    $sE1 = 0
EndIf

If PixelGetColor (2442,144) > 10000000 Then
Global $sF1 = 1
Else
    $sF1 = 0
EndIf

If PixelGetColor (2450,148) > 10000000 Then
Global $sG1 = 1
Else
    $sG1 = 0
EndIf

Local $sSPD1=$sA1&$sB1&$sC1&$sD1&$sE1&$sF1&$sG1

If StringCompare ($sSPD1, "1111110") = 0 Then
    Global $sSPDh = 0
ElseIf StringCompare ($sSPD1, "1101101") = 0 Then
    $sSPDh = 2
ElseIf StringCompare ($sSPD1, "1111001") = 0 Then
    $sSPDh = 3
ElseIf StringCompare ($sSPD1, "0110011") = 0 Then
    $sSPDh = 4
ElseIf StringCompare ($sSPD1, "1011011") = 0 Then
    $sSPDh = 5
ElseIf StringCompare ($sSPD1, "1011111") = 0 Then
    $sSPDh = 6
ElseIf StringCompare ($sSPD1, "1110000") = 0 Then
    $sSPDh = 7
ElseIf StringCompare ($sSPD1, "1111111") = 0 Then
    $sSPDh = 8
ElseIf StringCompare ($sSPD1, "1111011") = 0 Then
    $sSPDh = 9
Else
    $sSPDh = 1
EndIf

;---------FIRST 3 DIGITs-----------

If PixelGetColor (2677,137) > 10000000 Then
Global $sA3 = 1
Else
    $sA3 = 0
EndIf

If PixelGetColor (2686,144) > 10000000 Then
Global $sB3 = 1
Else
    $sB3 = 0
Endif

If PixelGetColor (2686,155) > 10000000 Then
Global $sC3 = 1
Else
    $sC3 = 0
EndIf

If PixelGetColor (2683,160) > 10000000 Then
Global $sD3 = 1
Else
    $sD3 = 0
EndIf

If PixelGetColor (2675,155) > 10000000 Then
Global $sE3 = 1
Else
    $sE3 = 0
EndIf

If PixelGetColor (2675,144) > 10000000 Then
Global $sF3 = 1
Else
    $sF3 = 0
EndIf

If PixelGetColor (2683,148) > 10000000 Then
Global $sG3 = 1
Else
    $sG3 = 0
EndIf

Local $sHDG3=$sA3&$sB3&$sC3&$sD3&$sE3&$sF3&$sG3

If StringCompare ($sHDG3, "1111110") = 0 Then
    Global $sHDGu = 0
ElseIf StringCompare ($sHDG3, "1101101") = 0 Then
    $sHDGu = 2
ElseIf StringCompare ($sHDG3, "1111001") = 0 Then
    $sHDGu = 3
ElseIf StringCompare ($sHDG3, "0110011") = 0 Then
    $sHDGu = 4
ElseIf StringCompare ($sHDG3, "1011011") = 0 Then
    $sHDGu = 5
ElseIf StringCompare ($sHDG3, "1011111") = 0 Then
    $sHDGu = 6
ElseIf StringCompare ($sHDG3, "1110000") = 0 Then
    $sHDGu = 7
ElseIf StringCompare ($sHDG3, "1111111") = 0 Then
    $sHDGu = 8
ElseIf StringCompare ($sHDG3, "1111011") = 0 Then
    $sHDGu = 9
Else
    $sHDGu = 1
EndIf

;----------------------------------------

If PixelGetColor (2657,137) > 10000000 Then
Global $sA2 = 1
Else
    $sA2 = 0
EndIf

If PixelGetColor (2666,144) > 10000000 Then
Global $sB2 = 1
Else
    $sB2 = 0
Endif

If PixelGetColor (2666,155) > 10000000 Then
Global $sC2 = 1
Else
    $sC2 = 0
EndIf

If PixelGetColor (2663,160) > 10000000 Then
Global $sD2 = 1
Else
    $sD2 = 0
EndIf

If PixelGetColor (2655,155) > 10000000 Then
Global $sE2 = 1
Else
    $sE2 = 0
EndIf

If PixelGetColor (2655,144) > 10000000 Then
Global $sF2 = 1
Else
    $sF2 = 0
EndIf

If PixelGetColor (2663,148) > 10000000 Then
Global $sG2 = 1
Else
    $sG2 = 0
EndIf

Local $sHDG2=$sA2&$sB2&$sC2&$sD2&$sE2&$sF2&$sG2


If StringCompare ($sHDG2, "1111110") = 0 Then
    Global $sHDGt = 0
ElseIf StringCompare ($sHDG2, "1101101") = 0 Then
    $sHDGt = 2
ElseIf StringCompare ($sHDG2, "1111001") = 0 Then
    $sHDGt = 3
ElseIf StringCompare ($sHDG2, "0110011") = 0 Then
    $sHDGt = 4
ElseIf StringCompare ($sHDG2, "1011011") = 0 Then
    $sHDGt = 5
ElseIf StringCompare ($sHDG2, "1011111") = 0 Then
    $sHDGt = 6
ElseIf StringCompare ($sHDG2, "1110000") = 0 Then
    $sHDGt = 7
ElseIf StringCompare ($sHDG2, "1111111") = 0 Then
    $sHDGt = 8
ElseIf StringCompare ($sHDG2, "1111011") = 0 Then
    $sHDGt = 9
Else
    $sHDGt = 1
EndIf

;----------------------------------------

If PixelGetColor (2637,137) > 10000000 Then
Global $sA1 = 1
Else
    $sA1 = 0
EndIf

If PixelGetColor (2646,144) > 10000000 Then
Global $sB1 = 1
Else
    $sB1 = 0
Endif

If PixelGetColor (2646,155) > 10000000 Then
Global $sC1 = 1
Else
    $sC1 = 0
EndIf

If PixelGetColor (2643,160) > 10000000 Then
Global $sD1 = 1
Else
    $sD1 = 0
EndIf

If PixelGetColor (2635,155) > 10000000 Then
Global $sE1 = 1
Else
    $sE1 = 0
EndIf

If PixelGetColor (2635,144) > 10000000 Then
Global $sF1 = 1
Else
    $sF1 = 0
EndIf

If PixelGetColor (2643,148) > 10000000 Then
Global $sG1 = 1
Else
    $sG1 = 0
EndIf

Local $sHDG1=$sA1&$sB1&$sC1&$sD1&$sE1&$sF1&$sG1

If StringCompare ($sHDG1, "1111110") = 0 Then
    Global $sHDGh = 0
ElseIf StringCompare ($sHDG1, "1101101") = 0 Then
    $sHDGh = 2
ElseIf StringCompare ($sHDG1, "1111001") = 0 Then
    $sHDGh = 3
Else
    $sHDGh = 1
EndIf

;---------DIGITS 4 to 6-----------

If PixelGetColor (3121,137) > 10000000 Then
Global $sA5 = 1
Else
    $sA5 = 0
EndIf

If PixelGetColor (3130,144) > 10000000 Then
Global $sB5 = 1
Else
    $sB5 = 0
Endif

If PixelGetColor (3130,155) > 10000000 Then
Global $sC5 = 1
Else
    $sC5 = 0
EndIf

If PixelGetColor (3127,160) > 10000000 Then
Global $sD5 = 1
Else
    $sD5 = 0
EndIf

If PixelGetColor (3119,155) > 10000000 Then
Global $sE5 = 1
Else
    $sE5 = 0
EndIf

If PixelGetColor (3119,144) > 10000000 Then
Global $sF5 = 1
Else
    $sF5 = 0
EndIf

If PixelGetColor (3127,148) > 10000000 Then
Global $sG5 = 1
Else
    $sG5 = 0
EndIf

Local $sALT5=$sA5&$sB5&$sC5&$sD5&$sE5&$sF5&$sG5


If StringCompare ($sALT5, "1111110") = 0 Then
    Global $sALTu = 0
ElseIf StringCompare ($sALT5, "1101101") = 0 Then
    $sALTu = 2
ElseIf StringCompare ($sALT5, "1111001") = 0 Then
    $sALTu = 3
ElseIf StringCompare ($sALT5, "0110011") = 0 Then
    $sALTu = 4
ElseIf StringCompare ($sALT5, "1011011") = 0 Then
    $sALTu = 5
ElseIf StringCompare ($sALT5, "1011111") = 0 Then
    $sALTu = 6
ElseIf StringCompare ($sALT5, "1110000") = 0 Then
    $sALTu = 7
ElseIf StringCompare ($sALT5, "1111111") = 0 Then
    $sALTu = 8
ElseIf StringCompare ($sALT5, "1111011") = 0 Then
    $sALTu = 9
ElseIf PixelGetColor (3127,142) > 10000000 Then
    $sALTu = 1
Else
    $sALTu = " "
    EndIf

;----------------------------------------

If PixelGetColor (3101,137) > 10000000 Then
Global $sA4 = 1
Else
    $sA4 = 0
EndIf

If PixelGetColor (3110,144) > 10000000 Then
Global $sB4 = 1
Else
    $sB4 = 0
Endif

If PixelGetColor (3110,155) > 10000000 Then
Global $sC4 = 1
Else
    $sC4 = 0
EndIf

If PixelGetColor (3107,160) > 10000000 Then
Global $sD4 = 1
Else
    $sD4 = 0
EndIf

If PixelGetColor (3099,155) > 10000000 Then
Global $sE4 = 1
Else
    $sE4 = 0
EndIf

If PixelGetColor (3099,144) > 10000000 Then
Global $sF4 = 1
Else
    $sF4 = 0
EndIf

If PixelGetColor (3107,148) > 10000000 Then
Global $sG4 = 1
Else
    $sG4 = 0
EndIf

Local $sALT4=$sA4&$sB4&$sC4&$sD4&$sE4&$sF4&$sG4


If StringCompare ($sALT4, "1111110") = 0 Then
    Global $sALTt = 0
ElseIf StringCompare ($sALT4, "1101101") = 0 Then
    $sALTt = 2
ElseIf StringCompare ($sALT4, "1111001") = 0 Then
    $sALTt = 3
ElseIf StringCompare ($sALT4, "0110011") = 0 Then
    $sALTt = 4
ElseIf StringCompare ($sALT4, "1011011") = 0 Then
    $sALTt = 5
ElseIf StringCompare ($sALT4, "1011111") = 0 Then
    $sALTt = 6
ElseIf StringCompare ($sALT4, "1110000") = 0 Then
    $sALTt = 7
ElseIf StringCompare ($sALT4, "1111111") = 0 Then
    $sALTt = 8
ElseIf StringCompare ($sALT4, "1111011") = 0 Then
    $sALTt = 9
ElseIf PixelGetColor (3107,142) > 10000000 Then
    $sALTt = 1
Else
    $sALTt = " "
    EndIf

;----------------------------------------

If PixelGetColor (3081,137) > 10000000 Then
Global $sA3 = 1
Else
    $sA3 = 0
EndIf

If PixelGetColor (3090,144) > 10000000 Then
Global $sB3 = 1
Else
    $sB3 = 0
Endif

If PixelGetColor (3090,155) > 10000000 Then
Global $sC3 = 1
Else
    $sC3 = 0
EndIf

If PixelGetColor (3087,160) > 10000000 Then
Global $sD3 = 1
Else
    $sD3 = 0
EndIf

If PixelGetColor (3079,155) > 10000000 Then
Global $sE3 = 1
Else
    $sE3 = 0
EndIf

If PixelGetColor (3079,144) > 10000000 Then
Global $sF3 = 1
Else
    $sF3 = 0
EndIf

If PixelGetColor (3087,148) > 10000000 Then
Global $sG3 = 1
Else
    $sG3 = 0
EndIf

Local $sALT3=$sA3&$sB3&$sC3&$sD3&$sE3&$sF3&$sG3


If StringCompare ($sALT3, "1111110") = 0 Then
    Global $sALTh = 0
ElseIf StringCompare ($sALT3, "1101101") = 0 Then
    $sALTh = 2
ElseIf StringCompare ($sALT3, "1111001") = 0 Then
    $sALTh = 3
ElseIf StringCompare ($sALT3, "0110011") = 0 Then
    $sALTh = 4
ElseIf StringCompare ($sALT3, "1011011") = 0 Then
    $sALTh = 5
ElseIf StringCompare ($sALT3, "1011111") = 0 Then
    $sALTh = 6
ElseIf StringCompare ($sALT3, "1110000") = 0 Then
    $sALTh = 7
ElseIf StringCompare ($sALT3, "1111111") = 0 Then
    $sALTh = 8
ElseIf StringCompare ($sALT3, "1111011") = 0 Then
    $sALTh = 9
ElseIf PixelGetColor (3087,142) > 10000000 Then
    $sALTh = 1
Else
    $sALTh = " "
    EndIf

;----------------------------------------

If PixelGetColor (3061,137) > 10000000 Then
Global $sA2 = 1
Else
    $sA2 = 0
EndIf

If PixelGetColor (3070,144) > 10000000 Then
Global $sB2 = 1
Else
    $sB2 = 0
Endif

If PixelGetColor (3070,155) > 10000000 Then
Global $sC2 = 1
Else
    $sC2 = 0
EndIf

If PixelGetColor (3067,160) > 10000000 Then
Global $sD2 = 1
Else
    $sD2 = 0
EndIf

If PixelGetColor (3059,155) > 10000000 Then
Global $sE2 = 1
Else
    $sE2 = 0
EndIf

If PixelGetColor (3059,144) > 10000000 Then
Global $sF2 = 1
Else
    $sF2 = 0
EndIf

If PixelGetColor (3067,148) > 10000000 Then
Global $sG2 = 1
Else
    $sG2 = 0
EndIf

Local $sALT2=$sA2&$sB2&$sC2&$sD2&$sE2&$sF2&$sG2


If StringCompare ($sALT2, "1111110") = 0 Then
    Global $sALTth = 0
ElseIf StringCompare ($sALT2, "1101101") = 0 Then
    $sALTth = 2
ElseIf StringCompare ($sALT2, "1111001") = 0 Then
    $sALTth = 3
ElseIf StringCompare ($sALT2, "0110011") = 0 Then
    $sALTth = 4
ElseIf StringCompare ($sALT2, "1011011") = 0 Then
    $sALTth = 5
ElseIf StringCompare ($sALT2, "1011111") = 0 Then
    $sALTth = 6
ElseIf StringCompare ($sALT2, "1110000") = 0 Then
    $sALTth = 7
ElseIf StringCompare ($sALT2, "1111111") = 0 Then
    $sALTth = 8
ElseIf StringCompare ($sALT2, "1111011") = 0 Then
    $sALTth = 9
ElseIf PixelGetColor (3067,142) > 10000000 Then
    $sALTth = 1
Else
    $sALTth = " "
    EndIf

;----------------------------------------

If PixelGetColor (3041,137) > 10000000 Then
Global $sA1 = 1
Else
    $sA1 = 0
EndIf

If PixelGetColor (3050,144) > 10000000 Then
Global $sB1 = 1
Else
    $sB1 = 0
Endif

If PixelGetColor (3050,155) > 10000000 Then
Global $sC1 = 1
Else
    $sC1 = 0
EndIf

If PixelGetColor (3047,160) > 10000000 Then
Global $sD1 = 1
Else
    $sD1 = 0
EndIf

If PixelGetColor (3039,155) > 10000000 Then
Global $sE1 = 1
Else
    $sE1 = 0
EndIf

If PixelGetColor (3039,144) > 10000000 Then
Global $sF1 = 1
Else
    $sF1 = 0
EndIf

If PixelGetColor (3047,148) > 10000000 Then
Global $sG1 = 1
Else
    $sG1 = 0
    EndIf

Local $sALT1=$sA1&$sB1&$sC1&$sD1&$sE1&$sF1&$sG1

If StringCompare ($sALT1, "1111110") = 0 Then
    Global $sALTtt = 0
ElseIf StringCompare ($sALT1, "1101101") = 0 Then
    $sALTtt = 2
ElseIf StringCompare ($sALT1, "1111001") = 0 Then
    $sALTtt = 3
ElseIf StringCompare ($sALT1, "0110011") = 0 Then
    $sALTtt = 4
ElseIf StringCompare ($sALT1, "1011011") = 0 Then
    $sALTtt = 5
ElseIf StringCompare ($sALT1, "1011111") = 0 Then
    $sALTtt = 6
ElseIf StringCompare ($sALT1, "1110000") = 0 Then
    $sALTtt = 7
ElseIf StringCompare ($sALT1, "1111111") = 0 Then
    $sALTtt = 8
ElseIf StringCompare ($sALT1, "1111011") = 0 Then
    $sALTtt = 9
ElseIf PixelGetColor (3047,142) > 10000000 Then
    $sALTtt = 1
Else
    $sALTtt = " "
    EndIf


;---------DIGITS 7to 10-----------

If PixelGetColor (3346,137) > 10000000 Then
Global $sA4 = 1
Else
    $sA4 = 0
EndIf

If PixelGetColor (3355,144) > 10000000 Then
Global $sB4 = 1
Else
    $sB4 = 0
Endif

If PixelGetColor (3355,155) > 10000000 Then
Global $sC4 = 1
Else
    $sC4 = 0
EndIf

If PixelGetColor (3352,160) > 10000000 Then
Global $sD4 = 1
Else
    $sD4 = 0
EndIf

If PixelGetColor (3344,155) > 10000000 Then
Global $sE4 = 1
Else
    $sE4 = 0
EndIf

If PixelGetColor (3344,144) > 10000000 Then
Global $sF4 = 1
Else
    $sF4 = 0
EndIf

If PixelGetColor (3352,148) > 10000000 Then
Global $sG4 = 1
Else
    $sG4 = 0
EndIf

Local $sVSF4=$sA4&$sB4&$sC4&$sD4&$sE4&$sF4&$sG4


If StringCompare ($sVSF4, "1111110") = 0 Then
    Global $sVSFu = 0
ElseIf StringCompare ($sVSF4, "1101101") = 0 Then
    $sVSFu = 2
ElseIf StringCompare ($sVSF4, "1111001") = 0 Then
    $sVSFu = 3
ElseIf StringCompare ($sVSF4, "0110011") = 0 Then
    $sVSFu = 4
ElseIf StringCompare ($sVSF4, "1011011") = 0 Then
    $sVSFu = 5
ElseIf StringCompare ($sVSF4, "1011111") = 0 Then
    $sVSFu = 6
ElseIf StringCompare ($sVSF4, "1110000") = 0 Then
    $sVSFu = 7
ElseIf StringCompare ($sVSF4, "1111111") = 0 Then
    $sVSFu = 8
ElseIf StringCompare ($sVSF4, "1111011") = 0 Then
    $sVSFu = 9
ElseIf PixelGetColor (3352,142) > 10000000 Then
    $sVSFu = 1
Else
    $sVSFu = " "
    EndIf

;----------------------------------------

If PixelGetColor (3326,137) > 10000000 Then
Global $sA3 = 1
Else
    $sA3 = 0
EndIf

If PixelGetColor (3335,144) > 10000000 Then
Global $sB3 = 1
Else
    $sB3 = 0
Endif

If PixelGetColor (3335,155) > 10000000 Then
Global $sC3 = 1
Else
    $sC3 = 0
EndIf

If PixelGetColor (3332,160) > 10000000 Then
Global $sD3 = 1
Else
    $sD3 = 0
EndIf

If PixelGetColor (3324,155) > 10000000 Then
Global $sE3 = 1
Else
    $sE3 = 0
EndIf

If PixelGetColor (3324,144) > 10000000 Then
Global $sF3 = 1
Else
    $sF3 = 0
EndIf

If PixelGetColor (3332,148) > 10000000 Then
Global $sG3 = 1
Else
    $sG3 = 0
EndIf

Local $sVSF3=$sA3&$sB3&$sC3&$sD3&$sE3&$sF3&$sG3


If StringCompare ($sVSF3, "1111110") = 0 Then
    Global $sVSFt = 0
ElseIf StringCompare ($sVSF3, "1101101") = 0 Then
    $sVSFt = 2
ElseIf StringCompare ($sVSF3, "1111001") = 0 Then
    $sVSFt = 3
ElseIf StringCompare ($sVSF3, "0110011") = 0 Then
    $sVSFt = 4
ElseIf StringCompare ($sVSF3, "1011011") = 0 Then
    $sVSFt = 5
ElseIf StringCompare ($sVSF3, "1011111") = 0 Then
    $sVSFt = 6
ElseIf StringCompare ($sVSF3, "1110000") = 0 Then
    $sVSFt = 7
ElseIf StringCompare ($sVSF3, "1111111") = 0 Then
    $sVSFt = 8
ElseIf StringCompare ($sVSF3, "1111011") = 0 Then
    $sVSFt = 9
ElseIf PixelGetColor (3332,142) > 10000000 Then
    $sVSFt = 1
Else
    $sVSFt = " "
    EndIf

;----------------------------------------

If PixelGetColor (3306,137) > 10000000 Then
Global $sA2 = 1
Else
    $sA2 = 0
EndIf

If PixelGetColor (3315,144) > 10000000 Then
Global $sB2 = 1
Else
    $sB2 = 0
Endif

If PixelGetColor (3315,155) > 10000000 Then
Global $sC2 = 1
Else
    $sC2 = 0
EndIf

If PixelGetColor (3312,160) > 10000000 Then
Global $sD2 = 1
Else
    $sD2 = 0
EndIf

If PixelGetColor (3304,155) > 10000000 Then
Global $sE2 = 1
Else
    $sE2 = 0
EndIf

If PixelGetColor (3304,144) > 10000000 Then
Global $sF2 = 1
Else
    $sF2 = 0
EndIf

If PixelGetColor (3312,148) > 10000000 Then
Global $sG2 = 1
Else
    $sG2 = 0
EndIf

Local $sVSF2=$sA2&$sB2&$sC2&$sD2&$sE2&$sF2&$sG2


If StringCompare ($sVSF2, "1111110") = 0 Then
    Global $sVSFh = "0"
ElseIf StringCompare ($sVSF2, "1101101") = 0 Then
    $sVSFh = 2
ElseIf StringCompare ($sVSF2, "1111001") = 0 Then
    $sVSFh = 3
ElseIf StringCompare ($sVSF2, "0110011") = 0 Then
    $sVSFh = 4
ElseIf StringCompare ($sVSF2, "1011011") = 0 Then
    $sVSFh = 5
ElseIf StringCompare ($sVSF2, "1011111") = 0 Then
    $sVSFh = 6
ElseIf StringCompare ($sVSF2, "1110000") = 0 Then
    $sVSFh = 7
ElseIf StringCompare ($sVSF2, "1111111") = 0 Then
    $sVSFh = 8
ElseIf StringCompare ($sVSF2, "1111011") = 0 Then
    $sVSFh = 9
ElseIf PixelGetColor (3312,142) > 10000000 Then
    $sVSFh = 1
Else
    $sVSFh = " "
    EndIf

;----------------------------------------

If PixelGetColor (3286,137) > 10000000 Then
Global $sA1 = 1
Else
    $sA1 = 0
EndIf

If PixelGetColor (3295,144) > 10000000 Then
Global $sB1 = 1
Else
    $sB1 = 0
Endif

If PixelGetColor (3295,155) > 10000000 Then
Global $sC1 = 1
Else
    $sC1 = 0
EndIf

If PixelGetColor (3292,160) > 10000000 Then
Global $sD1 = 1
Else
    $sD1 = 0
EndIf

If PixelGetColor (3284,155) > 10000000 Then
Global $sE1 = 1
Else
    $sE1 = 0
EndIf

If PixelGetColor (3284,144) > 10000000 Then
Global $sF1 = 1
Else
    $sF1 = 0
EndIf

If PixelGetColor (3292,148) > 10000000 Then
Global $sG1 = 1
Else
    $sG1 = 0
    EndIf

Local $sVSF1=$sA1&$sB1&$sC1&$sD1&$sE1&$sF1&$sG1

If StringCompare ($sVSF1, "1111110") = 0 Then
    Global $sVSFth = 0
ElseIf StringCompare ($sVSF1, "1101101") = 0 Then
    $sVSFth = 2
ElseIf StringCompare ($sVSF1, "1111001") = 0 Then
    $sVSFth = 3
ElseIf StringCompare ($sVSF1, "0110011") = 0 Then
    $sVSFth = 4
ElseIf StringCompare ($sVSF1, "1011011") = 0 Then
    $sVSFth = 5
ElseIf StringCompare ($sVSF1, "1011111") = 0 Then
    $sVSFth = 6
ElseIf StringCompare ($sVSF1, "1110000") = 0 Then
    $sVSFth = 7
ElseIf StringCompare ($sVSF1, "1111111") = 0 Then
    $sVSFth = 8
ElseIf StringCompare ($sVSF1, "1111011") = 0 Then
    $sVSFth = 9
ElseIf PixelGetColor (3293,142) > 10000000 Then
    $sVSFth = 1
Else
    $sVSFth = " "
    EndIf

If PixelGetColor (3270,142) > 10000000 Then
Global $sVSFpm = "+"
ElseIf PixelGetColor (3270,149) > 10000000 Then
    $sVSFpm = "-"
ElseIf $sVSFth = " " And PixelGetColor (3289,149) > 10000000 Then
    $sVSFpm = "-"
ElseIf PixelGetColor (3270,149) < 10000000 Then
    $sVSFpm = " "
EndIf

If $sVSFh = " " And $sVSFpm <> " " Then
    $sVSFh = "."
    EndIf

If $sG1 = 1 And $sG2 = 1 And $sG3 = 1 And $sG4 = 1 Then
    $sVSFpm = " "
    $sVSFth = "-"
    $sVSFh = "-"
    $sVSFt = "-"
    $sVSFu = "-"
    EndIf

;---------labels----------------

;d1-3
If PixelGetColor (2381,139) > 10000000 Then
    Global $sIM = 1
Else
    $sIM = 0
EndIf

;d4-6
If PixelGetColor (2579,143) > 10000000 Then
    Global $sHT = 1
Else
    $sHT = 0
EndIf

;d7-11
If PixelGetColor (3005,138) > 10000000 Then
    Global $sFM = 1
Else
    $sFM = 0
EndIf

;d11-15
If PixelGetColor (3229,146) > 10000000 Then
    Global $sVF = 1
Else
    $sVF = 0
EndIf
;---------consolidation-----------

Local $sReadout = "#a"&$sSPDd&$sSPDh&$sSPDt&$sSPDu&"#b"&$sHDGh&$sHDGt&$sHDGu&"#c"&$sALTtt&$sALTth&$sALTh&$sALTt&$sALTu&"#d"&$sVSFpm&$sVSFth&$sVSFh&$sVSFt&$sVSFu&"#e"&$sIM&"#f"&$sHT&"#g"&$sFM&"#h"&$sVF

;---------transmission-----------

_CommAPI_TransmitString($hFile, $sReadout)
sleep (100)

WEnd

; And break out if it is cleared
    ToolTip("Function Stopped")
    _CommAPI_ClosePort($hFile)
    Sleep(500)
    ToolTip("")
    Return
EndFunc   ;==>DataLoop
Edited by ckovoor
Link to comment
Share on other sites

  • Moderators

:blink: Holly crap, that is the largest While/WEnd loop I've ever seen... 1100 lines!!  :nuke:

1.  Is this for making calls? I ask, because almost always there's an api to get the data you're looking for rather than using PixelGet/Check anything.

2.  Break your calls into chunks (mini functions).  Then check for $FL, if it's true after your function call, exitloop.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi SmOke_N,

Thank you for taking a look at this and for commenting.

My own script is just a single While1....WEnd loop (with those 1000 lines) and it works flawlessly on its own. It is checking pixel states across a 15 digit 7-segment display on-screen, and across some additional characters, and then comparing the patterns with those made by digits 0 to 9 and some other characters. Each pixel has to be analysed on each loop, so I don't see much point in breaking it up into functions, and I don't know of any API relevant to this task.

I should have clarified that the While $FL.....WEnd Loop inserted to enclose my script is in fact working perfectly, i.e. it forms the window with the buttons, and I can start and stop and restart my own script within it. Which indicates that my own script is not stalling anywhere. It's just that it's ability to read the subsequent digits of the sequence gets degraded when I hand over control for starting and stopping to the While $FL.....WEnd Loop. It starts misreading the digits, that's all.

I am a beginner at all this, so of course I will defer to your better judgement, but would you reconsider your assessment in the light of what I have just said?

Thanks, and looking forward to your further comments,

Chakko.

Edited by ckovoor
Link to comment
Share on other sites

  • Moderators

I'm not interested in breaking down into specifics why I mentioned what I have about the functions.  You really don't need to, but you've implemented a foreign element into your "flawless" code.  Check the $FL throughout the code if you want, but you need to check it more than just once is what it sounds/looks like.  What has changed specifically?

eg.

While $FL
   ; my pixel code
   ; nothing else
WEnd

Or

While $FL
   ; my pixel code
   ; something else
WEnd

There's nothing from the code you've implemented that would degrade anything that I can see.

Edit:

Other than maybe a different window having focus if the script was just running by itself with a GUI before.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi SmOke_N,

Thank you so very much for taking time out to help me. I absolutely appreciate it!:)

Yes, I agree the possible (inadvertent) introduction of a foreign element is the obvious explanation for such misbehaviour.

Anyway, I tried cycling the run and stop buttons on the GUI created for/by the controller (While $FL....WEnd) loop, and found that on the first start the later digits in the sequence are invariably misread, but stopping and re-running the script clears these errors, and everything works fine for a while......then an occasional misread happens somewhere in the sequence (the digits are changing all the time).....but another stop-run cycle cures the problem.

So does it now point to some sort of memory/overload issue? By the way, I re-confirm that the working script on its own will work for hours without making any errors in reporting the digits. Is there any way I could lighten the additional load caused by the controlling loop to see if that would make a difference?

Thank you again for your time and patience.

Regards,

Chakko.

Edited by ckovoor
Link to comment
Share on other sites

  • Moderators

Your variables are global, so when you leave the function, they still retain the last amount of data.  Try localizing them.  The data will be cleared the next time you enter in the loop.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi SmOke_N,

I implemented your suggestion......changed all the Global to Local within my script.......and it had an obvious beneficial impact.......the displays were read correctly on the first run, and no further cycling of stop-run was required. :thumbsup: Thank you!:)

I would need to keep looking at the behaviour over extended periods, but it looks very promising so far.

And if there are any other improvements you could suggest, I'm all ears!

Thank you again! :ILA3:

Warm Regards,

Chakko.

Edited by ckovoor
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...