Jump to content

Monitor a loop while running a process


Recommended Posts

Hi Guys,

I`m new at AutoIT, so excuse me if my quistions are explained detailled enough.

I have a question:
I`m writing a bit of code that does the following:

It reads a value from my com port, this can be 0 or <> 0, what I want is that the value changes from 0 to <> 0  or from <>0 to 0 my slideshow resizes its format.

So, basicly I have a slideshow running conitnuasly based on files in a folder. THese jpg files should all be shown 5 seconds and than the next image.
but when the value is change it should directly change it screen size.

Now I have this code, is there someone who can help me finish this last bit:

#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>
#include "CommInterface.au3"
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7


#region - Settings
HotKeySet("{ESC}", "Terminate")
Opt("WinTitleMatchMode", 3)
#endregion

;GUISetBkColor(0xE0FFFF)
If @error Then Return SetError(@error, @ScriptLineNumber)


$picarray = _FileListToArray("C:\Users\Rob\Desktop\SaBjoTi\Photos\")
Local $sString = "This is an example of writing to the console."
ConsoleWrite($sString & @CRLF) ; Running this in a text editor which can trap console output e.g. SciTE, will display value of $sString.

                  ;$gui = GUICreate("SlideshowLarge",@DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
                  ;$pic = GUICtrlCreatePic("C:\Users\Rob\Desktop\SaBjoTi\"& $picarray[1], 0, 0, @DesktopWidth, @DesktopHeight)

                  $gui = GUICreate("Slideshow",250, 250, 0, 0, $WS_POPUP)
                  $pic = GUICtrlCreatePic("C:\Users\Rob\Desktop\SaBjoTi\Photos\"& $picarray[1], 0, 0, 250, 250)
                  GUISetCursor(16,1)
                  GUISetState()

                  ;$picarray = _FileListToArray("C:\Users\Rob\Desktop\SaBjoTi\Photos\")

    Local $hFile = _CommAPI_OpenCOMPort(7, 9600, 0, 8, 1)

    Local $sResult = "10"

Func Slideshow ()
    $picarray = _FileListToArray("C:\Users\Rob\Desktop\SaBjoTi\Photos\")
    ;Sleep(5000)
Do
    For $n = 1 To $picarray[0]
        GUICtrlSetImage($pic, "C:\Users\Rob\Desktop\SaBjoTi\Photos\" & $picarray[$n])
        Sleep (5000)
    Next
Until @error
EndFunc

     ; Slideshow ()

    While True
        $sResult = _CommAPI_ReceiveString($hFile, 5000)
 ;  MsgBox($MB_SYSTEMMODAL, "", "Value of $i is: " & $sResult)


    If $sResult = 0 then

;MsgBox($MB_SYSTEMMODAL, "", "result is 0: " & $sResult)
   GUICtrlSetPos($Pic, 150, 150, 300, 300)


   Do
      $sResult = _CommAPI_ReceiveString($hFile, 5000)
          For $n = 1 To $picarray[0]
        GUICtrlSetImage($pic, "C:\Users\Rob\Desktop\SaBjoTi\Photos\" & $picarray[$n])
       ; Sleep (5000)
    Next

Until $sResult > 50


    ElseIf $sResult > 50 then
    ;MsgBox($MB_SYSTEMMODAL, "", "result is 0: " & $sResult)
   GUICtrlSetPos($Pic, 0, 0, 100, 100)


   Do
    For $n = 1 To $picarray[0]
        GUICtrlSetImage($pic, "C:\Users\Rob\Desktop\SaBjoTi\Photos\" & $picarray[$n])
        $sResult = _CommAPI_ReceiveString($hFile, 5000)
        Sleep (1000)
      $sResult = _CommAPI_ReceiveString($hFile, 5000)
      Sleep (1000)
      $sResult = _CommAPI_ReceiveString($hFile, 5000)
      Sleep (1000)
      $sResult = _CommAPI_ReceiveString($hFile, 5000)
      Sleep (1000)
    Next


Until $sResult = 0




    EndIf

    WEnd

Hope to hear from somebody.

 

Greetz

Rob

Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

RobReijm,

Welcome to the AutoIt forums.

When you post code please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.

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

I`m testing with an other script, I am able to switch the size of the images from small to full screen. But at soon as I add this line of code into a function:

 

For $n = 1 To $picarray[0]
        GUICtrlSetImage($pic, "C:\Users\Rob\Desktop\SaBjoTi\Photos\" & $picarray[$n])
        Sleep (5000)
    Next

The loop waits untill this loop is done. So i`m not able to directly switch from a big to small screen.

This is my complete code:

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>
#include "CommInterface.au3"


$picarray = _FileListToArray("C:\Users\Rob\Desktop\SaBjoTi\Photos\")
                  $gui = GUICreate("SlideshowLarge",@DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
                  $pic = GUICtrlCreatePic("C:\Users\Rob\Desktop\SaBjoTi\Photos\"& $picarray[1], 0, 0, @DesktopWidth, @DesktopHeight)
                  $pic = GUISetBkColor(0x000000)
                  GUISetCursor(16,1)
                  GUISetState()

 ; Declare a flag
 Global $fRunOne = True

    Local $hFile = _CommAPI_OpenCOMPort(6, 9600, 0, 8, 1)
    Local $sResult = "10"
 Opt("GUIOnEventMode", 1)

 ;$hGUI = GUICreate("Test", 500, 500)
 GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

 ;$hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30)
 ;$hButton_1 = "Func One"
 ;GUICtrlSetOnEvent($hButton_1, "_Func_1")
 ;$hButton_2 = "Func Two"
 ;GUICtrlSetOnEvent($hButton_2, "_Func_2")
 ; $hButton_3 = GUICtrlCreateButton("Func Three", 10, 90, 80, 30)
; $hButton_3 = "Func Three"
 ;GUICtrlSetOnEvent($hButton_3, "_Func_3")
    $picarray = _FileListToArray("C:\Users\Rob\Desktop\SaBjoTi\Photos\")
 GUISetState()

;_Func_1()
_Func_2()


 While 1
     Sleep(10)
     ; Check if the flag has been set by the OnEvent function
     If $fRunOne Then
         ; Now start the "real" function from within the main code
         _Func_1_Run()
      EndIf

 WEnd

 Func _Func_1()
     ; Set the flag within the OnEvent function
     $fRunOne = True
         For $n = 1 To $picarray[0]
        GUICtrlSetImage($pic, "C:\Users\Rob\Desktop\SaBjoTi\Photos\" & $picarray[$n])
        Sleep (5000)
    Next
 EndFunc   ;==>_Func_1

 Func _Func_1_Run()
    GUICtrlSetPos($Pic, 0, 0, @DesktopWidth, @DesktopHeight)
     ; Slideshow ()
     Global $fRunOne = False

 EndFunc   ;==>_Func_1_Run

 Func _Func_2()
GUICtrlSetPos($Pic, 0, 0, 100, 100)
;Slideshow ()
      Do
      $sResult = _CommAPI_ReceiveString($hFile, 5000)
   Until $sResult > 50
      _Func_3()
EndFunc   ;==>_Func_2

 Func _Func_3()
    GUICtrlSetPos($Pic, 0, 0, @DesktopWidth, @DesktopHeight)
   Do
      $sResult = _CommAPI_ReceiveString($hFile, 5000)
   Until $sResult = 0
      _Func_2()
EndFunc   ;==>_Func_2




 Func _Exit()
     Exit
  EndFunc   ;==>_Exit

Is there anyone who can help me change the code so that the picture slideshow isn`t causing my script to pauze?

 

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